|
4 | 4 | #else |
5 | 5 | #include "test/catch.hpp" |
6 | 6 | #endif |
7 | | -#include <map> |
8 | 7 |
|
9 | | -using namespace std; |
10 | 8 |
|
11 | | -// Word-count exercise test case data version 1.4.0 |
| 9 | +/* |
| 10 | +For each word in the input, count the number of times it appears in the |
| 11 | +entire sentence. |
| 12 | +*/ |
12 | 13 |
|
13 | | -TEST_CASE("counts_one_word") |
14 | | -{ |
15 | | - const map<string, int> expected{{"word", 1}}; |
16 | | - |
17 | | - const auto actual = word_count::words("word"); |
18 | | - |
19 | | - REQUIRE(expected == actual); |
| 14 | +TEST_CASE("count one word", "[61559d5f-2cad-48fb-af53-d3973a9ee9ef]") { |
| 15 | + const std::map<std::string, int> expected{{"word", 1}}; |
| 16 | + REQUIRE(expected == word_count::words("word")); |
20 | 17 | } |
21 | 18 |
|
22 | 19 | #if defined(EXERCISM_RUN_ALL_TESTS) |
23 | | -TEST_CASE("counts_one_of_each") |
24 | | -{ |
25 | | - const map<string, int> expected{{"one", 1}, {"of", 1}, {"each", 1}}; |
26 | 20 |
|
27 | | - const auto actual = word_count::words("one of each"); |
28 | | - |
29 | | - REQUIRE(expected == actual); |
| 21 | +TEST_CASE("count one of each word", "[5abd53a3-1aed-43a4-a15a-29f88c09cbbd]") { |
| 22 | + const std::map<std::string, int> expected{{"one", 1}, {"of", 1}, {"each", 1}}; |
| 23 | + REQUIRE(expected == word_count::words("one of each")); |
30 | 24 | } |
31 | 25 |
|
32 | | -TEST_CASE("counts_multiple_occurrences") |
33 | | -{ |
34 | | - const map<string, int> expected{{"one", 1}, {"fish", 4}, {"two", 1}, {"red", 1}, {"blue", 1}}; |
35 | | - |
36 | | - const auto actual = word_count::words("one fish two fish red fish blue fish"); |
37 | | - |
38 | | - REQUIRE(expected == actual); |
| 26 | +TEST_CASE("multiple occurrences of a word", "[2a3091e5-952e-4099-9fac-8f85d9655c0e]") { |
| 27 | + const std::map<std::string, int> expected{{"one", 1}, {"fish", 4}, {"two", 1}, {"red", 1}, {"blue", 1}}; |
| 28 | + REQUIRE(expected == word_count::words("one fish two fish red fish blue fish")); |
39 | 29 | } |
40 | 30 |
|
41 | | -TEST_CASE("handles_cramped_list") |
42 | | -{ |
43 | | - const map<string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}}; |
44 | | - |
45 | | - const auto actual = word_count::words("one,two,three"); |
46 | | - |
47 | | - REQUIRE(expected == actual); |
| 31 | +TEST_CASE("handles cramped lists", "[e81877ae-d4da-4af4-931c-d923cd621ca6]") { |
| 32 | + const std::map<std::string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}}; |
| 33 | + REQUIRE(expected == word_count::words("one,two,three")); |
48 | 34 | } |
49 | 35 |
|
50 | | -TEST_CASE("handles_expanded_list") |
51 | | -{ |
52 | | - const map<string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}}; |
53 | | - |
54 | | - const auto actual = word_count::words("one,\ntwo,\nthree"); |
55 | | - |
56 | | - REQUIRE(expected == actual); |
| 36 | +TEST_CASE("handles expanded lists", "[7349f682-9707-47c0-a9af-be56e1e7ff30]") { |
| 37 | + const std::map<std::string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}}; |
| 38 | + REQUIRE(expected == word_count::words("one,\ntwo,\nthree")); |
57 | 39 | } |
58 | 40 |
|
59 | | -TEST_CASE("ignores_punctuation") |
60 | | -{ |
61 | | - const map<string, int> expected{{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}}; |
62 | | - |
63 | | - const auto actual = word_count::words("car: carpet as java: javascript!!&@$%^&"); |
64 | | - |
65 | | - REQUIRE(expected == actual); |
| 41 | +TEST_CASE("ignore punctuation", "[a514a0f2-8589-4279-8892-887f76a14c82]") { |
| 42 | + const std::map<std::string, int> expected{{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}}; |
| 43 | + REQUIRE(expected == word_count::words("car: carpet as java: javascript!!&@$%^&")); |
66 | 44 | } |
67 | 45 |
|
68 | | -TEST_CASE("includes_numbers") |
69 | | -{ |
70 | | - const map<string, int> expected{{"testing", 2}, {"1", 1}, {"2", 1}}; |
71 | | - |
72 | | - const auto actual = word_count::words("testing, 1, 2 testing"); |
73 | | - |
74 | | - REQUIRE(expected == actual); |
| 46 | +TEST_CASE("include numbers", "[d2e5cee6-d2ec-497b-bdc9-3ebe092ce55e]") { |
| 47 | + const std::map<std::string, int> expected{{"testing", 2}, {"1", 1}, {"2", 1}}; |
| 48 | + REQUIRE(expected == word_count::words("testing, 1, 2 testing")); |
75 | 49 | } |
76 | 50 |
|
77 | | -TEST_CASE("normalizes_case") |
78 | | -{ |
79 | | - const map<string, int> expected{{"go", 3}, {"stop", 2}}; |
80 | | - |
81 | | - const auto actual = word_count::words("go Go GO Stop stop"); |
82 | | - |
83 | | - REQUIRE(expected == actual); |
| 51 | +TEST_CASE("normalize case", "[dac6bc6a-21ae-4954-945d-d7f716392dbf]") { |
| 52 | + const std::map<std::string, int> expected{{"go", 3}, {"stop", 2}}; |
| 53 | + REQUIRE(expected == word_count::words("go Go GO Stop stop")); |
84 | 54 | } |
85 | 55 |
|
86 | | -TEST_CASE("with_apostrophes") |
87 | | -{ |
88 | | - const map<string, int> expected{{"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, {"cry", 1}}; |
89 | | - |
90 | | - const auto actual = word_count::words("First: don't laugh. Then: don't cry."); |
91 | | - |
92 | | - REQUIRE(expected == actual); |
| 56 | +TEST_CASE("with apostrophes", "[4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3]") { |
| 57 | + const std::map<std::string, int> expected{{"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, {"cry", 1}, {"you're", 1}, {"getting", 1}, {"it", 1}}; |
| 58 | + REQUIRE(expected == word_count::words("'First: don't laugh. Then: don't cry. You're getting it.'")); |
93 | 59 | } |
94 | 60 |
|
95 | | -TEST_CASE("with_quotations") |
96 | | -{ |
97 | | - const map<string, int> expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"large", 2}, {"and", 1}}; |
98 | | - |
99 | | - const auto actual = word_count::words("Joe can't tell between 'large' and large."); |
100 | | - |
101 | | - REQUIRE(expected == actual); |
| 61 | +TEST_CASE("with quotations", "[be72af2b-8afe-4337-b151-b297202e4a7b]") { |
| 62 | + const std::map<std::string, int> expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"large", 2}, {"and", 1}}; |
| 63 | + REQUIRE(expected == word_count::words("Joe can't tell between 'large' and large.")); |
102 | 64 | } |
103 | 65 |
|
104 | | -TEST_CASE("substrings_from_the_beginning") |
105 | | -{ |
106 | | - const map<string, int> expected{{ "joe", 1 }, { "can't", 1 }, { "tell", 1 }, { "between", 1 }, { "app", 1 }, { "apple", 1 }, { "and", 1 }, { "a", 1 }}; |
107 | | - |
108 | | - const auto actual = word_count::words("Joe can't tell between app, apple and a."); |
109 | | - |
110 | | - REQUIRE(expected == actual); |
| 66 | +TEST_CASE("substrings from the beginning", "[8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6]") { |
| 67 | + const std::map<std::string, int> expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"app", 1}, {"apple", 1}, {"and", 1}, {"a", 1}}; |
| 68 | + REQUIRE(expected == word_count::words("Joe can't tell between app, apple and a.")); |
111 | 69 | } |
112 | 70 |
|
113 | | -TEST_CASE("multiple_spaces_not_detected_as_a_word") |
114 | | -{ |
115 | | - const map<string, int> expected{{ "multiple", 1 }, { "whitespaces", 1 }}; |
116 | | - |
117 | | - const auto actual = word_count::words(" multiple whitespaces"); |
118 | | - |
119 | | - REQUIRE(expected == actual); |
| 71 | +TEST_CASE("multiple spaces not detected as a word", "[c5f4ef26-f3f7-4725-b314-855c04fb4c13]") { |
| 72 | + const std::map<std::string, int> expected{{"multiple", 1}, {"whitespaces", 1}}; |
| 73 | + REQUIRE(expected == word_count::words(" multiple whitespaces")); |
120 | 74 | } |
121 | 75 |
|
122 | | -TEST_CASE("alternating_word_separators_not_detected_as_a_word") |
123 | | -{ |
124 | | - const map<string, int> expected{{ "one", 1 }, { "two", 1 }, { "three", 1 }}; |
125 | | - |
126 | | - const auto actual = word_count::words(",\n,one,\n ,two \n 'three'"); |
| 76 | +TEST_CASE("alternating word separators not detected as a word", "[50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360]") { |
| 77 | + const std::map<std::string, int> expected{{"one", 1}, {"two", 1}, {"three", 1}}; |
| 78 | + REQUIRE(expected == word_count::words(",\n,one,\n ,two \n 'three'")); |
| 79 | +} |
127 | 80 |
|
128 | | - REQUIRE(expected == actual); |
| 81 | +TEST_CASE("quotation for word with apostrophe", "[6d00f1db-901c-4bec-9829-d20eb3044557]") { |
| 82 | + const std::map<std::string, int> expected{{"can", 1}, {"can't", 2}}; |
| 83 | + REQUIRE(expected == word_count::words("can, can't, 'can't'")); |
129 | 84 | } |
130 | 85 |
|
131 | 86 | #endif |
0 commit comments