Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word-count - update tests specification to version 1.4.0 #299

Merged
merged 3 commits into from
Aug 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 38 additions & 30 deletions exercises/word-count/word_count_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using namespace std;

// Word-count exercise test case data version 1.4.0

TEST_CASE("counts_one_word")
{
const map<string, int> expected{{"word", 1}};
Expand Down Expand Up @@ -32,88 +34,94 @@ TEST_CASE("counts_multiple_occurrences")
REQUIRE(expected == actual);
}

TEST_CASE("ignores_punctuation")
TEST_CASE("handles_cramped_list")
{
const map<string, int> expected{{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}};
const map<string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}};

const auto actual = word_count::words("car : carpet as java : javascript!!&@$%^&");
const auto actual = word_count::words("one,two,three");

REQUIRE(expected == actual);
}

TEST_CASE("includes_numbers")
TEST_CASE("handles_expanded_list")
{
const map<string, int> expected{{"testing", 2}, {"1", 1}, {"2", 1}};
const map<string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}};

const auto actual = word_count::words("testing, 1, 2 testing");
const auto actual = word_count::words("one,\ntwo,\nthree");

REQUIRE(expected == actual);
}

TEST_CASE("normalizes_case")
TEST_CASE("ignores_punctuation")
{
const map<string, int> expected{{"go", 3}};
const map<string, int> expected{{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}};

const auto actual = word_count::words("go Go GO");
const auto actual = word_count::words("car: carpet as java: javascript!!&@$%^&");

REQUIRE(expected == actual);
}

TEST_CASE("counts_constructor")
TEST_CASE("includes_numbers")
{
const map<string, int> expected{{"constructor", 2}};
const map<string, int> expected{{"testing", 2}, {"1", 1}, {"2", 1}};

const auto actual = word_count::words("constructor Constructor");
const auto actual = word_count::words("testing, 1, 2 testing");

REQUIRE(expected == actual);
}

TEST_CASE("counts_multiline")
TEST_CASE("normalizes_case")
{
const map<string, int> expected{{"hello", 1}, {"world", 1}};
const map<string, int> expected{{"go", 3}, {"stop", 2}};

const auto actual = word_count::words("hello\nworld");
const auto actual = word_count::words("go Go GO Stop stop");

REQUIRE(expected == actual);
}

TEST_CASE("count_everything_just_once")
TEST_CASE("with_apostrophes")
{
const map<string, int> expected{{"all", 2}, {"the", 2}, {"kings", 2}, {"horses", 1}, {"and", 1}, {"men", 1}};
const auto actual = word_count::words("all the kings horses and all the kings men");
const map<string, int> expected{{"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, {"cry", 1}};

const auto actual = word_count::words("First: don't laugh. Then: don't cry.");

REQUIRE(expected == actual);
}

TEST_CASE("handles_cramped_list")
TEST_CASE("with_quotations")
{
const map<string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}};
const auto actual = word_count::words("one,two,three");
const map<string, int> expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"large", 2}, {"and", 1}};

const auto actual = word_count::words("Joe can't tell between 'large' and large.");

REQUIRE(expected == actual);
}

TEST_CASE("with_apostrophes")
TEST_CASE("substrings_from_the_beginning")
{
const map<string, int> expected{{"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, {"cry", 1}};
const auto actual = word_count::words("First: don't laugh. Then: don't cry.");
const map<string, int> expected{{ "joe", 1 }, { "can't", 1 }, { "tell", 1 }, { "between", 1 }, { "app", 1 }, { "apple", 1 }, { "and", 1 }, { "a", 1 }};

const auto actual = word_count::words("Joe can't tell between app, apple and a.");

REQUIRE(expected == actual);
}

TEST_CASE("with_free_standing_apostrophes")
TEST_CASE("multiple_spaces_not_detected_as_a_word")
{
const map<string, int> expected{{ "go", 3 }};
const auto actual = word_count::words("go ' Go '' GO");
const map<string, int> expected{{ "multiple", 1 }, { "whitespaces", 1 }};

const auto actual = word_count::words(" multiple whitespaces");

REQUIRE(expected == actual);
}

TEST_CASE("with_apostrophes_as_quotes")
TEST_CASE("alternating_word_separators_not_detected_as_a_word")
{
const map<string, int> expected{{"she", 1}, {"said", 1}, {"let's", 1}, {"meet", 1}, {"at", 1}, {"twelve", 1}, {"o'clock", 1}};
const auto actual = word_count::words("She said, 'let's meet at twelve o'clock'");
const map<string, int> expected{{ "one", 1 }, { "two", 1 }, { "three", 1 }};

const auto actual = word_count::words(",\n,one,\n ,two \n 'three'");

REQUIRE(expected == actual);
}

#endif