From 7ed7b505ea73e9f38887298db4badaf18ee78b15 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:23:12 +0200 Subject: [PATCH 01/27] .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 259148fa..3e94e61a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ *.exe *.out *.app + +# Build dirs +build-* + +# .user files +*.user \ No newline at end of file From 5495752d0794a6d07b8012ae501ba283fc5d72d4 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:23:22 +0200 Subject: [PATCH 02/27] 1: red --- tdd_intro/homework/01_leap_year/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4f186c8b..61120db5 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,13 @@ If your language provides a method in the standard library that does this look-u */ #include + +bool isLeapYear(size_t year) +{ + return false; +} + +TEST(LeapYear, 2016IsLeapYear) +{ + EXPECT_TRUE(isLeapYear(2016)); +} From 5f9b2aeb371dcf11508922d714c66412f3f687b4 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:24:11 +0200 Subject: [PATCH 03/27] 1: green --- tdd_intro/homework/01_leap_year/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 61120db5..5ac66839 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,7 +16,7 @@ If your language provides a method in the standard library that does this look-u bool isLeapYear(size_t year) { - return false; + return true; } TEST(LeapYear, 2016IsLeapYear) From a44bc67dffc4deb4679d6da894eb7999b2752967 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:25:50 +0200 Subject: [PATCH 04/27] 1: red --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 5ac66839..4ce5b2e6 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -23,3 +23,7 @@ TEST(LeapYear, 2016IsLeapYear) { EXPECT_TRUE(isLeapYear(2016)); } +TEST(LeapYear, 2017IsNotLeapYear) +{ + EXPECT_FALSE(isLeapYear(2017)); +} From ee01e84da69f9a914a142a1e8f3e5f2e93161636 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:26:30 +0200 Subject: [PATCH 05/27] 1: green --- tdd_intro/homework/01_leap_year/test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4ce5b2e6..4a686047 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,7 +16,11 @@ If your language provides a method in the standard library that does this look-u bool isLeapYear(size_t year) { - return true; + if (year == 2016) + { + return true; + } + return false; } TEST(LeapYear, 2016IsLeapYear) From fee698313a660a9e8b62a1891fa90aca8d0789ef Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:27:18 +0200 Subject: [PATCH 06/27] 1: red --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4a686047..9b8fa9ba 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -31,3 +31,7 @@ TEST(LeapYear, 2017IsNotLeapYear) { EXPECT_FALSE(isLeapYear(2017)); } +TEST(LeapYear, 2020IsLeapYearToo) +{ + EXPECT_TRUE(isLeapYear(2020)); +} From 78314922556b79b430725c84f91f121e68ab0d48 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:27:50 +0200 Subject: [PATCH 07/27] 1: green --- tdd_intro/homework/01_leap_year/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 9b8fa9ba..5a8501d2 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,7 +16,7 @@ If your language provides a method in the standard library that does this look-u bool isLeapYear(size_t year) { - if (year == 2016) + if (year % 4 == 0) { return true; } From f23351d7164b753e1eda4ccb48b9f66bc5e8faf3 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:28:27 +0200 Subject: [PATCH 08/27] 1: refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 5a8501d2..bb7b4212 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -23,15 +23,12 @@ bool isLeapYear(size_t year) return false; } -TEST(LeapYear, 2016IsLeapYear) +TEST(LeapYear, TheYearsDivisibleBy4IsLeap) { EXPECT_TRUE(isLeapYear(2016)); + EXPECT_TRUE(isLeapYear(2020)); } TEST(LeapYear, 2017IsNotLeapYear) { EXPECT_FALSE(isLeapYear(2017)); } -TEST(LeapYear, 2020IsLeapYearToo) -{ - EXPECT_TRUE(isLeapYear(2020)); -} From 1d7d5f1547a1ac0342265ae6bfdd2c1c6dcfc4be Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:51:23 +0200 Subject: [PATCH 09/27] 1: red --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index bb7b4212..dcfa0cfc 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -32,3 +32,7 @@ TEST(LeapYear, 2017IsNotLeapYear) { EXPECT_FALSE(isLeapYear(2017)); } +TEST(LeapYear, TheYearDivisibleBy100IsNotLeap) +{ + EXPECT_FALSE(isLeapYear(1900)); +} From 05a4b60b93d75fa1d511699cd6d5e0e749cb310a Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:52:14 +0200 Subject: [PATCH 10/27] 1: green --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index dcfa0cfc..f6e78409 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,6 +16,10 @@ If your language provides a method in the standard library that does this look-u bool isLeapYear(size_t year) { + if (year % 100 == 0) + { + return false; + } if (year % 4 == 0) { return true; From 2efb5889528599a87a8e17679a54c2de150c5640 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:53:31 +0200 Subject: [PATCH 11/27] 1: red --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index f6e78409..dda72768 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -40,3 +40,7 @@ TEST(LeapYear, TheYearDivisibleBy100IsNotLeap) { EXPECT_FALSE(isLeapYear(1900)); } +TEST(LeapYear, TheYearDivisibleBy400IsLeap) +{ + EXPECT_TRUE(isLeapYear(2000)); +} From 93f4e38e3f663e85accede8ab54b6d3f2a0f79cf Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 14:53:59 +0200 Subject: [PATCH 12/27] 1: green --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index dda72768..e990aa50 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,6 +16,10 @@ If your language provides a method in the standard library that does this look-u bool isLeapYear(size_t year) { + if (year % 400 == 0) + { + return true; + } if (year % 100 == 0) { return false; From 76bdaf071b4af7272002b8efe0086ba140a65eb2 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 31 Oct 2018 15:00:54 +0200 Subject: [PATCH 13/27] 1: refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 38 +++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index e990aa50..474d2005 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -14,37 +14,35 @@ If your language provides a method in the standard library that does this look-u #include +bool isDivisibleBy(size_t numb, size_t by) +{ + return numb % by == 0; +} + bool isLeapYear(size_t year) { - if (year % 400 == 0) - { - return true; - } - if (year % 100 == 0) - { - return false; - } - if (year % 4 == 0) - { - return true; - } - return false; + return isDivisibleBy(year, 4) + && (!isDivisibleBy(year, 100) + || isDivisibleBy(year, 400)); } -TEST(LeapYear, TheYearsDivisibleBy4IsLeap) +TEST(LeapYear, TheYearsDivisibleBy4AreLeap) { EXPECT_TRUE(isLeapYear(2016)); EXPECT_TRUE(isLeapYear(2020)); } -TEST(LeapYear, 2017IsNotLeapYear) -{ - EXPECT_FALSE(isLeapYear(2017)); -} -TEST(LeapYear, TheYearDivisibleBy100IsNotLeap) +TEST(LeapYear, TheYearsDivisibleBy100AreNotLeap) { EXPECT_FALSE(isLeapYear(1900)); + EXPECT_FALSE(isLeapYear(1800)); } -TEST(LeapYear, TheYearDivisibleBy400IsLeap) +TEST(LeapYear, TheYearsDivisibleBy400AreLeap) { EXPECT_TRUE(isLeapYear(2000)); + EXPECT_TRUE(isLeapYear(1600)); +} +TEST(LeapYear, AnyOtherYearsArentNotLeapYear) +{ + EXPECT_FALSE(isLeapYear(2017)); + EXPECT_FALSE(isLeapYear(1235)); } From 2ad274359c4c66c218a77359f81b5eb27724a036 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 13:56:57 +0200 Subject: [PATCH 14/27] 2.1: red --- tdd_intro/demo/02_word_count/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 6bdc8367..6fc840a9 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -17,3 +17,13 @@ such: 1 #include #include +std::map CountWords(const std::string& sentence) +{ + return {}; +} + +TEST(CountWordsTest, ReturnsSameWordMapForOneWord) +{ + std::map expected({ { "word", 1 } }); + EXPECT_EQ(expected, CountWords("word")); +} From d1ff6352fc63f67c27bf452ef24784541c42c38a Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 13:57:43 +0200 Subject: [PATCH 15/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 6fc840a9..d9e888d9 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -19,7 +19,7 @@ such: 1 std::map CountWords(const std::string& sentence) { - return {}; + return { { sentence, 1 } }; } TEST(CountWordsTest, ReturnsSameWordMapForOneWord) From e3efe1635d49c12509a4dc93e84064fda3452d70 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 14:04:42 +0200 Subject: [PATCH 16/27] 2.1:red --- tdd_intro/demo/02_word_count/test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index d9e888d9..cdfa5aea 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -17,11 +17,20 @@ such: 1 #include #include +std::vector Split(const std::string& sentence, const std::string& delimetr) +{ + return {}; +} std::map CountWords(const std::string& sentence) { return { { sentence, 1 } }; } +TEST(SplitTest, ReturnSameWordForOneWord) +{ + EXPECT_EQ(std::vector({"word"}), Split("word", " ")); +} + TEST(CountWordsTest, ReturnsSameWordMapForOneWord) { std::map expected({ { "word", 1 } }); From 9c061ef4ba6b514448639703d3ab539f1d43ce75 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 14:05:06 +0200 Subject: [PATCH 17/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index cdfa5aea..e5519166 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -19,7 +19,7 @@ such: 1 std::vector Split(const std::string& sentence, const std::string& delimetr) { - return {}; + return { sentence }; } std::map CountWords(const std::string& sentence) { From 30cc80dc250c31936adfae19fb5eb48dae7966af Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 14:07:06 +0200 Subject: [PATCH 18/27] 2.1: red --- tdd_intro/demo/02_word_count/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index e5519166..d7ee56b8 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -30,6 +30,10 @@ TEST(SplitTest, ReturnSameWordForOneWord) { EXPECT_EQ(std::vector({"word"}), Split("word", " ")); } +TEST(SplitTest, ReturnsTwoWordsForTwoWords) +{ + EXPECT_EQ(std::vector({"word_a", "word_b"}), Split("word_a", "word_b")); +} TEST(CountWordsTest, ReturnsSameWordMapForOneWord) { From f423cdf4f41908ffe8b00e600329a48f09458553 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:22:49 +0200 Subject: [PATCH 19/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index d7ee56b8..e80879e5 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -19,7 +19,16 @@ such: 1 std::vector Split(const std::string& sentence, const std::string& delimetr) { - return { sentence }; + std::vector result; + + std::string::size_type next_delimetr_pos = sentence.find(delimetr); + result.push_back(sentence.substr(0, next_delimetr_pos)); + if (next_delimetr_pos != std::string::npos) + { + result.push_back(sentence.substr(next_delimetr_pos + 1)); + } + + return result; } std::map CountWords(const std::string& sentence) { @@ -32,7 +41,7 @@ TEST(SplitTest, ReturnSameWordForOneWord) } TEST(SplitTest, ReturnsTwoWordsForTwoWords) { - EXPECT_EQ(std::vector({"word_a", "word_b"}), Split("word_a", "word_b")); + EXPECT_EQ(std::vector({"word_a", "word_b"}), Split("word_a word_b", " ")); } TEST(CountWordsTest, ReturnsSameWordMapForOneWord) From 726ef5a0362c75fac94fae65a277dd8110526680 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:23:26 +0200 Subject: [PATCH 20/27] 2.1: red --- tdd_intro/demo/02_word_count/test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index e80879e5..7bf02540 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -35,14 +35,18 @@ std::map CountWords(const std::string& sentence) return { { sentence, 1 } }; } -TEST(SplitTest, ReturnSameWordForOneWord) +TEST(SplitTest, ReturnSameWordForOneWordSentence) { EXPECT_EQ(std::vector({"word"}), Split("word", " ")); } -TEST(SplitTest, ReturnsTwoWordsForTwoWords) +TEST(SplitTest, ReturnsTwoWordsForTwoWordsSentence) { EXPECT_EQ(std::vector({"word_a", "word_b"}), Split("word_a word_b", " ")); } +TEST(SplitTest, ReturnsNWordsForNWordsSentenceSentence) +{ + EXPECT_EQ(std::vector({"word_a", "word_b", "word_c"}), Split("word_a word_b word_c", " ")); +} TEST(CountWordsTest, ReturnsSameWordMapForOneWord) { From b3203b7b33edfac5e772db956caeacc41a2fe3b0 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:28:01 +0200 Subject: [PATCH 21/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 7bf02540..14375ec2 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -21,11 +21,16 @@ std::vector Split(const std::string& sentence, const std::string& d { std::vector result; - std::string::size_type next_delimetr_pos = sentence.find(delimetr); - result.push_back(sentence.substr(0, next_delimetr_pos)); - if (next_delimetr_pos != std::string::npos) + std::string::size_type pre_pos = 0; + for (;;) { - result.push_back(sentence.substr(next_delimetr_pos + 1)); + std::string::size_type delimetr_pos = sentence.find(delimetr, pre_pos); + result.push_back(sentence.substr(pre_pos, delimetr_pos - pre_pos)); + if (delimetr_pos == std::string::npos) + { + break; + } + pre_pos = delimetr_pos + 1; } return result; From 69f7a3c2cc990fc92356959e41d522488f567795 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:28:49 +0200 Subject: [PATCH 22/27] 2.1: refactoring --- tdd_intro/demo/02_word_count/test.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 14375ec2..cd1339b6 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -40,17 +40,12 @@ std::map CountWords(const std::string& sentence) return { { sentence, 1 } }; } -TEST(SplitTest, ReturnSameWordForOneWordSentence) +TEST(SplitTest, ReturnsNWordsForNWordsSentenceSentence) { EXPECT_EQ(std::vector({"word"}), Split("word", " ")); -} -TEST(SplitTest, ReturnsTwoWordsForTwoWordsSentence) -{ EXPECT_EQ(std::vector({"word_a", "word_b"}), Split("word_a word_b", " ")); -} -TEST(SplitTest, ReturnsNWordsForNWordsSentenceSentence) -{ EXPECT_EQ(std::vector({"word_a", "word_b", "word_c"}), Split("word_a word_b word_c", " ")); + EXPECT_EQ(std::vector({"word_a", "word_b", "word_a"}), Split("word_a word_b word_a", " ")); } TEST(CountWordsTest, ReturnsSameWordMapForOneWord) From ea2cf3063e9011cfb796c68eb11634665f7ce9e6 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:30:48 +0200 Subject: [PATCH 23/27] 2.1: red --- tdd_intro/demo/02_word_count/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index cd1339b6..09d84c5b 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -53,3 +53,8 @@ TEST(CountWordsTest, ReturnsSameWordMapForOneWord) std::map expected({ { "word", 1 } }); EXPECT_EQ(expected, CountWords("word")); } +TEST(CountWordsTest, CountsDifferentWords) +{ + std::map expected({ { "word_a", 1 }, { "word_b", 1 } }); + EXPECT_EQ(expected, CountWords("word_a word_b")); +} From 89515cae206fc952ebdefcea8990a76c178c34f5 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:33:19 +0200 Subject: [PATCH 24/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 09d84c5b..5f725bc4 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -37,7 +37,13 @@ std::vector Split(const std::string& sentence, const std::string& d } std::map CountWords(const std::string& sentence) { - return { { sentence, 1 } }; + std::map result; + std::vector words = Split(sentence, " "); + for (const std::string& word : words) + { + result.insert(std::make_pair(word, 1)); + } + return result; } TEST(SplitTest, ReturnsNWordsForNWordsSentenceSentence) From 9a527a8e1763597d2dfd540d44946ad37d0a2253 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:35:27 +0200 Subject: [PATCH 25/27] 2.1: red --- tdd_intro/demo/02_word_count/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 5f725bc4..6edd33b5 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -64,3 +64,8 @@ TEST(CountWordsTest, CountsDifferentWords) std::map expected({ { "word_a", 1 }, { "word_b", 1 } }); EXPECT_EQ(expected, CountWords("word_a word_b")); } +TEST(CountWordsTest, CountSameWords) +{ + std::map expected({ { "word_a", 2 } }); + EXPECT_EQ(expected, CountWords("word_a word_a")); +} From e1cebcd1d8dac770b888dcc559738ad25c3a943f Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:36:22 +0200 Subject: [PATCH 26/27] 2.1: green --- tdd_intro/demo/02_word_count/test.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 6edd33b5..0ccf7b30 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -41,7 +41,14 @@ std::map CountWords(const std::string& sentence) std::vector words = Split(sentence, " "); for (const std::string& word : words) { - result.insert(std::make_pair(word, 1)); + if (result.find(word) != result.end()) + { + result[word]++; + } + else + { + result.insert(std::make_pair(word, 1)); + } } return result; } From 846ebdfd8cd98accf95cafa662e159bfa9592e79 Mon Sep 17 00:00:00 2001 From: Zakhar Kurasov Date: Wed, 7 Nov 2018 15:39:51 +0200 Subject: [PATCH 27/27] 2.1: acceptance --- tdd_intro/demo/02_word_count/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tdd_intro/demo/02_word_count/test.cpp b/tdd_intro/demo/02_word_count/test.cpp index 0ccf7b30..bafa8d47 100644 --- a/tdd_intro/demo/02_word_count/test.cpp +++ b/tdd_intro/demo/02_word_count/test.cpp @@ -76,3 +76,19 @@ TEST(CountWordsTest, CountSameWords) std::map expected({ { "word_a", 2 } }); EXPECT_EQ(expected, CountWords("word_a word_a")); } +TEST(CountWordsTest, Acceptance) +{ + std::map expected({ + { "olly", 3 }, + { "in", 2 }, + { "come", 1 }, + { "free", 1 }, + { "please", 2 }, + { "let", 1 }, + { "it", 1 }, + { "be", 1 }, + { "such", 1 }, + { "manner", 1 }, + }); + EXPECT_EQ(expected, CountWords("olly olly in come free please please let it be in such manner olly")); +}