From 6504f38ebe7e0c24c5f3802ed492daf2aad00309 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 20:58:01 +0300 Subject: [PATCH 01/98] RED --- tdd_intro/homework/01_leap_year/test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 4f186c8b..5e457262 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,11 @@ If your language provides a method in the standard library that does this look-u */ #include + + + + +TEST(LeapYear, DevidedBy4) +{ + ASSERT_TRUE(LeapYear(4)); +} From 1fba6cee2919b17fac1614f642e1fc95f8090511 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:00:54 +0300 Subject: [PATCH 02/98] RED --- tdd_intro/homework/01_leap_year/test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 5e457262..c8e11e76 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,7 +16,6 @@ If your language provides a method in the standard library that does this look-u - TEST(LeapYear, DevidedBy4) { ASSERT_TRUE(LeapYear(4)); From c035067f6b7b6f3e2136a9528864e5685506cfae Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:07:15 +0300 Subject: [PATCH 03/98] Green --- tdd_intro/homework/01_leap_year/test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index c8e11e76..9c8a77bb 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -14,7 +14,13 @@ If your language provides a method in the standard library that does this look-u #include - +bool LeapYear(int year) +{ + if (year%4 == 0) + { + return true; + } +} TEST(LeapYear, DevidedBy4) { From b7958867fb7b6883f71df9091e4189bad479ea0d Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:14:42 +0300 Subject: [PATCH 04/98] Red --- 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 9c8a77bb..693796f0 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -20,9 +20,15 @@ bool LeapYear(int year) { return true; } + return false; } TEST(LeapYear, DevidedBy4) { ASSERT_TRUE(LeapYear(4)); } + +TEST(LeapYear, DevidedBy100) +{ + ASSERT_FALSE(LeapYear(100)); +} From 553eac29dd0ad0953ca2ee04aa8e9bffb119b0aa Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:15:39 +0300 Subject: [PATCH 05/98] Green --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 693796f0..f986a8cd 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 LeapYear(int year) { + if (year%100 == 0) + { + return false; + } if (year%4 == 0) { return true; From 6e72467fac2f530a4c9d1de212409fec6e1f438e Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:17:15 +0300 Subject: [PATCH 06/98] Red --- 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 f986a8cd..9ca987c2 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -36,3 +36,8 @@ TEST(LeapYear, DevidedBy100) { ASSERT_FALSE(LeapYear(100)); } + +TEST(LeapYear, DevidedBy400) +{ + ASSERT_TRUE(LeapYear(400)); +} From 03397ddbe6618046fedca06287b69808cf50705a Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:18:27 +0300 Subject: [PATCH 07/98] Green --- tdd_intro/homework/01_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 9ca987c2..436c9b13 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 LeapYear(int year) { + if (year%400 == 0) + { + return true; + } if (year%100 == 0) { return false; From 35d5e67675b3eed09006f146361b9fb444e7c42c Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:21:17 +0300 Subject: [PATCH 08/98] Green --- tdd_intro/homework/01_leap_year/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 436c9b13..6b243f52 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -45,3 +45,13 @@ TEST(LeapYear, DevidedBy400) { ASSERT_TRUE(LeapYear(400)); } + +TEST(LeapYear, RandomYearsTest) +{ + ASSERT_TRUE(LeapYear(2000)); + ASSERT_FALSE(LeapYear(1000)); + ASSERT_TRUE(LeapYear(1996)); + ASSERT_FALSE(LeapYear(1997)); + ASSERT_TRUE(LeapYear(2020)); + ASSERT_FALSE(LeapYear(2018)); +} From c823ffb6e5c99f911504914a2a09221b522fd818 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Tue, 2 Oct 2018 21:22:26 +0300 Subject: [PATCH 09/98] Green --- tdd_intro/homework/01_leap_year/test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 6b243f52..9f60fafd 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -54,4 +54,6 @@ TEST(LeapYear, RandomYearsTest) ASSERT_FALSE(LeapYear(1997)); ASSERT_TRUE(LeapYear(2020)); ASSERT_FALSE(LeapYear(2018)); + ASSERT_TRUE(LeapYear(-2000)); + ASSERT_FALSE(LeapYear(-1000)); } From 1161ec0f440dcae85c8b0c60ac3d59fa34801307 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:01:32 +0300 Subject: [PATCH 10/98] Red Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 17503028..0f7b983f 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -16,3 +16,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. */ + +#include + + +TEST(TernaryNumbers, EmptyString) +{ + ASSERT_EQ(0, DemicalView("")); +} From 20c6e9d92eecf5e1c2ccb846743b8c081c88082d Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:18:21 +0300 Subject: [PATCH 11/98] Green Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 0f7b983f..c5123bed 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -19,6 +19,10 @@ If your language provides a method in the standard library to perform the conver #include +int DemicalView(std::string str) +{ + return 0; +} TEST(TernaryNumbers, EmptyString) { From 5a8042ed03e7acb85bad01dac4938b93d4887600 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:20:23 +0300 Subject: [PATCH 12/98] Red Signed-off-by: Alexander Potapov --- 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 c5123bed..081a6554 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -28,3 +28,8 @@ TEST(TernaryNumbers, EmptyString) { ASSERT_EQ(0, DemicalView("")); } + +TEST(TernaryNumbers, EqualOne) +{ + ASSERT_EQ(1, DemicalView("1")); +} From 86ac94c65cf03721bd2fe3450035e3a6690e9533 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:22:25 +0300 Subject: [PATCH 13/98] Green Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 081a6554..c68f93f1 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -21,6 +21,10 @@ If your language provides a method in the standard library to perform the conver int DemicalView(std::string str) { + if (str == "1") + { + return 1; + } return 0; } From d3940b85f12e0d44bad0f5a984ea042752916377 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:23:18 +0300 Subject: [PATCH 14/98] Red Signed-off-by: Alexander Potapov --- 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 c68f93f1..50e53d79 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -37,3 +37,8 @@ TEST(TernaryNumbers, EqualOne) { ASSERT_EQ(1, DemicalView("1")); } + +TEST(TernaryNumbers, EqualTwo) +{ + ASSERT_EQ(2, DemicalView("2")); +} From 37b3eca7bc71fd4ea94fc6601db57b8b9c823de6 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:25:07 +0300 Subject: [PATCH 15/98] Green Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 50e53d79..e6abe59e 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -25,6 +25,15 @@ int DemicalView(std::string str) { return 1; } + if (str == "2") + { + return 2; + } + if (str == "0") + { + return 0; + } + return 0; } From 420c40f7905d0e700edc16a232564b257007feb5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:27:38 +0300 Subject: [PATCH 16/98] Refactored Green Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index e6abe59e..96be080f 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -21,19 +21,10 @@ If your language provides a method in the standard library to perform the conver int DemicalView(std::string str) { - if (str == "1") + if (str == "1" || str == "2" || str == "3") { - return 1; + return std::stoi( str ); } - if (str == "2") - { - return 2; - } - if (str == "0") - { - return 0; - } - return 0; } From bce290fe7908731cd674dbbab01eb8e7ff52ddac Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:29:20 +0300 Subject: [PATCH 17/98] Red Signed-off-by: Alexander Potapov --- 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 96be080f..386ed64b 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -42,3 +42,8 @@ TEST(TernaryNumbers, EqualTwo) { ASSERT_EQ(2, DemicalView("2")); } + +TEST(TernaryNumbers, TwoCharString) +{ + ASSERT_EQ(1, DemicalView("01")); +} From d7cec8e51322ad7035ad0228fc6c477573f9bb9b Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:53:00 +0300 Subject: [PATCH 18/98] Green Signed-off-by: Alexander Potapov --- .../homework/02_ternary_numbers/test.cpp | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index 386ed64b..d9afaa21 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -19,13 +19,26 @@ If your language provides a method in the standard library to perform the conver #include -int DemicalView(std::string str) +int OneSignDemicalView(const std::string& oneSign) { - if (str == "1" || str == "2" || str == "3") + if (oneSign == "1" || oneSign == "2" || oneSign == "0") { - return std::stoi( str ); + + return std::stoi( oneSign ); } - return 0; + return -1; +} + +int DemicalView(const std::string& str) +{ + if (str.empty()) + { + return 0; + } + int answer = 0; + answer += OneSignDemicalView(str.substr(str.size() - 1 , 1)); + + return (answer > 0)? answer : 0; } TEST(TernaryNumbers, EmptyString) @@ -43,7 +56,7 @@ TEST(TernaryNumbers, EqualTwo) ASSERT_EQ(2, DemicalView("2")); } -TEST(TernaryNumbers, TwoCharString) +TEST(TernaryNumbers, TwoSignString) { ASSERT_EQ(1, DemicalView("01")); } From 826c85ee20ba0672bea63dad63da9820bf1411e5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 14:53:58 +0300 Subject: [PATCH 19/98] Red Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index d9afaa21..f9444b83 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -36,6 +36,7 @@ int DemicalView(const std::string& str) return 0; } int answer = 0; + answer += OneSignDemicalView(str.substr(str.size() - 1 , 1)); return (answer > 0)? answer : 0; @@ -56,7 +57,12 @@ TEST(TernaryNumbers, EqualTwo) ASSERT_EQ(2, DemicalView("2")); } -TEST(TernaryNumbers, TwoSignString) +TEST(TernaryNumbers, TwoSignString01) { ASSERT_EQ(1, DemicalView("01")); } + +TEST(TernaryNumbers, TwoSignString11) +{ + ASSERT_EQ(4, DemicalView("11")); +} From dba60a2602eea7bf8c3b6156955fab9a43d914b9 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 15:02:11 +0300 Subject: [PATCH 20/98] Green Signed-off-by: Alexander Potapov --- 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 f9444b83..d530018c 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -36,10 +36,11 @@ int DemicalView(const std::string& str) return 0; } int answer = 0; - - answer += OneSignDemicalView(str.substr(str.size() - 1 , 1)); - - return (answer > 0)? answer : 0; + for(size_t i = 1; i <= str.size(); ++i) + { + answer += OneSignDemicalView(str.substr(str.size() - i , 1)) * pow(3, i - 1) ; + } + return (answer > 0) ? answer : 0; } TEST(TernaryNumbers, EmptyString) @@ -62,6 +63,7 @@ TEST(TernaryNumbers, TwoSignString01) ASSERT_EQ(1, DemicalView("01")); } + TEST(TernaryNumbers, TwoSignString11) { ASSERT_EQ(4, DemicalView("11")); From 8a30a05e2932c10cc3322c5327ee4ae95cc812e9 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 10 Oct 2018 15:03:11 +0300 Subject: [PATCH 21/98] Green Signed-off-by: Alexander Potapov --- tdd_intro/homework/02_ternary_numbers/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/02_ternary_numbers/test.cpp b/tdd_intro/homework/02_ternary_numbers/test.cpp index d530018c..8ab93634 100644 --- a/tdd_intro/homework/02_ternary_numbers/test.cpp +++ b/tdd_intro/homework/02_ternary_numbers/test.cpp @@ -68,3 +68,9 @@ TEST(TernaryNumbers, TwoSignString11) { ASSERT_EQ(4, DemicalView("11")); } + + +TEST(TernaryNumbers, SpecifcationTest) +{ + ASSERT_EQ(302, DemicalView("102012")); +} From 9ebf07fba3b1be8e53fb9ae7bff0ee84cbef025f Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 09:53:53 +0300 Subject: [PATCH 22/98] RED Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index cb4b28cb..6b45b100 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -194,3 +194,28 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", " | _| _||_||_ |_ ||_||_|", " ||_ _| | _||_| ||_| _|" }; + +// parse 1 number 0-9 +// right numbers +// wrong numbers + +// parse line +// more than 27 symbols in string +// less than 27 symbols in string +// 27 symbols in string + +// parse several structs + + + +// assumptions: +// one function, take vector of Display and return vector of int +// second function, take 1 Display and return one int. +// third function, take 1 Digit and return one int. +// No infirmation about wrong entry* + + +TEST(Bank, NumberZero) +{ + ASSERT_EQ(0, ZipNumberParser(s_digit0)); +} From 19f4597d8213da8396d3f2d58a1f9a6da220260b Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 09:55:37 +0300 Subject: [PATCH 23/98] GREEN Signed-off-by: Alexander Potapov --- 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 6b45b100..a934041a 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -215,6 +215,13 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", // No infirmation about wrong entry* +int ZipNumberParser(const Digit& digit) +{ + return 0; +} + + + TEST(Bank, NumberZero) { ASSERT_EQ(0, ZipNumberParser(s_digit0)); From ac52868b6d05d2ff8d71630c13f9bdf56b3d6fba Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 09:57:16 +0300 Subject: [PATCH 24/98] RED Signed-off-by: Alexander Potapov --- 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 a934041a..0a670e9f 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -226,3 +226,8 @@ TEST(Bank, NumberZero) { ASSERT_EQ(0, ZipNumberParser(s_digit0)); } + +TEST(Bank, NumberOne) +{ + ASSERT_EQ(1, ZipNumberParser(s_digit1)); +} From e2af60ab5befd947511f5abe431b68ec694f9b85 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:02:07 +0300 Subject: [PATCH 25/98] GREEN Signed-off-by: Alexander Potapov --- 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 0a670e9f..abc2320d 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -212,12 +212,19 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", // one function, take vector of Display and return vector of int // second function, take 1 Display and return one int. // third function, take 1 Digit and return one int. -// No infirmation about wrong entry* +// No information about wrong entry* int ZipNumberParser(const Digit& digit) { - return 0; + if(digit.lines[0] == s_digit0.lines[0] && digit.lines[1] == s_digit0.lines[1] && digit.lines[2] == s_digit0.lines[2]) + { + return 0; + } + if(digit.lines[0] == s_digit1.lines[0] && digit.lines[1] == s_digit1.lines[1] && digit.lines[2] == s_digit1.lines[2]) + { + return 1; + } } From ff3a01feda8d796ff0cbbea373ac65a46bbb34be Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:05:11 +0300 Subject: [PATCH 26/98] REFACTORING Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index abc2320d..0c251fc9 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -214,14 +214,18 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", // third function, take 1 Digit and return one int. // No information about wrong entry* +bool CompareDigits(const Digit& left, const Digit& right) +{ + return left.lines[0] == right.lines[0] && left.lines[1] == right.lines[1] && left.lines[2] == right.lines[2]; +} int ZipNumberParser(const Digit& digit) { - if(digit.lines[0] == s_digit0.lines[0] && digit.lines[1] == s_digit0.lines[1] && digit.lines[2] == s_digit0.lines[2]) + if( CompareDigits(digit, s_digit0) ) { return 0; } - if(digit.lines[0] == s_digit1.lines[0] && digit.lines[1] == s_digit1.lines[1] && digit.lines[2] == s_digit1.lines[2]) + if( CompareDigits(digit, s_digit1) ) { return 1; } From 42618c4e3fd661a8146750c99f223631478e469a Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:14:38 +0300 Subject: [PATCH 27/98] RED Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 0c251fc9..cf1edc5e 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -86,6 +86,7 @@ Example input and output */ #include #include +#include const unsigned short g_linesInDigit = 3; struct Digit @@ -242,3 +243,8 @@ TEST(Bank, NumberOne) { ASSERT_EQ(1, ZipNumberParser(s_digit1)); } + +TEST(Bank, NumberThree) +{ + ASSERT_EQ(3, ZipNumberParser(s_digit3)); +} From 2bba6aa8cdca6c1a442e7a574765a8fa0545b206 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:15:17 +0300 Subject: [PATCH 28/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index cf1edc5e..4c57cbdf 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -230,6 +230,10 @@ int ZipNumberParser(const Digit& digit) { return 1; } + if( CompareDigits(digit, s_digit3) ) + { + return 3; + } } From a2bfbbc2daa09c5c944bc992ed8c3c4da86a7990 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:29:27 +0300 Subject: [PATCH 29/98] REFACTORED Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 4c57cbdf..078ea226 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -87,6 +87,7 @@ Example input and output #include #include #include +#include const unsigned short g_linesInDigit = 3; struct Digit @@ -222,18 +223,27 @@ bool CompareDigits(const Digit& left, const Digit& right) int ZipNumberParser(const Digit& digit) { - if( CompareDigits(digit, s_digit0) ) + std::vector allNumbers; + allNumbers.reserve(10); + allNumbers.push_back(s_digit0); + allNumbers.push_back(s_digit1); + allNumbers.push_back(s_digit2); + allNumbers.push_back(s_digit3); + allNumbers.push_back(s_digit4); + allNumbers.push_back(s_digit5); + allNumbers.push_back(s_digit6); + allNumbers.push_back(s_digit7); + allNumbers.push_back(s_digit8); + allNumbers.push_back(s_digit9); + + for (int i = 0; i < allNumbers.size(); ++i) { - return 0; - } - if( CompareDigits(digit, s_digit1) ) - { - return 1; - } - if( CompareDigits(digit, s_digit3) ) - { - return 3; + if ( CompareDigits(digit, allNumbers[i]) ) + { + return i; + } } + return -1; } From 7682935c4631e0d50d67da2730ac50533d99176f Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:32:42 +0300 Subject: [PATCH 30/98] GREEN wrongNumber Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 078ea226..0a1df499 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -141,6 +141,10 @@ const Digit s_digit9 = { " _ ", "|_|", " _|" }; +const Digit s_noDigit = { " _ ", + "|_|", + " _ " + }; const Display s_displayAll0 = { " _ _ _ _ _ _ _ _ _ ", "| || || || || || || || || |", @@ -262,3 +266,8 @@ TEST(Bank, NumberThree) { ASSERT_EQ(3, ZipNumberParser(s_digit3)); } + +TEST(Bank, WrongNumber) +{ + ASSERT_EQ(-1, ZipNumberParser(s_noDigit)); +} From 02f2d9cba203f854a0d128f9c77d5b39149883c5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:34:37 +0300 Subject: [PATCH 31/98] GREEN EmptyDigit Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 0a1df499..d02ba0bd 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -271,3 +271,9 @@ TEST(Bank, WrongNumber) { ASSERT_EQ(-1, ZipNumberParser(s_noDigit)); } + +TEST(Bank, EmptyDigit) +{ + Digit emptyDigit{"", "", ""}; + ASSERT_EQ(-1, ZipNumberParser(emptyDigit)); +} From 9c8e7874140ed24227a40c320960695ac7fead30 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:37:37 +0300 Subject: [PATCH 32/98] RED Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index d02ba0bd..c2d903b8 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -216,7 +216,7 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", // assumptions: // one function, take vector of Display and return vector of int -// second function, take 1 Display and return one int. +// second function, take 1 Display and return one string with 9 digit. // third function, take 1 Digit and return one int. // No information about wrong entry* @@ -277,3 +277,8 @@ TEST(Bank, EmptyDigit) Digit emptyDigit{"", "", ""}; ASSERT_EQ(-1, ZipNumberParser(emptyDigit)); } + +TEST(Bank, LineOfZero) +{ + ASSERT_EQ("000000000", ZipLineParser(s_displayAll0)); +} From d2109260688cdb764af8f36b6a53730b56b5c9f7 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:39:02 +0300 Subject: [PATCH 33/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index c2d903b8..e4528000 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -250,6 +250,10 @@ int ZipNumberParser(const Digit& digit) return -1; } +std::string ZipLineParser(const Display& display) +{ + return "000000000"; +} TEST(Bank, NumberZero) From 6b116930f50d3830cfea098283b2c42805f75745 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:40:48 +0300 Subject: [PATCH 34/98] RED Signed-off-by: Alexander Potapov --- 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 e4528000..15739637 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -286,3 +286,8 @@ TEST(Bank, LineOfZero) { ASSERT_EQ("000000000", ZipLineParser(s_displayAll0)); } + +TEST(Bank, LineOfOne) +{ + ASSERT_EQ("111111111", ZipLineParser(s_displayAll1)); +} From 77c0cc5f2752d1003bf1cfe659a916db885dc0fd Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:48:44 +0300 Subject: [PATCH 35/98] RED Change test. So large step. Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 15739637..f44f77eb 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -278,7 +278,7 @@ TEST(Bank, WrongNumber) TEST(Bank, EmptyDigit) { - Digit emptyDigit{"", "", ""}; + const Digit emptyDigit{"", "", ""}; ASSERT_EQ(-1, ZipNumberParser(emptyDigit)); } @@ -287,7 +287,8 @@ TEST(Bank, LineOfZero) ASSERT_EQ("000000000", ZipLineParser(s_displayAll0)); } -TEST(Bank, LineOfOne) +TEST(Bank, emptyDisplay) { - ASSERT_EQ("111111111", ZipLineParser(s_displayAll1)); + Display emptyDisplay{"", "", ""}; + ASSERT_EQ("-1", ZipLineParser(emptyDisplay)); } From 1dba3c5ba3e05b964fe53d003ffcf0f885e7d8d5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:50:40 +0300 Subject: [PATCH 36/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index f44f77eb..51ffc586 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -252,6 +252,10 @@ int ZipNumberParser(const Digit& digit) std::string ZipLineParser(const Display& display) { + if (display.lines[0].size() != 27 || display.lines[1].size() != 27 || display.lines[2].size() != 27) + { + return "-1"; + } return "000000000"; } From cd01843d9e711295b3365a77fa27ea226628714f Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:52:50 +0300 Subject: [PATCH 37/98] GREEN largeDisplay Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 51ffc586..6b3ae258 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -296,3 +296,11 @@ TEST(Bank, emptyDisplay) Display emptyDisplay{"", "", ""}; ASSERT_EQ("-1", ZipLineParser(emptyDisplay)); } + +TEST(Bank, largeDisplay) +{ + Display largeDisplay{"______________________________", + "___________________________", + "___________________________"}; + ASSERT_EQ("-1", ZipLineParser(largeDisplay)); +} From 0ff6185171051a87beb763bc1497ba51ce324bc5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 10:54:58 +0300 Subject: [PATCH 38/98] RED Signed-off-by: Alexander Potapov --- 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 6b3ae258..79e889cd 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -204,6 +204,7 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", // parse 1 number 0-9 // right numbers // wrong numbers +// empty digit // parse line // more than 27 symbols in string @@ -304,3 +305,7 @@ TEST(Bank, largeDisplay) "___________________________"}; ASSERT_EQ("-1", ZipLineParser(largeDisplay)); } +TEST(Bank, LineOf1) +{ + ASSERT_EQ("111111111", ZipLineParser(s_displayAll1)); +} From 379997a37a0a8666adf13113c40a7bc4026d2dc6 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:05:46 +0300 Subject: [PATCH 39/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 79e889cd..74f1e907 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -257,6 +257,10 @@ std::string ZipLineParser(const Display& display) { return "-1"; } + if (display.lines[0] == s_displayAll1.lines[0] && display.lines[1] == s_displayAll1.lines[1] && display.lines[2] == s_displayAll1.lines[2] ) + { + return "111111111"; + } return "000000000"; } From b4bcbf1e0561ebb644c155174a6179a033212faa Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:06:29 +0300 Subject: [PATCH 40/98] RED Signed-off-by: Alexander Potapov --- 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 74f1e907..1515cb4c 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -313,3 +313,8 @@ TEST(Bank, LineOf1) { ASSERT_EQ("111111111", ZipLineParser(s_displayAll1)); } + +TEST(Bank, LineOf2) +{ + ASSERT_EQ("222222222", ZipLineParser(s_displayAll2)); +} From 8988a66b64ade595c13ee6f74c6ad54924e43be7 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:07:14 +0300 Subject: [PATCH 41/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 1515cb4c..af1c246d 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -261,6 +261,10 @@ std::string ZipLineParser(const Display& display) { return "111111111"; } + if (display.lines[0] == s_displayAll2.lines[0] && display.lines[1] == s_displayAll2.lines[1] && display.lines[2] == s_displayAll2.lines[2] ) + { + return "222222222"; + } return "000000000"; } From 210e8a5fccab90396ea56d70d101a932727b6ae5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:24:21 +0300 Subject: [PATCH 42/98] REFACTORING Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index af1c246d..b00085ab 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -257,15 +257,23 @@ std::string ZipLineParser(const Display& display) { return "-1"; } - if (display.lines[0] == s_displayAll1.lines[0] && display.lines[1] == s_displayAll1.lines[1] && display.lines[2] == s_displayAll1.lines[2] ) + std::string answer=""; + for(int i = 0; i < 27; i+=3) { - return "111111111"; - } - if (display.lines[0] == s_displayAll2.lines[0] && display.lines[1] == s_displayAll2.lines[1] && display.lines[2] == s_displayAll2.lines[2] ) - { - return "222222222"; + Digit tempDigit{ std::string(display.lines[0].begin(),display.lines[0].begin()+3), + std::string(display.lines[1].begin(),display.lines[1].begin()+3), + std::string(display.lines[2].begin(),display.lines[2].begin()+3)}; + int temp = ZipNumberParser(tempDigit); + if(temp == -1) + { + return "-1"; + } + else + { + answer = answer + std::to_string(temp); + } } - return "000000000"; + return answer; } From f937abc77d3015ede76fb512520ee653de019f20 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:27:41 +0300 Subject: [PATCH 43/98] RED Signed-off-by: Alexander Potapov --- 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 b00085ab..9ed254ab 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -330,3 +330,10 @@ TEST(Bank, LineOf2) { ASSERT_EQ("222222222", ZipLineParser(s_displayAll2)); } + +TEST(Bank, Line123456789) +{ + ASSERT_EQ("123456789", ZipLineParser(s_display123456789)); +} + + From 0de9281f761eeb5bc4c867f675d9ebbf5ac4b1d4 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:28:31 +0300 Subject: [PATCH 44/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 9ed254ab..24c466f0 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -260,9 +260,9 @@ std::string ZipLineParser(const Display& display) std::string answer=""; for(int i = 0; i < 27; i+=3) { - Digit tempDigit{ std::string(display.lines[0].begin(),display.lines[0].begin()+3), - std::string(display.lines[1].begin(),display.lines[1].begin()+3), - std::string(display.lines[2].begin(),display.lines[2].begin()+3)}; + Digit tempDigit{ std::string(display.lines[0].begin() + i,display.lines[0].begin()+3 + i), + std::string(display.lines[1].begin() + i,display.lines[1].begin()+3 + i), + std::string(display.lines[2].begin() + i,display.lines[2].begin()+3 + i)}; int temp = ZipNumberParser(tempDigit); if(temp == -1) { From 3e9433da608b9919f52c8d183804884981621b9d Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:32:43 +0300 Subject: [PATCH 45/98] GREEN wrongDisplay Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 24c466f0..81e25639 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -200,6 +200,10 @@ const Display s_display123456789 = { " _ _ _ _ _ _ _ ", " | _| _||_||_ |_ ||_||_|", " ||_ _| | _||_| ||_| _|" }; +const Display s_wrongDisplay = { " _ _ _ _ _ _ _ _ _ ", + "|_||_||_||_||_||_||_||_||_|", + " _| _| _| _ _| _| _| _| _|" +}; // parse 1 number 0-9 // right numbers @@ -336,4 +340,10 @@ TEST(Bank, Line123456789) ASSERT_EQ("123456789", ZipLineParser(s_display123456789)); } +TEST(Bank, WrongDispley) +{ + ASSERT_EQ("-1", ZipLineParser(s_wrongDisplay)); +} + + From 523f777cda3af6cfd609ac930e3e62cd33d29e7f Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:35:48 +0300 Subject: [PATCH 46/98] RED Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 81e25639..bc71b9ca 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -220,7 +220,7 @@ const Display s_wrongDisplay = { " _ _ _ _ _ _ _ _ _ ", // assumptions: -// one function, take vector of Display and return vector of int +// one function, take vector of Display and return vector of string // second function, take 1 Display and return one string with 9 digit. // third function, take 1 Digit and return one int. // No information about wrong entry* @@ -345,5 +345,16 @@ TEST(Bank, WrongDispley) ASSERT_EQ("-1", ZipLineParser(s_wrongDisplay)); } +TEST(Bank, TwoLines) +{ + std::vector linesOfDisplay; + linesOfDisplay.push_back(s_displayAll0); + linesOfDisplay.push_back(s_displayAll1); + std::vector answer; + answer.push_back("000000000"); + answer.push_back("111111111"); + ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); +} + From b3d10004e0fc1ff95f49b55fa4b22667da42625a Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:38:01 +0300 Subject: [PATCH 47/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index bc71b9ca..22095330 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -280,6 +280,14 @@ std::string ZipLineParser(const Display& display) return answer; } +std::vector ZipVectorParser(std::vector displays) +{ + std::vector answer; + answer.push_back("000000000"); + answer.push_back("111111111"); + return answer; +} + TEST(Bank, NumberZero) { From c7b98329a2d80d14485cbfaf4047844b4e8922a5 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:39:43 +0300 Subject: [PATCH 48/98] RED Signed-off-by: Alexander Potapov --- 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 22095330..ef1d3667 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -364,5 +364,18 @@ TEST(Bank, TwoLines) ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); } +TEST(Bank, ThreeLines) +{ + std::vector linesOfDisplay; + linesOfDisplay.push_back(s_displayAll0); + linesOfDisplay.push_back(s_displayAll1); + linesOfDisplay.push_back(s_display123456789); + std::vector answer; + answer.push_back("000000000"); + answer.push_back("111111111"); + answer.push_back("123456789"); + ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); +} + From ed19e6358bfd300de2f256dcf8090ea99fc4e1ce Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:46:05 +0300 Subject: [PATCH 49/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index ef1d3667..7faab400 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -283,8 +283,19 @@ std::string ZipLineParser(const Display& display) std::vector ZipVectorParser(std::vector displays) { std::vector answer; - answer.push_back("000000000"); - answer.push_back("111111111"); + if(displays.size() == 2) + { + answer.push_back("000000000"); + answer.push_back("111111111"); + } + else + { + answer.push_back("000000000"); + answer.push_back("111111111"); + answer.push_back("123456789"); + } + + return answer; } From b484a4b60f8f38a027f6f96bc00ce904cf9a2e20 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:47:42 +0300 Subject: [PATCH 50/98] REFACTORING Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 7faab400..2ec85bc8 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -283,19 +283,10 @@ std::string ZipLineParser(const Display& display) std::vector ZipVectorParser(std::vector displays) { std::vector answer; - if(displays.size() == 2) + for(auto disp:displays) { - answer.push_back("000000000"); - answer.push_back("111111111"); + answer.push_back(ZipLineParser(disp)); } - else - { - answer.push_back("000000000"); - answer.push_back("111111111"); - answer.push_back("123456789"); - } - - return answer; } From f10a8dd7c47a0faa5d119d1298bc6ea010189d78 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 17 Oct 2018 11:49:23 +0300 Subject: [PATCH 51/98] GREEN Signed-off-by: Alexander Potapov --- tdd_intro/homework/03_bank_ocr/test.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/03_bank_ocr/test.cpp b/tdd_intro/homework/03_bank_ocr/test.cpp index 2ec85bc8..06d3f3cc 100644 --- a/tdd_intro/homework/03_bank_ocr/test.cpp +++ b/tdd_intro/homework/03_bank_ocr/test.cpp @@ -379,5 +379,16 @@ TEST(Bank, ThreeLines) ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); } - +TEST(Bank, ThreeLinesWithWrongDisplay) +{ + std::vector linesOfDisplay; + linesOfDisplay.push_back(s_displayAll0); + linesOfDisplay.push_back(s_wrongDisplay); + linesOfDisplay.push_back(s_display123456789); + std::vector answer; + answer.push_back("000000000"); + answer.push_back("-1"); + answer.push_back("123456789"); + ASSERT_EQ(answer, ZipVectorParser(linesOfDisplay)); +} From b833c67e22a00bfb6316fcfcc579a0bc7759edd7 Mon Sep 17 00:00:00 2001 From: Alexander Potapov Date: Wed, 24 Oct 2018 17:18:30 +0300 Subject: [PATCH 52/98] The task. Signed-off-by: Alexander Potapov --- tdd_intro/homework/04_weather_client/test.cpp | 105 ++++++++++++++---- 1 file changed, 82 insertions(+), 23 deletions(-) diff --git a/tdd_intro/homework/04_weather_client/test.cpp b/tdd_intro/homework/04_weather_client/test.cpp index 6b04a27c..0a87c44c 100644 --- a/tdd_intro/homework/04_weather_client/test.cpp +++ b/tdd_intro/homework/04_weather_client/test.cpp @@ -1,40 +1,99 @@ /* Fake Weather Client -You are going to develop a program that gets the statistics about weather in the cities using information from a certain server. Then the program calculates average values for collected statistics and generates a report. - -To communicate with the weather server you've already created the class WeatherServerClient, which gets the raw string from the server for the requested day or period of time. This class implements an interface IWeatherServerClient and actually communicates with the real server. You have to implement the parsing function for the raw responses via TDD, therefore, you need to create another IWeatherServerClient class with fake implementation, because interacting with real network is inacceptable within the unit tests. - -The server answers with text of this format: - 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;46;179:4.5 - Where each line represents the time of the day and contains the next information: ";