Skip to content

Commit

Permalink
add missing testcases for word.cpp for improving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelcaliber committed Jul 15, 2024
1 parent 296484e commit ac4f434
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/modules/word/word_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view> 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());
}
}

0 comments on commit ac4f434

Please sign in to comment.