From 6cdafc1df9555ff7903c7ef209584f3691bca392 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey <79640544+pixelcaliber@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:59:01 +0530 Subject: [PATCH] add missing testcases for word.cpp for improving coverage (#799) --- tests/modules/word/word_test.cpp | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/modules/word/word_test.cpp b/tests/modules/word/word_test.cpp index b12a9f2d..53b2cf59 100644 --- a/tests/modules/word/word_test.cpp +++ b/tests/modules/word/word_test.cpp @@ -219,3 +219,38 @@ TEST_F(WordTest, shouldGenerateWords) ASSERT_TRUE(std::ranges::all_of(separatedWords, [](const std::string& separatedWord) { return std::ranges::find(_allWords, separatedWord) != _allWords.end(); })); } + +TEST_F(WordTest, shouldReturnRandomElementWhenExactLengthNotFound) +{ + const unsigned int existingLength = 5; + + std::vector matchingAdjectives; + for (const auto& adj : _adjectives_sorted) { + if (adj.size() == existingLength) { + matchingAdjectives.push_back(adj); + } + } + + const auto generatedAdjective = adjective(existingLength + 1); + + ASSERT_TRUE(std::ranges::find(_adjectives_sorted, generatedAdjective) != _adjectives_sorted.end()); + ASSERT_TRUE(std::ranges::find(matchingAdjectives, generatedAdjective) == matchingAdjectives.end()); +} + +TEST_F(WordTest, shouldReturnEmptyStringForZeroWords) +{ + const auto result = words(0); + ASSERT_TRUE(result.empty()); +} + +TEST_F(WordTest, shouldGenerateLargeNumberOfWords) +{ + const unsigned int largeWordCount = 300; + const auto generatedWords = words(largeWordCount); + const auto separatedWords = common::split(generatedWords, " "); + + ASSERT_EQ(separatedWords.size(), largeWordCount); + for (const auto& word : separatedWords) { + ASSERT_TRUE(std::ranges::find(_allWords, word) != _allWords.end()); + } +} \ No newline at end of file