isleapyear by Java
public class LeapYear {
public static final int LEAP = 1;
public static final int COMMON = 0;
public static int isLeapYear(int d) {
if(d%400 == 0) return 1;
if(d%100 == 0) return 0;
if(d%4 == 0) return 1;
return 0;
}
}
import org.junit.*;
import static org.junit.Assert.*;
public class LeapYearTest {
@Test
public void test_1996_is_leap_year() {
int actual = LeapYear.isLeapYear(1996);
assertEquals(LeapYear.LEAP, actual);
}
@Test
public void test_2001_is_common_year() {
int actual = LeapYear.isLeapYear(2001);
assertEquals(LeapYear.COMMON, actual);
}
@Test
public void test_1900_is_common_year() {
int actual = LeapYear.isLeapYear(1900);
assertEquals(LeapYear.COMMON, actual);
}
@Test
public void test_2000_is_leap_year() {
int actual = LeapYear.isLeapYear(2000);
assertEquals(LeapYear.LEAP, actual);
}
}