Skip to content
45 changes: 45 additions & 0 deletions tdd_intro/homework/01_leap_year/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,48 @@ If your language provides a method in the standard library that does this look-u
*/

#include <gtest/gtest.h>

bool is_leap_year(uint32_t year)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

финальный рефакторинг не закончен, окончательный вариант функции +- вот таким может быть
return (year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Але ж це не найпростіше рішення на даному етапі

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это был бы последний этап - самый последний рефакторинг

{
if (year % 4 == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какие были подставы для рефакторинга? тестов я не видел

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При додані нового теста докостилювалися нові умови в if. Це хіба не підстава для рефакторинга?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, но в коммите я не видел тестов, предыдущее изменение тоже рефакторинг

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А до якого коміта прив'язані ці коменти? Бо в мене попередній коміт - це фікс теста для 4. І після теста я зарефакторив умову, тому що всі попередні числа ділились на 4.

{
if (year % 100 == 0)
{
year /= 100;
return is_leap_year(year);
}
else
return true;
}
return false;
}

TEST(leap_year, test_1997)
{
EXPECT_EQ(false, is_leap_year(1997));
}

TEST(leap_year, test_1996)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

название теста ни о чем не говорит. Из этого имени нельзя понять, что действительно разработчик хочет проверить

{
EXPECT_EQ(true, is_leap_year(1996));
}

TEST(leap_year, test_1990)
{
EXPECT_EQ(false, is_leap_year(1990));
}

TEST(leap_year, test_2000)
{
EXPECT_EQ(true, is_leap_year(2000));
}

TEST(leap_year, test_4)
{
EXPECT_EQ(true, is_leap_year(4));
}

TEST(leap_year, test_100)
{
EXPECT_EQ(false, is_leap_year(100));
}