From d09938e0bd7f552baa1e393ffaa1e2a7ac7e710d Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:08:52 +0300 Subject: [PATCH 01/14] read test for check_LeapYear --- tdd_intro/homework/02_leap_year/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 4f186c8..06b1be4 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -13,3 +13,13 @@ If your language provides a method in the standard library that does this look-u */ #include + +bool IsLeapYear(int) +{ + return false; +} + +TEST(IsLeapYear, check_LeapYear) +{ + EXPECT_TRUE(IsLeapYear(2016)); +} From ca0dc69fe07c5d172d579f6ca1e8a1e1e8a18629 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:11:14 +0300 Subject: [PATCH 02/14] green test for check_LeapYear --- tdd_intro/homework/02_leap_year/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 06b1be4..c206982 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -16,7 +16,7 @@ If your language provides a method in the standard library that does this look-u bool IsLeapYear(int) { - return false; + return true; } TEST(IsLeapYear, check_LeapYear) From e9739d3febb71784410dbf2a5ce81dc6b31ecf00 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:15:18 +0300 Subject: [PATCH 03/14] read test for check_NoLeapYear --- tdd_intro/homework/02_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index c206982..be7a963 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -23,3 +23,8 @@ TEST(IsLeapYear, check_LeapYear) { EXPECT_TRUE(IsLeapYear(2016)); } + +TEST(IsLeapYear, check_NotLeapYear) +{ + EXPECT_FALSE(IsLeapYear(2017)); +} From ec362ce02f0551594285ccc18925f03724c7a92d Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:22:00 +0300 Subject: [PATCH 04/14] green test for check_NotLeapYear --- tdd_intro/homework/02_leap_year/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index be7a963..c895fae 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -14,9 +14,9 @@ If your language provides a method in the standard library that does this look-u #include -bool IsLeapYear(int) +bool IsLeapYear(int year) { - return true; + return (year % 4) == 0; } TEST(IsLeapYear, check_LeapYear) From a423234dde88271d05095a90db190d4f69a19387 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:29:59 +0300 Subject: [PATCH 05/14] read test for check_NotLeapYear_ForDivisibleBy100 --- tdd_intro/homework/02_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index c895fae..dd1b91e 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -28,3 +28,8 @@ TEST(IsLeapYear, check_NotLeapYear) { EXPECT_FALSE(IsLeapYear(2017)); } + +TEST(IsLeapYear, check_NotLeapYear_ForDivisibleBy100) +{ + EXPECT_FALSE(IsLeapYear(1900)); +} From 51941da0687a2c4a3556d8dbd806cfb7be74993d Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:33:06 +0300 Subject: [PATCH 06/14] green test for check_NotLeapYear_ForDivisibleBy100 --- tdd_intro/homework/02_leap_year/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index dd1b91e..09aafa6 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -16,7 +16,7 @@ If your language provides a method in the standard library that does this look-u bool IsLeapYear(int year) { - return (year % 4) == 0; + return (year % 4) == 0 && (year % 100) != 0; } TEST(IsLeapYear, check_LeapYear) From c19ba436b960fc3319889c1e23383988091bf6f5 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:43:16 +0300 Subject: [PATCH 07/14] refactoring after green check_NotLeapYear_ForDivisibleBy100 test --- tdd_intro/homework/02_leap_year/test.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 09aafa6..c851a94 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -14,9 +14,22 @@ If your language provides a method in the standard library that does this look-u #include +bool IsDivisibleBy4(int year) +{ + return (year % 4) == 0; +} + +bool IsDivisibleBy100(int year) +{ + return (year % 100) == 0; +} + bool IsLeapYear(int year) { - return (year % 4) == 0 && (year % 100) != 0; + bool result = true; + result &= IsDivisibleBy4(year); + result &= !IsDivisibleBy100(year); + return result; } TEST(IsLeapYear, check_LeapYear) From 0d85c70d09f99da56aebb8d566afbd493889c3ea Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:47:53 +0300 Subject: [PATCH 08/14] read test for check_LeapYear_ForDivisibleBy400 --- tdd_intro/homework/02_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index c851a94..7438fe5 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -46,3 +46,8 @@ TEST(IsLeapYear, check_NotLeapYear_ForDivisibleBy100) { EXPECT_FALSE(IsLeapYear(1900)); } + +TEST(IsLeapYear, check_NotLeapYear_ForDivisibleBy400) +{ + EXPECT_TRUE(IsLeapYear(2000)); +} From dc8480834ffc22a520762273b4269edd0d4ffc7c Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 06:49:36 +0300 Subject: [PATCH 09/14] rename check_NotLeapYear_ForDivisibleBy400 to LeapYear_ForDivisibleBy400 --- tdd_intro/homework/02_leap_year/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 7438fe5..b5cfb7f 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -47,7 +47,7 @@ TEST(IsLeapYear, check_NotLeapYear_ForDivisibleBy100) EXPECT_FALSE(IsLeapYear(1900)); } -TEST(IsLeapYear, check_NotLeapYear_ForDivisibleBy400) +TEST(IsLeapYear, check_LeapYear_ForDivisibleBy400) { EXPECT_TRUE(IsLeapYear(2000)); } From 916dbfe954f8fcb4bb353a584e2d051e24535511 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 07:02:05 +0300 Subject: [PATCH 10/14] green test for check_LeapYear_ForDivisibleBy400 --- tdd_intro/homework/02_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index b5cfb7f..c07374d 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -29,6 +29,10 @@ bool IsLeapYear(int year) bool result = true; result &= IsDivisibleBy4(year); result &= !IsDivisibleBy100(year); + if((year % 400) == 0 ) + { + return true; + } return result; } From 0e6753367daeb52bf3cbe8dd807ebc8ac9b9e637 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 07:07:41 +0300 Subject: [PATCH 11/14] refactoring after green the check_LeapYear_ForDivisibleBy400 test --- tdd_intro/homework/02_leap_year/test.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index c07374d..f5af3f9 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -24,15 +24,17 @@ bool IsDivisibleBy100(int year) return (year % 100) == 0; } +bool IsDivisibleBy400(int year) +{ + return (year % 400) == 0; +} + bool IsLeapYear(int year) { bool result = true; result &= IsDivisibleBy4(year); - result &= !IsDivisibleBy100(year); - if((year % 400) == 0 ) - { - return true; - } + result &= IsDivisibleBy400(year) || !IsDivisibleBy100(year); + return result; } From a216dcbc44a9ca85b72d7bfd6c9c2c5ba48aff09 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 07:15:39 +0300 Subject: [PATCH 12/14] add check_LeapYear_ForZerro test and it green :) --- tdd_intro/homework/02_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index f5af3f9..5d626d0 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -57,3 +57,8 @@ TEST(IsLeapYear, check_LeapYear_ForDivisibleBy400) { EXPECT_TRUE(IsLeapYear(2000)); } + +TEST(IsLeapYear, check_LeapYear_ForZerro) +{ + EXPECT_TRUE(IsLeapYear(0)); +} From fcaac2ef30db9a0421199c6f0a830c35cf3e42e2 Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 07:21:04 +0300 Subject: [PATCH 13/14] read test for check_LeapYear_ForNegativeNumber --- tdd_intro/homework/02_leap_year/test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 5d626d0..1e50439 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -62,3 +62,8 @@ TEST(IsLeapYear, check_LeapYear_ForZerro) { EXPECT_TRUE(IsLeapYear(0)); } + +TEST(IsLeapYear, check_LeapYear_ForNegativeNumber) +{ + EXPECT_THROW(IsLeapYear(-4), std::runtime_error); +} From 4c1d4c0edfa09900b6e9b642df144cbed4f0f8ba Mon Sep 17 00:00:00 2001 From: Inna Danchuk Date: Tue, 28 May 2019 07:22:03 +0300 Subject: [PATCH 14/14] green test for check_LeapYear_ForNegativeNumber --- tdd_intro/homework/02_leap_year/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tdd_intro/homework/02_leap_year/test.cpp b/tdd_intro/homework/02_leap_year/test.cpp index 1e50439..0023911 100644 --- a/tdd_intro/homework/02_leap_year/test.cpp +++ b/tdd_intro/homework/02_leap_year/test.cpp @@ -31,6 +31,10 @@ bool IsDivisibleBy400(int year) bool IsLeapYear(int year) { + if(year < 0) + { + throw std::runtime_error("incorrect input data"); + } bool result = true; result &= IsDivisibleBy4(year); result &= IsDivisibleBy400(year) || !IsDivisibleBy100(year);