From 4e129352b6697bbc6a238e2cfcbcc67780775119 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:44:58 +0300 Subject: [PATCH 01/94] Red test (Test for Odd numbers). --- 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 4f186c8b..8706e008 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(IsLeap, ReturnFalseForOddYears) +{ + ASSERT_FALSE(IsLeap(1901)); +} From 3b9b0e9fcebbe48d4cc033f080097f8ee04b7c9e Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:46:19 +0300 Subject: [PATCH 02/94] Green test (Test for Odd numbers). --- 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 8706e008..1592c4f3 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -14,6 +14,10 @@ If your language provides a method in the standard library that does this look-u #include +bool IsLeap(size_t year) +{ + return false; +} TEST(IsLeap, ReturnFalseForOddYears) { ASSERT_FALSE(IsLeap(1901)); From 17440714672b9bf7e40452aa18910898ae6a0e8a Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:48:22 +0300 Subject: [PATCH 03/94] Red test (Test for numbers that devisible by 400). --- tdd_intro/homework/01_leap_year/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 1592c4f3..bde0ce2e 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -18,7 +18,13 @@ bool IsLeap(size_t year) { return false; } + TEST(IsLeap, ReturnFalseForOddYears) { ASSERT_FALSE(IsLeap(1901)); } + +TEST(IsLeap, ReturnTrueIfDevisibleBy400) +{ + ASSERT_TRUE(IsLeap(1600)); +} From 7bd7fca87f5927f4f095463dbdf6cbbf8c6626d5 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:49:51 +0300 Subject: [PATCH 04/94] Green test (Test for numbers that devisible by 400). --- 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 bde0ce2e..2fb483c1 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 IsLeap(size_t year) { + if (year % 400 == 0) + { + return true; + } return false; } From bfa4b730a6372052517d2c3e831cf23c423bdf44 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:53:25 +0300 Subject: [PATCH 05/94] 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 2fb483c1..ae29168f 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -32,3 +32,8 @@ TEST(IsLeap, ReturnTrueIfDevisibleBy400) { ASSERT_TRUE(IsLeap(1600)); } + +TEST(IsLeap, ReturnTrueIfDevisibleBy4AndNotDevisibleBy100) +{ + ASSERT_TRUE(IsLeap(1804)); +} From 84ea9db453001dfe8ae5469e69adb71c66cb63c0 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:56:54 +0300 Subject: [PATCH 06/94] Green test --- 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 ae29168f..94b935de 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 IsLeap(size_t year) { - if (year % 400 == 0) + if (year % 400 == 0 || year % 4 == 0) { return true; } From c70e9f38c866503c0b202a79bfea3ee6215004c9 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 17:58:42 +0300 Subject: [PATCH 07/94] 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 94b935de..aebe17d7 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -37,3 +37,8 @@ TEST(IsLeap, ReturnTrueIfDevisibleBy4AndNotDevisibleBy100) { ASSERT_TRUE(IsLeap(1804)); } + +TEST(IsLeap, ReturnFalseIfDevisibleBy100AndNotDivisibleBy400) +{ + ASSERT_FALSE(IsLeap(1900)); +} From 4b168325c960909ca38fe2ca426f0eab592f1b80 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 18:00:34 +0300 Subject: [PATCH 08/94] Green Test --- 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 aebe17d7..00d56d25 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 IsLeap(size_t year) { + if (year % 100 == 0 && year % 400 != 0) + { + return false; + } if (year % 400 == 0 || year % 4 == 0) { return true; From 5aa80076832367f63f6b6837182535d3eca89414 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 18:07:41 +0300 Subject: [PATCH 09/94] Refactoring. --- tdd_intro/homework/01_leap_year/test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 00d56d25..b753fc33 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,15 +16,15 @@ If your language provides a method in the standard library that does this look-u bool IsLeap(size_t year) { - if (year % 100 == 0 && year % 400 != 0) + if (year % 400 != 0) { - return false; + if (year % 100 == 0) + { + return false; + } } - if (year % 400 == 0 || year % 4 == 0) - { - return true; - } - return false; + + return year % 4 == 0; } TEST(IsLeap, ReturnFalseForOddYears) From a213436d1e89f364ed89cdf95878886ffcd68766 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 18:13:50 +0300 Subject: [PATCH 10/94] Acceptance test. --- tdd_intro/homework/01_leap_year/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index b753fc33..e156fbbb 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -46,3 +46,16 @@ TEST(IsLeap, ReturnFalseIfDevisibleBy100AndNotDivisibleBy400) { ASSERT_FALSE(IsLeap(1900)); } + +TEST(IsLeap, AcceptanceTest) +{ + ASSERT_TRUE(IsLeap(4)); + ASSERT_TRUE(IsLeap(1604)); + ASSERT_TRUE(IsLeap(400)); + ASSERT_TRUE(IsLeap(2000)); + + ASSERT_FALSE(IsLeap(1)); + ASSERT_FALSE(IsLeap(1701)); + ASSERT_FALSE(IsLeap(1700)); + ASSERT_FALSE(IsLeap(1900)); +} From dbb50e399cde659fac136a79ff378070dcac4507 Mon Sep 17 00:00:00 2001 From: MrKris99 <37215549+MrKris99@users.noreply.github.com> Date: Sun, 30 Sep 2018 18:15:44 +0300 Subject: [PATCH 11/94] Small final 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 e156fbbb..95c428b8 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,12 +16,9 @@ If your language provides a method in the standard library that does this look-u bool IsLeap(size_t year) { - if (year % 400 != 0) + if (year % 400 != 0 && year % 100 == 0) { - if (year % 100 == 0) - { - return false; - } + return false; } return year % 4 == 0; From 3930208869e63259cb9b3ac220fb4583860bb529 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:07:26 +0300 Subject: [PATCH 12/94] Red --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 17503028..38b64c2f 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -16,3 +16,8 @@ The last place in a ternary number is the 1's place. The second to last is the 3 If your language provides a method in the standard library to perform the conversion, pretend it doesn't exist and implement it yourself. */ + +TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter) +{ + EXPECT_EQ(ConvertToTernary("a"), 0); +} From a3bb0e919edf95738df6b3f1cab8fba44a1d497f Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:09:14 +0300 Subject: [PATCH 13/94] Green --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 38b64c2f..de58aeb8 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -17,6 +17,11 @@ The last place in a ternary number is the 1's place. The second to last is the 3 If your language provides a method in the standard library to perform the conversion, pretend it doesn't exist and implement it yourself. */ +int ConvertToTernary(const std::string& number) +{ + return 0; +} + TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter) { EXPECT_EQ(ConvertToTernary("a"), 0); From b515066b6af9c2d032fbe1a5b8d6122ed409170a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:15:21 +0300 Subject: [PATCH 14/94] Red --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index de58aeb8..c36d4336 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -26,3 +26,8 @@ TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter) { EXPECT_EQ(ConvertToTernary("a"), 0); } + +TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1) +{ + EXPECT_EQ(ConvertToTernary("1"), 1); +} From 7f60cfa179751a831b807ae1e635dbdf9718e7f4 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:17:18 +0300 Subject: [PATCH 15/94] Green. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index c36d4336..86fb7cd4 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -19,6 +19,11 @@ If your language provides a method in the standard library to perform the conver int ConvertToTernary(const std::string& number) { + if (number == "1") + { + return 1; + } + return 0; } From 0a2094ca8f2e4b65392bc781964c3ed682f8424a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:19:26 +0300 Subject: [PATCH 16/94] Red --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 86fb7cd4..16168215 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -36,3 +36,8 @@ TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1) { EXPECT_EQ(ConvertToTernary("1"), 1); } + +TEST(ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1_2) +{ + EXPECT_EQ(ConvertToTernary("2"), 2); +} From 8f9899d96a8dba2fd11535b84724f6ee660a59d9 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:21:56 +0300 Subject: [PATCH 17/94] green --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 16168215..34efbb62 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -24,6 +24,11 @@ int ConvertToTernary(const std::string& number) return 1; } + if (number == "2") + { + return 2; + } + return 0; } From a75569d7710fa16bde167ac10a1421270a03f314 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:34:47 +0300 Subject: [PATCH 18/94] Refactoring. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 34efbb62..f2ad031f 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -1,4 +1,5 @@ #include +#include /* Convert a ternary number, represented as a string (e.g. '102012'), to its decimal equivalent using first principles. @@ -19,14 +20,11 @@ If your language provides a method in the standard library to perform the conver int ConvertToTernary(const std::string& number) { - if (number == "1") + if (isdigit(number[0])) { - return 1; - } - - if (number == "2") - { - return 2; + std::string firstChar; + firstChar += number[0]; + return std::atoi(firstChar.c_str()); } return 0; From f7533fddd7a8243b4c4ce657992f3b9e7e67bf9a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 15:41:33 +0300 Subject: [PATCH 19/94] Red --- tdd_intro/homework/02_ternary_numbers/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index f2ad031f..6d572857 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -40,7 +40,12 @@ TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1) EXPECT_EQ(ConvertToTernary("1"), 1); } -TEST(ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1_2) +TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals1_2) { EXPECT_EQ(ConvertToTernary("2"), 2); } + +TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals2) +{ + EXPECT_EQ(ConvertToTernary("10"), 3); +} From 3cc14e64bcf78a90f9f2a269ecfc2951036ecb96 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:14:30 +0300 Subject: [PATCH 20/94] Green. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 6d572857..07ab314a 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -20,6 +20,17 @@ If your language provides a method in the standard library to perform the conver int ConvertToTernary(const std::string& number) { + if (number.size() == 2) + { + int result = 0; + std::string firstChar; + firstChar += number[0]; + result += 3 * std::atoi(firstChar.c_str()); + std::string secondChar; + secondChar += number[1]; + return result + std::atoi(secondChar.c_str()); + } + if (isdigit(number[0])) { std::string firstChar; From 9e55f9f6ac51eedb5bbac6848c8e81745fbb49ae Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:32:32 +0300 Subject: [PATCH 21/94] Refactoring (summarized cases with lenght = 1 and lenght = 2). --- .../homework/02_ternary_numbers/test.cpp | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 07ab314a..57ce74ac 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -20,25 +20,19 @@ If your language provides a method in the standard library to perform the conver int ConvertToTernary(const std::string& number) { - if (number.size() == 2) + int result = 0; + for (int i = 1; i <= number.size(); ++i) { - int result = 0; - std::string firstChar; - firstChar += number[0]; - result += 3 * std::atoi(firstChar.c_str()); - std::string secondChar; - secondChar += number[1]; - return result + std::atoi(secondChar.c_str()); + const int pos = number.size() - i; + if (isdigit(number[pos])) + { + std::string curChar; + curChar += number[pos]; + result += pow(3, i - 1) * std::atoi(curChar.c_str()); + } } - if (isdigit(number[0])) - { - std::string firstChar; - firstChar += number[0]; - return std::atoi(firstChar.c_str()); - } - - return 0; + return result; } TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter) From 93bed2efba83ec9e151608308dc7507ec2e25cbc Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:34:55 +0300 Subject: [PATCH 22/94] RED --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 57ce74ac..da68cb35 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -54,3 +54,8 @@ TEST (ConvertToTernary, SuccesfullyConvertStringWithSizeEquals2) { EXPECT_EQ(ConvertToTernary("10"), 3); } + +TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_2) +{ + EXPECT_EQ(ConvertToTernary("1a2b"), 0); +} From bf839deb874e6225d8487695bace80a4f7d13164 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:36:23 +0300 Subject: [PATCH 23/94] Green. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index da68cb35..9cfeb2f0 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -24,12 +24,14 @@ int ConvertToTernary(const std::string& number) for (int i = 1; i <= number.size(); ++i) { const int pos = number.size() - i; - if (isdigit(number[pos])) + if (!isdigit(number[pos])) { - std::string curChar; - curChar += number[pos]; - result += pow(3, i - 1) * std::atoi(curChar.c_str()); + return 0; } + + std::string curChar; + curChar += number[pos]; + result += pow(3, i - 1) * std::atoi(curChar.c_str()); } return result; From 196f707922b9952746543845c16d3391e03dcee4 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:37:55 +0300 Subject: [PATCH 24/94] RED. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 9cfeb2f0..6ae10f2d 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -61,3 +61,8 @@ TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_2) { EXPECT_EQ(ConvertToTernary("1a2b"), 0); } + +TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_3) +{ + EXPECT_EQ(ConvertToTernary("53"), 0); +} From 9044c1dcbfb91eb58ddbc9973eab5a5fb174cb8a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:40:24 +0300 Subject: [PATCH 25/94] Green. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 6ae10f2d..894c5bfe 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -31,6 +31,13 @@ int ConvertToTernary(const std::string& number) std::string curChar; curChar += number[pos]; + + int curNumber = 0; + if (curNumber = std::atoi(curChar.c_str()) > 2) + { + return 0; + } + result += pow(3, i - 1) * std::atoi(curChar.c_str()); } From 35c45b38463c74a0b2f8ca8ca39b42423500594b Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:40:59 +0300 Subject: [PATCH 26/94] Refactoring. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 894c5bfe..70cd38b8 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -38,7 +38,7 @@ int ConvertToTernary(const std::string& number) return 0; } - result += pow(3, i - 1) * std::atoi(curChar.c_str()); + result += pow(3, i - 1) * curNumber; } return result; From 1e556e4e0f830d762a99b62c395dddd634a6a619 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:48:44 +0300 Subject: [PATCH 27/94] Forgot to build tests - fix problem (GREEN). --- tdd_intro/homework/02_ternary_numbers/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 70cd38b8..1a5d73f9 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -33,7 +33,7 @@ int ConvertToTernary(const std::string& number) curChar += number[pos]; int curNumber = 0; - if (curNumber = std::atoi(curChar.c_str()) > 2) + if ((curNumber = std::atoi(curChar.c_str())) > 2) { return 0; } From e2dcb1b2dbad766bc2a76665041a19c154843bac Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 16:56:03 +0300 Subject: [PATCH 28/94] Acceptance --- tdd_intro/homework/02_ternary_numbers/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 1a5d73f9..485946d6 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -73,3 +73,19 @@ TEST (ConvertToTernary, ReturnsZeroIfPassInvalidParameter_3) { EXPECT_EQ(ConvertToTernary("53"), 0); } + +TEST (ConvertToTernary, AcceptanceTests) +{ + EXPECT_EQ(ConvertToTernary("202"), 20); + EXPECT_EQ(ConvertToTernary("2201"), 73); + EXPECT_EQ(ConvertToTernary("12"), 5); + + EXPECT_EQ(ConvertToTernary("abc"), 0); + EXPECT_EQ(ConvertToTernary("d1hj"), 0); + + EXPECT_EQ(ConvertToTernary("4356"), 0); + EXPECT_EQ(ConvertToTernary("7"), 0); + + EXPECT_EQ(ConvertToTernary("a31"), 0); + EXPECT_EQ(ConvertToTernary("zr5"), 0); +} From 4b79407fa2fdbbb4b960d30f13aa4afb282bc041 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 10 Oct 2018 17:02:22 +0300 Subject: [PATCH 29/94] Final refactoring. --- tdd_intro/homework/02_ternary_numbers/test.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 485946d6..9ed37c1a 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -20,25 +20,27 @@ If your language provides a method in the standard library to perform the conver int ConvertToTernary(const std::string& number) { - int result = 0; - for (int i = 1; i <= number.size(); ++i) + const size_t inputSize = number.size(); + size_t result = 0; + + for (size_t i = 1; i <= inputSize; ++i) { - const int pos = number.size() - i; - if (!isdigit(number[pos])) + const char current = number[inputSize - i]; + if (!isdigit(current)) { return 0; } - std::string curChar; - curChar += number[pos]; + std::string curCharStr; + curCharStr += current; int curNumber = 0; - if ((curNumber = std::atoi(curChar.c_str())) > 2) + if ((curNumber = std::atoi(curCharStr.c_str())) > 2) { return 0; } - result += pow(3, i - 1) * curNumber; + result += static_cast(pow(3, i - 1) * curNumber); } return result; From a537402c32f16686edcc717fdf848115dc5b9292 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 16:45:41 +0300 Subject: [PATCH 30/94] Test list. --- tdd_intro/homework/03_bank_ocr/test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index a01540b9..963904a0 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -195,3 +195,14 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", " | _| _||_||_ |_ ||_||_|", " ||_ _| | _||_| ||_| _|" }; + +/* + * test list : + * throws if empty file + * throws if not each line 27 long + * throws if line count mod 3 != 0 + * throws in case of invalid number form + * successful conversation (one id) + * successful conversation (two id's) + * successful conversation (unlimited size) +*/ From edfa61f546ed9291be8935cb512ef2c05b672619 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 16:48:38 +0300 Subject: [PATCH 31/94] Red --- tdd_intro/homework/03_bank_ocr/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 963904a0..9394471f 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -206,3 +206,8 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", * successful conversation (two id's) * successful conversation (unlimited size) */ + +TEST(ParseFile, ThrowsIfEmptyFile) +{ + ASSERT_THROW(ParseFile(""), EmptyFileError); +} From 44af33723173ad005b71ccaf63f3055400307b56 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 16:52:53 +0300 Subject: [PATCH 32/94] Green. --- tdd_intro/homework/03_bank_ocr/test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 9394471f..f825b75b 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -207,6 +207,22 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", * successful conversation (unlimited size) */ +class EmptyFileError : public std::runtime_error +{ +public: + EmptyFileError(const char* what) + : std::runtime_error(what) + {} +}; + +std::vector ParseFile(const std::string& file) +{ + if (file.empty()) + { + throw EmptyFileError("OOPS"); + } +} + TEST(ParseFile, ThrowsIfEmptyFile) { ASSERT_THROW(ParseFile(""), EmptyFileError); From aa2b61d59bc4317ffbcd599dcb69bbb3761a7dc4 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 16:55:15 +0300 Subject: [PATCH 33/94] Red. --- tdd_intro/homework/03_bank_ocr/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index f825b75b..e39497d1 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -227,3 +227,8 @@ TEST(ParseFile, ThrowsIfEmptyFile) { ASSERT_THROW(ParseFile(""), EmptyFileError); } + +TEST(ParseFile, ThrowsIfNotEachLine27Long) +{ + ASSERT_THROW(ParseFile("abc"), LenghtError); +} From 607b641d05e98c7070eb88556553c825923caaa7 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 16:56:51 +0300 Subject: [PATCH 34/94] Green. --- tdd_intro/homework/03_bank_ocr/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index e39497d1..a251d82c 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -215,12 +215,25 @@ class EmptyFileError : public std::runtime_error {} }; +class LenghtError : public std::runtime_error +{ +public: + LenghtError(const char* what) + : std::runtime_error(what) + {} +}; + std::vector ParseFile(const std::string& file) { if (file.empty()) { throw EmptyFileError("OOPS"); } + + if (file == "abc") + { + throw LenghtError("OOPS"); + } } TEST(ParseFile, ThrowsIfEmptyFile) From cc014477690aa26bc9b3bb0e5f61dcea85f064e4 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 17:06:03 +0300 Subject: [PATCH 35/94] Triangulation. --- tdd_intro/homework/03_bank_ocr/test.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index a251d82c..f507381e 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -223,6 +223,23 @@ class LenghtError : public std::runtime_error {} }; +std::vector Split(const std::string& strToSplit) +{ + std::stringstream ss(strToSplit); + std::string item; + std::vector splittedStrings; + while (std::getline(ss, item, '\n')) + { + if (item.size() != 27) + { + throw LenghtError("OOPS"); + } + + splittedStrings.push_back(item); + } + return splittedStrings; +} + std::vector ParseFile(const std::string& file) { if (file.empty()) @@ -230,10 +247,7 @@ std::vector ParseFile(const std::string& file) throw EmptyFileError("OOPS"); } - if (file == "abc") - { - throw LenghtError("OOPS"); - } + Split(file); } TEST(ParseFile, ThrowsIfEmptyFile) From a331c51064923fb0391559c0e43ae61190f65b1f Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 17:19:30 +0300 Subject: [PATCH 36/94] Red. --- tdd_intro/homework/03_bank_ocr/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index f507381e..0c4b0b0f 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -259,3 +259,10 @@ TEST(ParseFile, ThrowsIfNotEachLine27Long) { ASSERT_THROW(ParseFile("abc"), LenghtError); } + +TEST(ParseFile, ThrowsIfLineCountMod3NotZero) +{ + std::string file(27, '_'); + file = file + '\n' + file; + ASSERT_THROW(ParseFile(file), LineCountError); +} From f4a0732e3e817b34299598e2cbb2934d16623a7b Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 17:22:30 +0300 Subject: [PATCH 37/94] Green. --- tdd_intro/homework/03_bank_ocr/test.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 0c4b0b0f..61cb66df 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -223,6 +223,14 @@ class LenghtError : public std::runtime_error {} }; +class LineCountError : public std::runtime_error +{ +public: + LineCountError(const char* what) + : std::runtime_error(what) + {} +}; + std::vector Split(const std::string& strToSplit) { std::stringstream ss(strToSplit); @@ -247,7 +255,12 @@ std::vector ParseFile(const std::string& file) throw EmptyFileError("OOPS"); } - Split(file); + std::vector lines = Split(file); + + if (lines.size() % 3 != 0) + { + throw LineCountError("OOPS"); + } } TEST(ParseFile, ThrowsIfEmptyFile) From 0509c22f3d82abf25817de228cbc96e1c82c91f3 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 17:33:03 +0300 Subject: [PATCH 38/94] Red. --- tdd_intro/homework/03_bank_ocr/test.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 61cb66df..d29bdc2d 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -231,7 +231,7 @@ class LineCountError : public std::runtime_error {} }; -std::vector Split(const std::string& strToSplit) +std::vector SplitByLines(const std::string& strToSplit) { std::stringstream ss(strToSplit); std::string item; @@ -255,7 +255,7 @@ std::vector ParseFile(const std::string& file) throw EmptyFileError("OOPS"); } - std::vector lines = Split(file); + std::vector lines = SplitByLines(file); if (lines.size() % 3 != 0) { @@ -279,3 +279,10 @@ TEST(ParseFile, ThrowsIfLineCountMod3NotZero) file = file + '\n' + file; ASSERT_THROW(ParseFile(file), LineCountError); } + +TEST(SplitByNumbers, ThrowsInCaseOfInvalidNumberForm) +{ + std::string file(27, '_'); + file = file + '\n' + file + '\n' + file; + ASSERT_THROW(SplitByNumbers(file), NumberFormatError); +} From 20d13fdd1173b21ad0b5c1ce844270af259dac07 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 18:20:09 +0300 Subject: [PATCH 39/94] Green. --- tdd_intro/homework/03_bank_ocr/test.cpp | 97 ++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index d29bdc2d..75d6ae09 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -231,6 +231,14 @@ class LineCountError : public std::runtime_error {} }; +class NumberFormatError : public std::runtime_error +{ +public: + NumberFormatError(const char* what) + : std::runtime_error(what) + {} +}; + std::vector SplitByLines(const std::string& strToSplit) { std::stringstream ss(strToSplit); @@ -248,6 +256,92 @@ std::vector SplitByLines(const std::string& strToSplit) return splittedStrings; } +bool operator == (const Digit& lhs, const Digit& rhs) +{ + bool equals = true; + for (size_t i = 0; i < 3; ++i) + { + equals = equals && lhs.lines[i] == rhs.lines[i]; + } + + return equals; +} + +size_t GetDigit(const Digit& digit) +{ + if (digit == s_digit0) + { + return 0; + } + if (digit == s_digit1) + { + return 1; + } + if (digit == s_digit2) + { + return 2; + } + if (digit == s_digit3) + { + return 3; + } + if (digit == s_digit4) + { + return 4; + } + if (digit == s_digit5) + { + return 5; + } + if (digit == s_digit6) + { + return 6; + } + if (digit == s_digit7) + { + return 7; + } + if (digit == s_digit8) + { + return 8; + } + if (digit == s_digit9) + { + return 9; + } + + throw NumberFormatError("OOPS"); +} +std::string GetNumberFromThreeStrings(const std::string& first, const std::string& second, const std::string& third) +{ + std::stringstream stream; + size_t pos = 0; + while (pos < 27) + { + Digit digit; + digit.lines[0] = first.substr(pos, pos + 3); + digit.lines[1] = second.substr(pos, pos + 3); + digit.lines[2] = third.substr(pos, pos + 3); + stream << GetDigit(digit); + pos += 3; + } + + return stream.str(); +} +std::vector SplitByNumbers(const std::vector& lines) +{ + std::vector numbers; + for (size_t i = 0; i < lines.size() / 3; ++i) + { + std::string firstLine = lines[3*i]; + std::string secondLine = lines[3*i + 1]; + std::string thirdLine = lines[3*i + 2]; + numbers.push_back(GetNumberFromThreeStrings(firstLine, secondLine, thirdLine)); + } + + return numbers; +} + std::vector ParseFile(const std::string& file) { if (file.empty()) @@ -284,5 +378,6 @@ TEST(SplitByNumbers, ThrowsInCaseOfInvalidNumberForm) { std::string file(27, '_'); file = file + '\n' + file + '\n' + file; - ASSERT_THROW(SplitByNumbers(file), NumberFormatError); + std::vector files {file, file, file}; + ASSERT_THROW(SplitByNumbers(files), NumberFormatError); } From 21bdd1c7032a44f52b07c6e232b376f5170a27a5 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 18:46:19 +0300 Subject: [PATCH 40/94] Red. --- tdd_intro/homework/03_bank_ocr/test.cpp | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 75d6ae09..a89986c2 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -291,7 +291,7 @@ size_t GetDigit(const Digit& digit) } if (digit == s_digit5) { - return 5; + return 5; } if (digit == s_digit6) { @@ -299,7 +299,7 @@ size_t GetDigit(const Digit& digit) } if (digit == s_digit7) { - return 7; + return 7; } if (digit == s_digit8) { @@ -319,15 +319,16 @@ std::string GetNumberFromThreeStrings(const std::string& first, const std::strin while (pos < 27) { Digit digit; - digit.lines[0] = first.substr(pos, pos + 3); - digit.lines[1] = second.substr(pos, pos + 3); - digit.lines[2] = third.substr(pos, pos + 3); + digit.lines[0] = first.substr(pos, 3); + digit.lines[1] = second.substr(pos, 3); + digit.lines[2] = third.substr(pos, 3); stream << GetDigit(digit); pos += 3; } return stream.str(); } + std::vector SplitByNumbers(const std::vector& lines) { std::vector numbers; @@ -346,14 +347,14 @@ std::vector ParseFile(const std::string& file) { if (file.empty()) { - throw EmptyFileError("OOPS"); + throw EmptyFileError("empty file"); } std::vector lines = SplitByLines(file); if (lines.size() % 3 != 0) { - throw LineCountError("OOPS"); + throw LineCountError("line count error"); } } @@ -381,3 +382,18 @@ TEST(SplitByNumbers, ThrowsInCaseOfInvalidNumberForm) std::vector files {file, file, file}; ASSERT_THROW(SplitByNumbers(files), NumberFormatError); } + +TEST(SplitByNumbers, SuccessfulSplit) +{ + std::vector lines = {s_display123456789.lines[0], s_display123456789.lines[1], s_display123456789.lines[2]}; + auto result = SplitByNumbers(lines); + ASSERT_EQ(result.size(), 1); + ASSERT_EQ(result[0], "123456789"); +} + +TEST(ParseFile, SuccessfulParse) +{ + std::string file = s_display123456789.lines[0] + "\n" + s_display123456789.lines[1] + "\n" + s_display123456789.lines[2]; + std::vector result = ParseFile(file); + ASSERT_EQ(result[1], "123456789"); +} From 05666e26a30473e8b8a1ec20f57fc63bbd80eea0 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 17 Oct 2018 18:48:21 +0300 Subject: [PATCH 41/94] Green (with fix of test). --- tdd_intro/homework/03_bank_ocr/test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index a89986c2..80f775b0 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -343,7 +343,7 @@ std::vector SplitByNumbers(const std::vector& lines) return numbers; } -std::vector ParseFile(const std::string& file) +std::vector ParseFile(const std::string& file) { if (file.empty()) { @@ -356,6 +356,8 @@ std::vector ParseFile(const std::string& file) { throw LineCountError("line count error"); } + + return SplitByNumbers(lines); } TEST(ParseFile, ThrowsIfEmptyFile) @@ -395,5 +397,5 @@ TEST(ParseFile, SuccessfulParse) { std::string file = s_display123456789.lines[0] + "\n" + s_display123456789.lines[1] + "\n" + s_display123456789.lines[2]; std::vector result = ParseFile(file); - ASSERT_EQ(result[1], "123456789"); + ASSERT_EQ(result[0], "123456789"); } From 3095775ea19494e3b39c4e9410e127189e5100d1 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 13:49:24 +0300 Subject: [PATCH 42/94] test list) --- tdd_intro/homework/04_weather_client/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 346ea809..cc06ace2 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -79,3 +79,7 @@ class IWeatherClient virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) = 0; virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) = 0; }; + +/*Test list: + * all methods throws in case of invalid date format + * all methods return right value :) From 6058f1f7be3d8f9b6ca57c849bd61a670eafda4e Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 13:57:31 +0300 Subject: [PATCH 43/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index cc06ace2..d39fb84b 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -68,6 +68,15 @@ class IWeatherServer virtual std::string GetWeather(const std::string& request) = 0; }; +class FakeServer : public IWeatherServer +{ +public: + virtual std::string GetWeather(const std::string& request) override + { + return ""; + } +}; + // Implement this interface class IWeatherClient { @@ -80,6 +89,24 @@ class IWeatherClient virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) = 0; }; +class WeatherClient : public IWeatherClient +{ +public: + virtual double GetAverageTemperature(IWeatherServer& server, const std::string& date) override; + virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override; + virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override; + virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override; + virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override; +}; + /*Test list: * all methods throws in case of invalid date format * all methods return right value :) +*/ + +TEST (WeatherClient, GAT_ThrowsIfInvalidDateFormat) +{ + WeatherClient client; + FakeServer server; + client.GetAverageTemperature(server, ""); +} From bcf5c50240e36596770f5ac293c24794c1f85f74 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 13:58:45 +0300 Subject: [PATCH 44/94] forgot something (still red). --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index d39fb84b..dcdf9827 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -108,5 +108,5 @@ TEST (WeatherClient, GAT_ThrowsIfInvalidDateFormat) { WeatherClient client; FakeServer server; - client.GetAverageTemperature(server, ""); + EXPECT_THROW(client.GetAverageTemperature(server, ""), std::runtime_error); } From b95360d75e96e5ac1b00aebe42d4da0ab29f87ac Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:00:39 +0300 Subject: [PATCH 45/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index dcdf9827..02e4c804 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -92,11 +92,26 @@ class IWeatherClient class WeatherClient : public IWeatherClient { public: - virtual double GetAverageTemperature(IWeatherServer& server, const std::string& date) override; - virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override; - virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override; - virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override; - virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override; + virtual double GetAverageTemperature(IWeatherServer& server, const std::string& date) override + { + throw std::runtime_error(""); + } + virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override + { + return 0; + } + virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override + { + return 0; + } + virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override + { + return 0; + } + virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override + { + return 0; + } }; /*Test list: From 0dfbc26d4f7afe1d729bcbc28037235dcc33a7ed Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:02:16 +0300 Subject: [PATCH 46/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 02e4c804..3cab74df 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -125,3 +125,10 @@ TEST (WeatherClient, GAT_ThrowsIfInvalidDateFormat) FakeServer server; EXPECT_THROW(client.GetAverageTemperature(server, ""), std::runtime_error); } + +TEST(WeatherClient, GMT_ThrowsIfInvalidDateFormat) +{ + WeatherClient client; + FakeServer server; + EXPECT_THROW(client.GetMaximumTemperature(server, ""), std::runtime_error); +} From aed731d319320186a1ec9c1d642c18176565e6d3 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:04:42 +0300 Subject: [PATCH 47/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 3cab74df..f75101a2 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -102,7 +102,7 @@ class WeatherClient : public IWeatherClient } virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override { - return 0; + throw std::runtime_error(""); } virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override { From 1864c44ba02af9b426f5881fb045bb64b7036865 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:05:23 +0300 Subject: [PATCH 48/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index f75101a2..b60e694c 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -132,3 +132,10 @@ TEST(WeatherClient, GMT_ThrowsIfInvalidDateFormat) FakeServer server; EXPECT_THROW(client.GetMaximumTemperature(server, ""), std::runtime_error); } + +TEST(WeatherClient, GMnT_ThrowsIfInvalidDateFormat) +{ + WeatherClient client; + FakeServer server; + EXPECT_THROW(client.GetMinimumTemperature(server, ""), std::runtime_error); +} From 0ced7620c477afdd18104354ca7325afaad8a2c2 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:06:06 +0300 Subject: [PATCH 49/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index b60e694c..420cd51e 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -98,7 +98,7 @@ class WeatherClient : public IWeatherClient } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override { - return 0; + throw std::runtime_error(""); } virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override { From 8b479d2932ec876072301f563bdd8cbe2627291b Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:06:57 +0300 Subject: [PATCH 50/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 420cd51e..7c0f85df 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -139,3 +139,10 @@ TEST(WeatherClient, GMnT_ThrowsIfInvalidDateFormat) FakeServer server; EXPECT_THROW(client.GetMinimumTemperature(server, ""), std::runtime_error); } + +TEST(WeatherClient, GAWD_ThrowsIfInvalidDateFormat) +{ + WeatherClient client; + FakeServer server; + EXPECT_THROW(client.GetAverageWindDirection(server, ""), std::runtime_error); +} From 402e7acdd31474594033baefe627e651b676f846 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:10:16 +0300 Subject: [PATCH 51/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 7c0f85df..9933e6bd 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -106,7 +106,7 @@ class WeatherClient : public IWeatherClient } virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override { - return 0; + throw std::runtime_error(""); } virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override { From 6b39a61e392dac01a79f66c8c6f1ff1b60cc0b68 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:11:49 +0300 Subject: [PATCH 52/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 9933e6bd..352d543b 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -146,3 +146,10 @@ TEST(WeatherClient, GAWD_ThrowsIfInvalidDateFormat) FakeServer server; EXPECT_THROW(client.GetAverageWindDirection(server, ""), std::runtime_error); } + +TEST(WeatherClient, GMWD_ThrowsIfInvalidDateFormat) +{ + WeatherClient client; + FakeServer server; + EXPECT_THROW(client.GetMaximumWindSpeed(server, ""), std::runtime_error); +} From a1f2c365b4628de53ccc24acf8edef852cf4cdbc Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:12:15 +0300 Subject: [PATCH 53/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 352d543b..f7f70c3a 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -110,7 +110,7 @@ class WeatherClient : public IWeatherClient } virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override { - return 0; + throw std::runtime_error(""); } }; From 3780eb32027c6843ff54bdca0f6a98cca5e1c3cf Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:20:39 +0300 Subject: [PATCH 54/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index f7f70c3a..becc90f3 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -153,3 +153,16 @@ TEST(WeatherClient, GMWD_ThrowsIfInvalidDateFormat) FakeServer server; EXPECT_THROW(client.GetMaximumWindSpeed(server, ""), std::runtime_error); } + +TEST(WeatherClient, GAT_Succesful) +{ + WeatherClient client; + FakeServer server; + + const std::string date("31.08.2018"); + + const double expectedValue = (20 + 23 + 33 + 26) / 4; + const double error = std::abs(expectedValue - client.GetAverageTemperature(server, date)); + + EXPECT_TRUE(error < 0.01); +} From d3b8e9de9eae3ff9b9657511b8526ee3bae815fc Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:29:14 +0300 Subject: [PATCH 55/94] Implemented helpful things (still red). --- tdd_intro/homework/04_weather_client/test.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index becc90f3..69e5f7f6 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -47,6 +47,16 @@ Each line means "" : "": #include #include +namespace +{ + std::map g_fakeResults = { + {"31.08.2018;03:00", "20;181;5.1"}, + {"31.08.2018;09:00", "23;204;4.9"}, + {"31.08.2018;15:00", "33;193;4.3"}, + {"31.08.2018;21:00", "26;179;4.5"} + }; +} + struct Weather { short temperature = 0; @@ -73,7 +83,14 @@ class FakeServer : public IWeatherServer public: virtual std::string GetWeather(const std::string& request) override { - return ""; + try + { + return g_fakeResults[request]; + } + catch(const std::exception&) + { + throw std::runtime_error(""); + } } }; From 8d20e883e52f48bd885bc891afa7128390d9c5d1 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:57:27 +0300 Subject: [PATCH 56/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 69e5f7f6..3cd5e128 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -47,16 +47,6 @@ Each line means "" : "": #include #include -namespace -{ - std::map g_fakeResults = { - {"31.08.2018;03:00", "20;181;5.1"}, - {"31.08.2018;09:00", "23;204;4.9"}, - {"31.08.2018;15:00", "33;193;4.3"}, - {"31.08.2018;21:00", "26;179;4.5"} - }; -} - struct Weather { short temperature = 0; @@ -85,13 +75,20 @@ class FakeServer : public IWeatherServer { try { - return g_fakeResults[request]; + return m_fakeResults.at(request); } catch(const std::exception&) { throw std::runtime_error(""); } } +private: + std::map m_fakeResults = { + {"31.08.2018;03:00", "20;181;5.1"}, + {"31.08.2018;09:00", "23;204;4.9"}, + {"31.08.2018;15:00", "33;193;4.3"}, + {"31.08.2018;21:00", "26;179;4.5"} + }; }; // Implement this interface @@ -111,6 +108,22 @@ class WeatherClient : public IWeatherClient public: virtual double GetAverageTemperature(IWeatherServer& server, const std::string& date) override { + std::vector responses = { + server.GetWeather(date + ";03:00"), + server.GetWeather(date + ";09:00"), + server.GetWeather(date + ";15:00"), + server.GetWeather(date + ";21:00") + }; + + double result = 0; + for (const auto& response : responses) + { + size_t pos = response.find(";"); + result += std::atof(std::string(response.begin(), response.begin() + pos).c_str()); + } + + return result / 4; + throw std::runtime_error(""); } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override @@ -178,7 +191,7 @@ TEST(WeatherClient, GAT_Succesful) const std::string date("31.08.2018"); - const double expectedValue = (20 + 23 + 33 + 26) / 4; + const double expectedValue = static_cast(20 + 23 + 33 + 26) / 4; const double error = std::abs(expectedValue - client.GetAverageTemperature(server, date)); EXPECT_TRUE(error < 0.01); From c85fcd7e9d3b3908452e2db08a8d695d08991559 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:58:11 +0300 Subject: [PATCH 57/94] Refactoring. --- tdd_intro/homework/04_weather_client/test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 3cd5e128..74688f6c 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -123,8 +123,6 @@ class WeatherClient : public IWeatherClient } return result / 4; - - throw std::runtime_error(""); } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override { From 634e0dc6f35f46ce3905501d1e6e3413011cc14e Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 14:58:54 +0300 Subject: [PATCH 58/94] Refactoring. --- tdd_intro/homework/04_weather_client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 74688f6c..e98a22cf 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -122,7 +122,7 @@ class WeatherClient : public IWeatherClient result += std::atof(std::string(response.begin(), response.begin() + pos).c_str()); } - return result / 4; + return result / responses.size(); } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override { From c823a10ab7ba35cace8cba4d3e98fca32e02826a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:10:27 +0300 Subject: [PATCH 59/94] Refactoring. --- tdd_intro/homework/04_weather_client/test.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index e98a22cf..92e72503 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -108,12 +108,8 @@ class WeatherClient : public IWeatherClient public: virtual double GetAverageTemperature(IWeatherServer& server, const std::string& date) override { - std::vector responses = { - server.GetWeather(date + ";03:00"), - server.GetWeather(date + ";09:00"), - server.GetWeather(date + ";15:00"), - server.GetWeather(date + ";21:00") - }; + std::vector responses; + GetResponcesFromDate(date, server, responses); double result = 0; for (const auto& response : responses) @@ -140,6 +136,16 @@ class WeatherClient : public IWeatherClient { throw std::runtime_error(""); } +private: + + void GetResponcesFromDate(const std::string& date, IWeatherServer& server, + std::vector& responses) + { + responses.push_back(server.GetWeather(date + ";03:00")); + responses.push_back(server.GetWeather(date + ";09:00")); + responses.push_back(server.GetWeather(date + ";15:00")); + responses.push_back(server.GetWeather(date + ";21:00")); + } }; /*Test list: From 77d92043c5139903ef27cdd38e0372c83d10cf6b Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:14:12 +0300 Subject: [PATCH 60/94] Fixed behavior of fake server (in case of invalid request). --- tdd_intro/homework/04_weather_client/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 92e72503..da33535a 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -79,7 +79,7 @@ class FakeServer : public IWeatherServer } catch(const std::exception&) { - throw std::runtime_error(""); + return ""; } } private: @@ -114,6 +114,11 @@ class WeatherClient : public IWeatherClient double result = 0; for (const auto& response : responses) { + if (response.empty()) + { + throw std::runtime_error(""); + } + size_t pos = response.find(";"); result += std::atof(std::string(response.begin(), response.begin() + pos).c_str()); } From eb1de2cecb502452d3df884d5592dfcb7a9bc347 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:17:09 +0300 Subject: [PATCH 61/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index da33535a..8793c5b8 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -205,3 +205,16 @@ TEST(WeatherClient, GAT_Succesful) EXPECT_TRUE(error < 0.01); } + +TEST(WeatherClient, GMT_Succesful) +{ + WeatherClient client; + FakeServer server; + + const std::string date("31.08.2018"); + + const double expectedValue = 20; + const double error = std::abs(expectedValue - client.GetMinimumTemperature(server, date)); + + EXPECT_TRUE(error < 0.01); +} From ad73c86d2101641d5b865c6cd4d46313f2493ccb Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:25:21 +0300 Subject: [PATCH 62/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 8793c5b8..cf0a82aa 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -127,7 +127,27 @@ class WeatherClient : public IWeatherClient } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override { - throw std::runtime_error(""); + std::vector responses; + GetResponcesFromDate(date, server, responses); + + double result = 1000; // unreal big temperature + for (const auto& response : responses) + { + if (response.empty()) + { + throw std::runtime_error(""); + } + + size_t pos = response.find(";"); + double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); + + if (temp < result) + { + result = temp; + } + } + + return result; } virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override { From 80e70994770aa3871bef36bae4886f93d2a2740a Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:27:55 +0300 Subject: [PATCH 63/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index cf0a82aa..8fa8df5d 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -226,7 +226,7 @@ TEST(WeatherClient, GAT_Succesful) EXPECT_TRUE(error < 0.01); } -TEST(WeatherClient, GMT_Succesful) +TEST(WeatherClient, GMnT_Succesful) { WeatherClient client; FakeServer server; @@ -238,3 +238,17 @@ TEST(WeatherClient, GMT_Succesful) EXPECT_TRUE(error < 0.01); } + +TEST(WeatherClient, GMT_Succesful) +{ + WeatherClient client; + FakeServer server; + + const std::string date("31.08.2018"); + + const double expectedValue = 33; + const double error = std::abs(expectedValue - client.GetMaximumTemperature(server, date)); + + EXPECT_TRUE(error < 0.01); +} + From a7badbb250620e2eb8d316bafc191132f7d7d253 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:29:20 +0300 Subject: [PATCH 64/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 8fa8df5d..cba4bc06 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -151,7 +151,27 @@ class WeatherClient : public IWeatherClient } virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override { - throw std::runtime_error(""); + std::vector responses; + GetResponcesFromDate(date, server, responses); + + double result = -1000; // unreal low temperature + for (const auto& response : responses) + { + if (response.empty()) + { + throw std::runtime_error(""); + } + + size_t pos = response.find(";"); + double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); + + if (temp > result) + { + result = temp; + } + } + + return result; } virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override { From 4b7f893930e308f7d863a01cdb21c9962ea64252 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:37:10 +0300 Subject: [PATCH 65/94] Refactoring. --- tdd_intro/homework/04_weather_client/test.cpp | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index cba4bc06..7eb4ddd4 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -46,6 +46,7 @@ Each line means "" : "": #include #include +#include struct Weather { @@ -127,51 +128,17 @@ class WeatherClient : public IWeatherClient } virtual double GetMinimumTemperature(IWeatherServer& server, const std::string& date) override { - std::vector responses; - GetResponcesFromDate(date, server, responses); - - double result = 1000; // unreal big temperature - for (const auto& response : responses) + return GetExtremumTemperatureByComparator(server, date, [](double left, double right) { - if (response.empty()) - { - throw std::runtime_error(""); - } - - size_t pos = response.find(";"); - double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); - - if (temp < result) - { - result = temp; - } - } - - return result; + return left < right; + }); } virtual double GetMaximumTemperature(IWeatherServer& server, const std::string& date) override { - std::vector responses; - GetResponcesFromDate(date, server, responses); - - double result = -1000; // unreal low temperature - for (const auto& response : responses) + return GetExtremumTemperatureByComparator(server, date, [](double left, double right) { - if (response.empty()) - { - throw std::runtime_error(""); - } - - size_t pos = response.find(";"); - double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); - - if (temp > result) - { - result = temp; - } - } - - return result; + return left > right; + }); } virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override { @@ -191,6 +158,39 @@ class WeatherClient : public IWeatherClient responses.push_back(server.GetWeather(date + ";15:00")); responses.push_back(server.GetWeather(date + ";21:00")); } + + double GetExtremumTemperatureByComparator(IWeatherServer& server, const std::string& date, std::function comp) + { + std::vector responses; + GetResponcesFromDate(date, server, responses); + + double result = 0; + bool initialized = false; + for (const auto& response : responses) + { + if (response.empty()) + { + throw std::runtime_error(""); + } + + const size_t pos = response.find(";"); + double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); + + if (!initialized) + { + result = temp; + initialized = true; + continue; + } + + if (comp(temp, result)) + { + result = temp; + } + } + + return result; + } }; /*Test list: From c1e6668797b9674ccacc3646c9df1c09decc9736 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:40:27 +0300 Subject: [PATCH 66/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 7eb4ddd4..ad7d20e6 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -272,3 +272,17 @@ TEST(WeatherClient, GMT_Succesful) EXPECT_TRUE(error < 0.01); } +TEST(WeatherClient, GAWD_Succesful) +{ + WeatherClient client; + FakeServer server; + + const std::string date("31.08.2018"); + + const double expectedValue = static_cast(181 + 204 + 193 + 179) / 4; + const double error = std::abs(expectedValue - client.GetAverageWindDirection(server, date)); + + EXPECT_TRUE(error < 0.01); +} + + From 6b4057c733f77744187a376bcb6a824bcfdda7ab Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:51:04 +0300 Subject: [PATCH 67/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index ad7d20e6..400a36f8 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -142,7 +142,24 @@ class WeatherClient : public IWeatherClient } virtual double GetAverageWindDirection(IWeatherServer& server, const std::string& date) override { - throw std::runtime_error(""); + std::vector responses; + GetResponcesFromDate(date, server, responses); + + double result = 0; + + for (const auto& response : responses) + { + if (response.empty()) + { + throw std::runtime_error(""); + } + + const size_t pos1 = response.find(";"); + const size_t pos2 = response.find(";", pos1 + 1); + result += std::atof(std::string(response.begin() + pos1 + 1, response.begin() + pos2).c_str()); + } + + return result / responses.size(); } virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override { From 9ae5298b4bb7ff88026196a7b13d96be6e71ea3f Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 15:54:18 +0300 Subject: [PATCH 68/94] Red. --- tdd_intro/homework/04_weather_client/test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 400a36f8..8383d3af 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -302,4 +302,15 @@ TEST(WeatherClient, GAWD_Succesful) EXPECT_TRUE(error < 0.01); } +TEST(WeatherClient, GMWD_Succesful) +{ + WeatherClient client; + FakeServer server; + + const std::string date("31.08.2018"); + + const double expectedValue = 5.1; + const double error = std::abs(expectedValue - client.GetMaximumWindSpeed(server, date)); + EXPECT_TRUE(error < 0.01); +} From fa01dae80fcb884f9a146964235411ed170eeaad Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 16:02:11 +0300 Subject: [PATCH 69/94] Green. --- tdd_intro/homework/04_weather_client/test.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 8383d3af..e4506802 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -163,8 +163,31 @@ class WeatherClient : public IWeatherClient } virtual double GetMaximumWindSpeed(IWeatherServer& server, const std::string& date) override { - throw std::runtime_error(""); + std::vector responses; + GetResponcesFromDate(date, server, responses); + + double result = 0; + + for (const auto& response : responses) + { + if (response.empty()) + { + throw std::runtime_error(""); + } + + const size_t pos1 = response.find(";"); + const size_t pos2 = response.find(";", pos1 + 1); + double temp = std::atof(std::string(response.begin() + pos2 + 1, response.end()).c_str()); + + if (temp > result) + { + result = temp; + } + } + + return result; } + private: void GetResponcesFromDate(const std::string& date, IWeatherServer& server, From fbe700c41ee3c92df2f2372e35c3b0508f261c61 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 24 Oct 2018 16:05:25 +0300 Subject: [PATCH 70/94] Refactoring. --- tdd_intro/homework/04_weather_client/test.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index e4506802..1e7a04c5 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -74,14 +74,7 @@ class FakeServer : public IWeatherServer public: virtual std::string GetWeather(const std::string& request) override { - try - { - return m_fakeResults.at(request); - } - catch(const std::exception&) - { - return ""; - } + return m_fakeResults.count(request) ? m_fakeResults[request] : ""; } private: std::map m_fakeResults = { @@ -206,6 +199,7 @@ class WeatherClient : public IWeatherClient double result = 0; bool initialized = false; + for (const auto& response : responses) { if (response.empty()) @@ -214,7 +208,7 @@ class WeatherClient : public IWeatherClient } const size_t pos = response.find(";"); - double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); + const double temp = std::atof(std::string(response.begin(), response.begin() + pos).c_str()); if (!initialized) { From 9c6fd82394ee94b50fee15308efd743dd344bac7 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 14:57:50 +0200 Subject: [PATCH 71/94] Red. --- tdd_intro/homework/05_word_wrapp/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index 77e47210..a0c8beca 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -94,3 +94,9 @@ TEST(WrapString, StringWrappedBySeveralWhitespace) WrappedStrings expected = {"12", "34"}; ASSERT_EQ(expected, WrapString("12 34", 3)); } + +TEST(WrapString, StringWrappedBySeveralWhitespace2) +{ + WrappedStrings expected = {"12", "34"}; + ASSERT_EQ(expected, WrapString("12 34", 3)); +} From 8c4d50763bb1faede366bd80fe741ea517f6aa7e Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:07:39 +0200 Subject: [PATCH 72/94] Green. --- tdd_intro/homework/05_word_wrapp/test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index a0c8beca..9ada1f47 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -36,7 +36,8 @@ WrappedStrings WrapString(const std::string& str, size_t wrapLength) for(size_t i = 0; i < str.length(); i += wrapLength) { std::string cur = str.substr(i, wrapLength); - if (cur.back() == ' ') + + while (!cur.empty() && cur.back() == ' ') { cur.pop_back(); } From f62436e345829a93b6e19eba62300436c220f20d Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:14:22 +0200 Subject: [PATCH 73/94] Red. --- tdd_intro/homework/05_word_wrapp/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index 9ada1f47..cb96baaa 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -101,3 +101,9 @@ TEST(WrapString, StringWrappedBySeveralWhitespace2) WrappedStrings expected = {"12", "34"}; ASSERT_EQ(expected, WrapString("12 34", 3)); } + +TEST(WrapString, StringWrappedBySeveralWhitespace3) +{ + WrappedStrings expected = {"123", "34"}; + ASSERT_EQ(expected, WrapString("123 34", 4)); +} From c3d03c13498a96fe421d115946714ad3fb03a0a1 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:17:09 +0200 Subject: [PATCH 74/94] Green. --- tdd_intro/homework/05_word_wrapp/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index cb96baaa..b70a5b97 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -42,7 +42,7 @@ WrappedStrings WrapString(const std::string& str, size_t wrapLength) cur.pop_back(); } - if(!cur.empty() && cur.front() == ' ') + while (!cur.empty() && cur.front() == ' ') { cur = cur.substr(1); } From 757ed560b9f79b14b7fc9e38e088cb651c08d302 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:30:14 +0200 Subject: [PATCH 75/94] refactoring. --- tdd_intro/homework/05_word_wrapp/test.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index b70a5b97..854f5a60 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -42,10 +42,12 @@ WrappedStrings WrapString(const std::string& str, size_t wrapLength) cur.pop_back(); } - while (!cur.empty() && cur.front() == ' ') + auto it = std::find_if_not(cur.cbegin(), cur.cend(), [](char elem) { - cur = cur.substr(1); - } + return elem == ' '; + }); + + cur.erase(cur.begin(), it); if(!cur.empty()) { From d8c6e1e083b3045343797bd60e8284874af383ec Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:42:36 +0200 Subject: [PATCH 76/94] Refactoring + acceptance. --- tdd_intro/homework/05_word_wrapp/test.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index 854f5a60..6a7464c5 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -42,12 +42,15 @@ WrappedStrings WrapString(const std::string& str, size_t wrapLength) cur.pop_back(); } - auto it = std::find_if_not(cur.cbegin(), cur.cend(), [](char elem) + if (!cur.empty() && cur.front() == ' ') { - return elem == ' '; - }); + auto it = std::find_if_not(cur.cbegin(), cur.cend(), [](char elem) + { + return elem == ' '; + }); - cur.erase(cur.begin(), it); + cur.erase(cur.begin(), it); + } if(!cur.empty()) { @@ -109,3 +112,12 @@ TEST(WrapString, StringWrappedBySeveralWhitespace3) WrappedStrings expected = {"123", "34"}; ASSERT_EQ(expected, WrapString("123 34", 4)); } + +TEST(WrapString, Acceptance) +{ + WrappedStrings expected = {"1234567", "34567", "12 456"}; + ASSERT_EQ(expected, WrapString("1234567 34567 12 456", 7)); + + WrappedStrings expected2 = {"abcd", "efg", "qwe", "rty", "asdf", "gh"}; + ASSERT_EQ(expected2, WrapString("abcd efg qwerty asdf gh", 4)); +} From 3749c0aaf74970afcf490a88e82243b9bacc41d3 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Thu, 1 Nov 2018 15:46:35 +0200 Subject: [PATCH 77/94] add test from list (GREEN). --- tdd_intro/homework/05_word_wrapp/test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tdd_intro/homework/05_word_wrapp/test.cpp b/tdd_intro/homework/05_word_wrapp/test.cpp index 6a7464c5..4eea25b5 100644 --- a/tdd_intro/homework/05_word_wrapp/test.cpp +++ b/tdd_intro/homework/05_word_wrapp/test.cpp @@ -113,6 +113,13 @@ TEST(WrapString, StringWrappedBySeveralWhitespace3) ASSERT_EQ(expected, WrapString("123 34", 4)); } +TEST(WrapString, OnlyWhiteSpaces) +{ + WrappedStrings expected; + ASSERT_EQ(expected, WrapString(" ", 4)); + ASSERT_EQ(expected, WrapString(" ", 1)); +} + TEST(WrapString, Acceptance) { WrappedStrings expected = {"1234567", "34567", "12 456"}; From e7cd3ab055be7883b2d0839c47c819cb5e240376 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:21:08 +0200 Subject: [PATCH 78/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 33b9093e..45008046 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -59,16 +59,19 @@ class MockSourceOfIngredients : public ISourceOfIngredients class CoffeeMachine { public: - CoffeeMachine(ISourceOfIngredients& source) : m_source(source) + CoffeeMachine(ISourceOfIngredients& source) + : m_source(source) { } - void CreateCoffee(const Cup cup, const Coffee coffee) + + void CreateCoffee(Cup cup, Coffee coffee) { m_source.AddCoffee(0); m_source.SetCupSize(0); m_source.AddWater(0, 0); } + private: ISourceOfIngredients& m_source; }; @@ -117,3 +120,16 @@ TEST(CoffeeMachine, Americano) cm.CreateCoffee(Cup::Normal, Coffee::Americano); } + +TEST(CoffeeMachine, Cappuccino) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(33)).Times(1); + EXPECT_CALL(si, AddMilk(33)).Times(1); + EXPECT_CALL(si, AddMilkFoam(33)).Times(1); + EXPECT_CALL(si, SetCupSize(100)).Times(1); + + cm.CreateCoffee(Cup::Normal, Coffee::Cappucino); +} From b216fc0f5385853cb01637c24f1b6bfbf5b4573e Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:25:53 +0200 Subject: [PATCH 79/94] Forgot that the last test was red. Fixed. (GREEN). --- tdd_intro/homework/06_coffee/test.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 45008046..820be74b 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -40,7 +40,8 @@ enum Cup enum Coffee { - Americano + Americano, + Cappuccino }; class MockSourceOfIngredients : public ISourceOfIngredients @@ -67,9 +68,18 @@ class CoffeeMachine void CreateCoffee(Cup cup, Coffee coffee) { - m_source.AddCoffee(0); - m_source.SetCupSize(0); - m_source.AddWater(0, 0); + if (coffee == Americano) + { + m_source.AddCoffee(75); + m_source.SetCupSize(100); + m_source.AddWater(25, 60); + return; + } + + m_source.SetCupSize(100); + m_source.AddMilkFoam(33); + m_source.AddCoffee(33); + m_source.AddMilk(33); } private: @@ -131,5 +141,5 @@ TEST(CoffeeMachine, Cappuccino) EXPECT_CALL(si, AddMilkFoam(33)).Times(1); EXPECT_CALL(si, SetCupSize(100)).Times(1); - cm.CreateCoffee(Cup::Normal, Coffee::Cappucino); + cm.CreateCoffee(Cup::Normal, Coffee::Cappuccino); } From 0a6491cf406198aed81450e96861b8ef0616f076 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:30:42 +0200 Subject: [PATCH 80/94] Refactoring. --- tdd_intro/homework/06_coffee/test.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 820be74b..1dbb40ab 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -68,18 +68,26 @@ class CoffeeMachine void CreateCoffee(Cup cup, Coffee coffee) { - if (coffee == Americano) + switch (coffee) + { + case (Americano) : { m_source.AddCoffee(75); m_source.SetCupSize(100); m_source.AddWater(25, 60); - return; + break; + } + case (Cappuccino) : + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(33); + m_source.AddCoffee(33); + m_source.AddMilk(33); + break; + } } - m_source.SetCupSize(100); - m_source.AddMilkFoam(33); - m_source.AddCoffee(33); - m_source.AddMilk(33); + } private: From 24fbc6aa515dd516b53bf7165eff8843ba980c78 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:34:38 +0200 Subject: [PATCH 81/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 1dbb40ab..95268b20 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -151,3 +151,16 @@ TEST(CoffeeMachine, Cappuccino) cm.CreateCoffee(Cup::Normal, Coffee::Cappuccino); } + +TEST(CoffeeMachine, Latte) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(50)).Times(1); + EXPECT_CALL(si, AddMilk(25)).Times(1); + EXPECT_CALL(si, AddMilkFoam(25)).Times(1); + EXPECT_CALL(si, SetCupSize(100)).Times(1); + + cm.CreateCoffee(Cup::Normal, Coffee::Latte); +} From 64e4154357d88686a5ccc548a9a22ad591d81e21 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:37:25 +0200 Subject: [PATCH 82/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 95268b20..f019bb13 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -41,7 +41,8 @@ enum Cup enum Coffee { Americano, - Cappuccino + Cappuccino, + Latte }; class MockSourceOfIngredients : public ISourceOfIngredients @@ -85,6 +86,13 @@ class CoffeeMachine m_source.AddMilk(33); break; } + case (Latte) : + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(25); + m_source.AddCoffee(50); + m_source.AddMilk(25); + } } From bcbe079166990fb4ddd448f0d0255f0a289da5d3 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:39:26 +0200 Subject: [PATCH 83/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index f019bb13..39f6d4be 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -172,3 +172,16 @@ TEST(CoffeeMachine, Latte) cm.CreateCoffee(Cup::Normal, Coffee::Latte); } + +TEST(CoffeeMachine, Marochino) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(25)).Times(1); + EXPECT_CALL(si, AddChocolate(25)).Times(1); + EXPECT_CALL(si, AddMilkFoam(25)).Times(1); + EXPECT_CALL(si, SetCupSize(100)).Times(1); + + cm.CreateCoffee(Cup::Normal, Coffee::Marochino); +} From 97cff32d41eefbb01172fffe29c7cf078809576b Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:42:10 +0200 Subject: [PATCH 84/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 39f6d4be..88961ea6 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -42,7 +42,8 @@ enum Coffee { Americano, Cappuccino, - Latte + Latte, + Marochino }; class MockSourceOfIngredients : public ISourceOfIngredients @@ -92,6 +93,15 @@ class CoffeeMachine m_source.AddMilkFoam(25); m_source.AddCoffee(50); m_source.AddMilk(25); + break; + } + case (Marochino) : + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(25); + m_source.AddCoffee(25); + m_source.AddChocolate(25); + break; } } From d25e52c9aa23ea670bc2bafba24101c833c002e6 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 15:52:10 +0200 Subject: [PATCH 85/94] Refactoring. --- tdd_intro/homework/06_coffee/test.cpp | 57 ++++++++++++++++----------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 88961ea6..e6242da5 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -73,39 +73,50 @@ class CoffeeMachine switch (coffee) { case (Americano) : - { - m_source.AddCoffee(75); - m_source.SetCupSize(100); - m_source.AddWater(25, 60); + PerformAmericano(cup); break; - } case (Cappuccino) : - { - m_source.SetCupSize(100); - m_source.AddMilkFoam(33); - m_source.AddCoffee(33); - m_source.AddMilk(33); + PerformCappucino(cup); break; - } case (Latte) : - { - m_source.SetCupSize(100); - m_source.AddMilkFoam(25); - m_source.AddCoffee(50); - m_source.AddMilk(25); + PerformLatte(cup); break; - } case (Marochino) : - { - m_source.SetCupSize(100); - m_source.AddMilkFoam(25); - m_source.AddCoffee(25); - m_source.AddChocolate(25); + PerformMarochino(cup); break; } - } + } +private: + void PerformAmericano(Cup cup) + { + m_source.AddCoffee(75); + m_source.SetCupSize(100); + m_source.AddWater(25, 60); + } + + void PerformCappucino(Cup cup) + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(33); + m_source.AddCoffee(33); + m_source.AddMilk(33); + } + void PerformLatte(Cup cup) + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(25); + m_source.AddCoffee(50); + m_source.AddMilk(25); + } + + void PerformMarochino(Cup cup) + { + m_source.SetCupSize(100); + m_source.AddMilkFoam(25); + m_source.AddCoffee(25); + m_source.AddChocolate(25); } private: From 53af55869be5ebec0038b1746e659c6ae0a8ea09 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:00:05 +0200 Subject: [PATCH 86/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index e6242da5..c0c0c963 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -206,3 +206,15 @@ TEST(CoffeeMachine, Marochino) cm.CreateCoffee(Cup::Normal, Coffee::Marochino); } + +TEST(CoffeeMachine, BigAmericano) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(105)).Times(1); + EXPECT_CALL(si, SetCupSize(140)).Times(1); + EXPECT_CALL(si, AddWater(35, 60)).Times(1); + + cm.CreateCoffee(Cup::Big, Coffee::Americano); +} From 335a471476820bd15e11cace6adec8ae15b81fbb Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:03:53 +0200 Subject: [PATCH 87/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index c0c0c963..7ecfe804 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -90,9 +90,10 @@ class CoffeeMachine private: void PerformAmericano(Cup cup) { - m_source.AddCoffee(75); - m_source.SetCupSize(100); - m_source.AddWater(25, 60); + const double factor = cup == Normal ? 1 : 1.4; + m_source.AddCoffee(75 * factor); + m_source.SetCupSize(100 * factor); + m_source.AddWater(25 * factor, 60); } void PerformCappucino(Cup cup) From 30bb8206079fe402b32b85a56739766838c9a462 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:06:53 +0200 Subject: [PATCH 88/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 7ecfe804..d9993b33 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -219,3 +219,16 @@ TEST(CoffeeMachine, BigAmericano) cm.CreateCoffee(Cup::Big, Coffee::Americano); } + +TEST(CoffeeMachine, BigCappuccino) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(46)).Times(1); + EXPECT_CALL(si, AddMilk(46)).Times(1); + EXPECT_CALL(si, AddMilkFoam(46)).Times(1); + EXPECT_CALL(si, SetCupSize(140)).Times(1); + + cm.CreateCoffee(Cup::Big, Coffee::Cappuccino); +} From ad2e550219d66f17c1554311806b219d81ce3c97 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:07:52 +0200 Subject: [PATCH 89/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index d9993b33..e85a9ea6 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -98,10 +98,11 @@ class CoffeeMachine void PerformCappucino(Cup cup) { - m_source.SetCupSize(100); - m_source.AddMilkFoam(33); - m_source.AddCoffee(33); - m_source.AddMilk(33); + const double factor = cup == Normal ? 1 : 1.4; + m_source.SetCupSize(100 * factor); + m_source.AddMilkFoam(33 * factor); + m_source.AddCoffee(33 * factor); + m_source.AddMilk(33 * factor); } void PerformLatte(Cup cup) From c9b60461212c0e8e3f2e5c7a0ff1ebe58a446788 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:10:39 +0200 Subject: [PATCH 90/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index e85a9ea6..ad726a6d 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -233,3 +233,16 @@ TEST(CoffeeMachine, BigCappuccino) cm.CreateCoffee(Cup::Big, Coffee::Cappuccino); } + +TEST(CoffeeMachine, BigLatte) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(70)).Times(1); + EXPECT_CALL(si, AddMilk(35)).Times(1); + EXPECT_CALL(si, AddMilkFoam(35)).Times(1); + EXPECT_CALL(si, SetCupSize(140)).Times(1); + + cm.CreateCoffee(Cup::Big, Coffee::Latte); +} From 39561ac06176f7cbd8d0e70428e8cc022cd3f3bd Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:11:58 +0200 Subject: [PATCH 91/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index ad726a6d..500c05aa 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -107,10 +107,11 @@ class CoffeeMachine void PerformLatte(Cup cup) { - m_source.SetCupSize(100); - m_source.AddMilkFoam(25); - m_source.AddCoffee(50); - m_source.AddMilk(25); + const double factor = cup == Normal ? 1 : 1.4; + m_source.SetCupSize(100 * factor); + m_source.AddMilkFoam(25 * factor); + m_source.AddCoffee(50 * factor); + m_source.AddMilk(25 * factor); } void PerformMarochino(Cup cup) From 4d259b7b80f31dd53cf71cd6229382f0d1e9579d Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:13:18 +0200 Subject: [PATCH 92/94] Red. --- tdd_intro/homework/06_coffee/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 500c05aa..bd47f9dc 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -247,3 +247,16 @@ TEST(CoffeeMachine, BigLatte) cm.CreateCoffee(Cup::Big, Coffee::Latte); } + +TEST(CoffeeMachine, BigMarochino) +{ + MockSourceOfIngredients si; + CoffeeMachine cm(si); + + EXPECT_CALL(si, AddCoffee(35)).Times(1); + EXPECT_CALL(si, AddChocolate(35)).Times(1); + EXPECT_CALL(si, AddMilkFoam(35)).Times(1); + EXPECT_CALL(si, SetCupSize(140)).Times(1); + + cm.CreateCoffee(Cup::Big, Coffee::Marochino); +} From 899c19110a5f967880e741acb2e21ec8858498af Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:14:37 +0200 Subject: [PATCH 93/94] Green. --- tdd_intro/homework/06_coffee/test.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index bd47f9dc..678ff625 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -116,10 +116,11 @@ class CoffeeMachine void PerformMarochino(Cup cup) { - m_source.SetCupSize(100); - m_source.AddMilkFoam(25); - m_source.AddCoffee(25); - m_source.AddChocolate(25); + const double factor = cup == Normal ? 1 : 1.4; + m_source.SetCupSize(100 * factor); + m_source.AddMilkFoam(25 * factor); + m_source.AddCoffee(25 * factor); + m_source.AddChocolate(25 * factor); } private: From a0987f9ab9a105d820e46b31772952e0dbbddd97 Mon Sep 17 00:00:00 2001 From: MrKris99 Date: Wed, 14 Nov 2018 16:28:26 +0200 Subject: [PATCH 94/94] Removed dummy tests. --- tdd_intro/homework/06_coffee/test.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tdd_intro/homework/06_coffee/test.cpp b/tdd_intro/homework/06_coffee/test.cpp index 678ff625..a07aaf41 100644 --- a/tdd_intro/homework/06_coffee/test.cpp +++ b/tdd_intro/homework/06_coffee/test.cpp @@ -141,24 +141,6 @@ class CoffeeMachine // 4. Check parameters // 5. Same for each recipe -TEST(CoffeeMachine, CoffemachineIsHere) -{ - MockSourceOfIngredients si; - CoffeeMachine cm(si); -} - -TEST(CoffeeMachine, CallsImportantThings) -{ - MockSourceOfIngredients si; - CoffeeMachine cm(si); - - EXPECT_CALL(si, AddCoffee(::testing::_)).Times(1); - EXPECT_CALL(si, SetCupSize(::testing::_)).Times(1); - EXPECT_CALL(si, AddWater(::testing::_, ::testing::_)).Times(1); - - cm.CreateCoffee(Cup::Normal, Coffee::Americano); -} - //- americano: water & coffee 1:3 Water temp 60C TEST(CoffeeMachine, Americano) {