From c09e2dde38813019ada0da7e8fc1592a3928e9a6 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Wed, 14 Nov 2018 17:52:26 +0200 Subject: [PATCH 01/15] First practice (Bob) --- tdd_intro/demo/01_bob/test.cpp | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tdd_intro/demo/01_bob/test.cpp b/tdd_intro/demo/01_bob/test.cpp index dc9e42f..5840552 100644 --- a/tdd_intro/demo/01_bob/test.cpp +++ b/tdd_intro/demo/01_bob/test.cpp @@ -10,3 +10,45 @@ He answers 'Whatever.' to anything else. #include #include +const std::string g_tellBobAnswer = "Sure"; +const std::string g_yellBobAnswer = "Whoa, chill out!"; +const std::string g_emptyBobAnswer = "Fine. Be that way!"; +const std::string g_defaultBobAnswer = "Whatever."; + +std::string CallBob(const std::string& str) +{ + if (str.empty()) + { + return g_emptyBobAnswer; + } + if (str.back() == '!') + { + return g_yellBobAnswer; + } + else if (str.back() == '?') + { + return g_tellBobAnswer; + } + + return g_defaultBobAnswer; +} + +TEST(bob, AnswerSureOnQuestion) +{ + ASSERT_EQ(g_tellBobAnswer, CallBob("Are you ok?")); +} + +TEST(bob, AnswerChillOnYell) +{ + ASSERT_EQ(g_yellBobAnswer, CallBob("Yell!!!!")); +} + +TEST(bob, AnswerOnEmptyString) +{ + ASSERT_EQ(g_emptyBobAnswer, CallBob("")); +} + +TEST(bob, AnswerOnAnythingElse) +{ + ASSERT_EQ(g_defaultBobAnswer, CallBob("Anything else")); +} From 1d7fe3c190120c116f66fd7a95bf9fcf7abfd5b3 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Mon, 19 Nov 2018 19:05:51 +0200 Subject: [PATCH 02/15] Added 00_intro to the project --- tdd_intro/homework/homework.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/tdd_intro/homework/homework.pro b/tdd_intro/homework/homework.pro index cf6c01b..07506ca 100644 --- a/tdd_intro/homework/homework.pro +++ b/tdd_intro/homework/homework.pro @@ -1,6 +1,7 @@ TEMPLATE = subdirs SUBDIRS += \ + 00_intro \ 01_leap_year \ 02_ternary_numbers \ 03_bank_ocr \ From e54945c49eceffdbe4b559f2c5db278436579193 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Mon, 19 Nov 2018 19:10:48 +0200 Subject: [PATCH 03/15] First red test --- tdd_intro/homework/00_intro/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/homework/00_intro/test.cpp b/tdd_intro/homework/00_intro/test.cpp index be6959b..bf168d5 100644 --- a/tdd_intro/homework/00_intro/test.cpp +++ b/tdd_intro/homework/00_intro/test.cpp @@ -7,3 +7,13 @@ For example: input: "cool" output: "looc" */ #include + +std::string ReverseString(const std::string& str) +{ + return ""; +} + +TEST(intro, StringIsReversed) +{ + ASSERT_EQ("desreveR", ReverseString("Reversed")); +} From 3107554b88d3c594226b136f68e49e0375d76b72 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Mon, 19 Nov 2018 19:11:42 +0200 Subject: [PATCH 04/15] First green test --- tdd_intro/homework/00_intro/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/00_intro/test.cpp b/tdd_intro/homework/00_intro/test.cpp index bf168d5..e0b4e3f 100644 --- a/tdd_intro/homework/00_intro/test.cpp +++ b/tdd_intro/homework/00_intro/test.cpp @@ -10,7 +10,7 @@ For example: input: "cool" output: "looc" std::string ReverseString(const std::string& str) { - return ""; + return "desreveR"; } TEST(intro, StringIsReversed) From 851788a5c7a10d1cae9b1731fdac866d2ff97c01 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Mon, 19 Nov 2018 19:16:37 +0200 Subject: [PATCH 05/15] First refactoring --- tdd_intro/homework/00_intro/test.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/00_intro/test.cpp b/tdd_intro/homework/00_intro/test.cpp index e0b4e3f..bfbaaab 100644 --- a/tdd_intro/homework/00_intro/test.cpp +++ b/tdd_intro/homework/00_intro/test.cpp @@ -8,12 +8,18 @@ For example: input: "cool" output: "looc" #include +const std::string g_textToReverse = "Reversed"; +const std::string g_textReversed = "desreveR"; + std::string ReverseString(const std::string& str) { - return "desreveR"; + std::string reversedStr(str); + std::reverse(reversedStr.begin(), reversedStr.end()); + + return reversedStr; } TEST(intro, StringIsReversed) { - ASSERT_EQ("desreveR", ReverseString("Reversed")); + ASSERT_EQ(g_textReversed, ReverseString(g_textToReverse)); } From b7b61424f50e25788823727aa2126c4c2fd9df56 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 14:53:56 +0200 Subject: [PATCH 06/15] First red test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4f186c8..cff68e1 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,8 @@ If your language provides a method in the standard library that does this look-u */ #include + +TEST(LeapYear, DivibleBy4) +{ + ASSERT_TRUE(IsLeapYear(1996)); +} From 7cb5685e63e73b0a18462c474ad0d776c8a7bdbe Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 14:54:25 +0200 Subject: [PATCH 07/15] First green test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index cff68e1..a0dd92c 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -14,6 +14,11 @@ If your language provides a method in the standard library that does this look-u #include +bool IsLeapYear(unsigned int year) +{ + return true; +} + TEST(LeapYear, DivibleBy4) { ASSERT_TRUE(IsLeapYear(1996)); From dd1a0b94f6e7b65e84df390b8cc9c591942e3fa3 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:05:07 +0200 Subject: [PATCH 08/15] First refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index a0dd92c..53bd7bb 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,7 +16,12 @@ If your language provides a method in the standard library that does this look-u bool IsLeapYear(unsigned int year) { - return true; + if (year % 4 == 0) + { + return true; + } + + return false; } TEST(LeapYear, DivibleBy4) From 30706a5a43bb61f337a525baddd71a56c4058bfb Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:05:42 +0200 Subject: [PATCH 09/15] Second red test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 53bd7bb..8c6a7fb 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -28,3 +28,8 @@ TEST(LeapYear, DivibleBy4) { ASSERT_TRUE(IsLeapYear(1996)); } + +TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100) +{ + ASSERT_FALSE(IsLeapYear(1900)); +} From f0dd1c909182e0f2396daa36967c9eb0773642a7 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:08:36 +0200 Subject: [PATCH 10/15] Second green test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 8c6a7fb..6259141 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -18,6 +18,11 @@ bool IsLeapYear(unsigned int year) { if (year % 4 == 0) { + if (year % 100 == 0) + { + return false; + } + return true; } From 583ef8c2ce8e305229e0502f9a2126de3cb9abee Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:12:08 +0200 Subject: [PATCH 11/15] Second refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 6259141..b7fa0b5 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,13 +16,8 @@ If your language provides a method in the standard library that does this look-u bool IsLeapYear(unsigned int year) { - if (year % 4 == 0) + if ((year % 4 == 0) && (year % 100 != 0)) { - if (year % 100 == 0) - { - return false; - } - return true; } From 8dcd2b3e7e36744b48a7d90ba05d986385d45320 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:15:05 +0200 Subject: [PATCH 12/15] Third red test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index b7fa0b5..f7a0a6f 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -33,3 +33,8 @@ TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100) { ASSERT_FALSE(IsLeapYear(1900)); } + +TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100UnlessDivisibleBy400) +{ + ASSERT_TRUE(IsLeapYear(2000)); +} From d18e3bd201e1c38eb3ac12e5a90b1b2ecb05302e Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:27:26 +0200 Subject: [PATCH 13/15] Third green test --- tdd_intro/homework/01_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index f7a0a6f..7d89650 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -21,6 +21,11 @@ bool IsLeapYear(unsigned int year) return true; } + if (year % 400 == 0) + { + return true; + } + return false; } From 1cd1253dc9c896f17e3d97338bd6ac448a236e95 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:28:49 +0200 Subject: [PATCH 14/15] Third refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 7d89650..6d4872e 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,12 +16,7 @@ If your language provides a method in the standard library that does this look-u bool IsLeapYear(unsigned int year) { - if ((year % 4 == 0) && (year % 100 != 0)) - { - return true; - } - - if (year % 400 == 0) + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { return true; } From 3d38518c59ae7d3b98d915becdd5e574d39e0952 Mon Sep 17 00:00:00 2001 From: Viacheslav Konstantinov Date: Tue, 27 Nov 2018 15:46:07 +0200 Subject: [PATCH 15/15] Acceptence test --- tdd_intro/homework/01_leap_year/test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 6d4872e..40c8587 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -38,3 +38,11 @@ TEST(LeapYear, DivisibleBy4ExceptDivisibleBy100UnlessDivisibleBy400) { ASSERT_TRUE(IsLeapYear(2000)); } + +TEST(LeapYear, Acceptence) +{ + ASSERT_TRUE(IsLeapYear(2020)); + ASSERT_TRUE(IsLeapYear(2008)); + ASSERT_FALSE(IsLeapYear(1990)); + ASSERT_FALSE(IsLeapYear(1000)); +}