From 8de7e8c872f4eadc0f8c0d550528f8f6ba38e408 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:18:25 +0200 Subject: [PATCH 01/13] 01 - Leap year - Fake it! --- 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 4f186c8..ae72860 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -13,3 +13,13 @@ If your language provides a method in the standard library that does this look-u */ #include + +bool is_leap_year(int year) +{ + return false; +} + +TEST(leap_year, test_1997) +{ + EXPECT_EQ(false, is_leap_year(1997)); +} From fcf17c0bb6ea5cef02c6b2e4bcfe0a4cbce7d113 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:20:17 +0200 Subject: [PATCH 02/13] 01 - Leap year - Failed 1996 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 ae72860..5837551 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -23,3 +23,8 @@ TEST(leap_year, test_1997) { EXPECT_EQ(false, is_leap_year(1997)); } + +TEST(leap_year, test_1996) +{ + EXPECT_EQ(true, is_leap_year(1996)); +} From fbfe3fe6562ecbfbec2a24cb74e1b385d321c2a2 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:21:20 +0200 Subject: [PATCH 03/13] 01 - Leap year - 1996 test megafix --- 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 5837551..92c24bb 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 is_leap_year(int year) { + if (year == 1996) + { + return true; + } return false; } From af1ef204c1c2465a28de279ee9245bf4cf80d152 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:23:08 +0200 Subject: [PATCH 04/13] 01 - Leap year - Added 1990 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 92c24bb..be22f9e 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -32,3 +32,8 @@ TEST(leap_year, test_1996) { EXPECT_EQ(true, is_leap_year(1996)); } + +TEST(leap_year, test_1990) +{ + EXPECT_EQ(false, is_leap_year(1990)); +} From 355005dd11e207792fbefd249b1951ec5b681733 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:25:53 +0200 Subject: [PATCH 05/13] 01 - Leap year - Added failing 2000 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 be22f9e..8bd7ea3 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -37,3 +37,8 @@ TEST(leap_year, test_1990) { EXPECT_EQ(false, is_leap_year(1990)); } + +TEST(leap_year, test_2000) +{ + EXPECT_EQ(true, is_leap_year(2000)); +} From f6b0c245819cce2c28e9f30df44791160a9a9bd1 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:27:55 +0200 Subject: [PATCH 06/13] 01 - Leap year - Fixed 2000 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 8bd7ea3..f73e73c 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 is_leap_year(int year) { - if (year == 1996) + if (year == 1996 || year == 2000) { return true; } From aa304e04db6271c17daf16b440a7837e10f95981 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:29:19 +0200 Subject: [PATCH 07/13] 01 - Leap year - Added one more test --- tdd_intro/homework/01_leap_year/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index f73e73c..777b2fc 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -14,7 +14,7 @@ If your language provides a method in the standard library that does this look-u #include -bool is_leap_year(int year) +bool is_leap_year(uint32_t year) { if (year == 1996 || year == 2000) { @@ -42,3 +42,8 @@ TEST(leap_year, test_2000) { EXPECT_EQ(true, is_leap_year(2000)); } + +TEST(leap_year, test_4) +{ + EXPECT_EQ(true, is_leap_year(4)); +} From 46bab5bc3df3c9e470a456ca7b22a31d54cdf1b0 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:31:20 +0200 Subject: [PATCH 08/13] 01 - Leap year - Fixed test for 4 --- 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 777b2fc..9266020 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 is_leap_year(uint32_t year) { - if (year == 1996 || year == 2000) + if (year == 1996 || year == 2000 || year == 4) { return true; } From 81ae4ff5582501ffac06811450358a5fbc193110 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:32:29 +0200 Subject: [PATCH 09/13] 01 - Leap year - Refactoring and added test for 100 --- tdd_intro/homework/01_leap_year/test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 9266020..8937c75 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 is_leap_year(uint32_t year) { - if (year == 1996 || year == 2000 || year == 4) + if (year % 4 == 0) { return true; } @@ -47,3 +47,8 @@ TEST(leap_year, test_4) { EXPECT_EQ(true, is_leap_year(4)); } + +TEST(leap_year, test_100) +{ + EXPECT_EQ(false, is_leap_year(100)); +} From 012ec8822c16e0164381063740a409a86c582ed0 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:38:06 +0200 Subject: [PATCH 10/13] 01 - Leap year - Fixed test for 100 but broke for e 2000 --- 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 8937c75..261bcc0 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 is_leap_year(uint32_t year) { - if (year % 4 == 0) + if (year % 4 == 0 && year % 100 != 0) { return true; } From 61318142c7048479068d6c62f3cc5326b1218073 Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 13:44:40 +0200 Subject: [PATCH 11/13] 01 - Leap year - Fixed test for 2000 --- tdd_intro/homework/01_leap_year/test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 261bcc0..f3d4a8d 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,6 +16,9 @@ If your language provides a method in the standard library that does this look-u bool is_leap_year(uint32_t year) { + if (year % 400 == 0) + return true; + if (year % 4 == 0 && year % 100 != 0) { return true; From 6d63ef128e3d4e94b85d8f615a20cdf96cd610ad Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 14:10:00 +0200 Subject: [PATCH 12/13] 01 - Leap year - Refactoring --- tdd_intro/homework/01_leap_year/test.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index f3d4a8d..087902f 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -16,12 +16,15 @@ If your language provides a method in the standard library that does this look-u bool is_leap_year(uint32_t year) { - if (year % 400 == 0) - return true; - - if (year % 4 == 0 && year % 100 != 0) + if (year % 4 == 0) { - return true; + if (year % 100 == 0) + { + year /= 100; + return is_leap_year(year); + } + else + return true; } return false; } From 1d1530b31dbd054037b4c64c3e1b0412b71e039b Mon Sep 17 00:00:00 2001 From: Gega Anatoly Date: Wed, 28 Nov 2018 14:13:48 +0200 Subject: [PATCH 13/13] 01 - Leap year - Added acceptance test --- tdd_intro/homework/01_leap_year/test.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tdd_intro/homework/01_leap_year/test.cpp b/tdd_intro/homework/01_leap_year/test.cpp index 087902f..7fe3510 100644 --- a/tdd_intro/homework/01_leap_year/test.cpp +++ b/tdd_intro/homework/01_leap_year/test.cpp @@ -58,3 +58,12 @@ TEST(leap_year, test_100) { EXPECT_EQ(false, is_leap_year(100)); } + +TEST(leap_year, acceptance) +{ + EXPECT_EQ(true, is_leap_year(400)); + EXPECT_EQ(true, is_leap_year(2004)); + EXPECT_EQ(false, is_leap_year(500)); + EXPECT_EQ(false, is_leap_year(2100)); + EXPECT_EQ(false, is_leap_year(1234)); +}