Skip to content

Commit 1bb23bf

Browse files
authored
fix: count leap day in birthday (#730)
1 parent dbb4d79 commit 1bb23bf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
21
import static org.junit.jupiter.api.Assertions.assertEquals;
32

43
import java.time.LocalDate;
5-
import java.time.Year;
64
import org.junit.jupiter.api.Test;
75

86
class KataTest {
@@ -11,7 +9,9 @@ void sample() {
119
var birthday = LocalDate.now();
1210
assertEquals("You are 2 days old", Kata.ageInDays(birthday.minusDays(2).getYear(), birthday.minusDays(2).getMonthValue(), birthday.minusDays(2).getDayOfMonth()));
1311

14-
String expected = String.format("You are %d days old", Year.of(birthday.getYear()).length());
15-
assertEquals(expected, Kata.ageInDays(birthday.minusYears(1).getYear(), birthday.minusYears(1).getMonthValue(), birthday.minusYears(1).getDayOfMonth()));
12+
var pastYear = birthday.minusYears(1);
13+
boolean leapDay = birthday.getMonthValue() > 2 && birthday.isLeapYear() || birthday.getMonthValue() < 3 && pastYear.isLeapYear();
14+
String expected = String.format("You are %d days old", leapDay ? 366 : 365);
15+
assertEquals(expected, Kata.ageInDays(pastYear.getYear(), pastYear.getMonthValue(), pastYear.getDayOfMonth()));
1616
}
17-
}
17+
}

0 commit comments

Comments
 (0)