Leap Year kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a function that returns true or false depending on whether its input integer is a leap year or not. | |
A leap year is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400. | |
2001 is a typical common year | |
1996 is a typical leap year | |
1900 is an atypical common year | |
2000 is an atypical leap year |
package leapyear;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class TestLeapYear {
private LeapYear leapYear;
@Before
public void setUp() throws Exception {
leapYear = new LeapYear();
}
@Test
public void when1996_thenIsLeap() {
boolean isLeap = isLeap(1996);
assertTrue(isLeap);
}
@Test
public void when2001_thenIsNotLeap() {
boolean isLeap = this.isLeap(2001);
assertFalse(isLeap);
}
@Test
public void when1900_thenIsNotLeap() {
assertFalse(this.isLeap(1900));
}
@Test
public void when2000_thenIsLeap() {
assertTrue(isLeap(2000));
}
private boolean isLeap(int year) {
return leapYear.isLeap(year);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
package leapyear;
public class LeapYear {
}