Skip to content

Instantly share code, notes, and snippets.

@SDiamante13
Created July 27, 2022 21:01
Show Gist options
  • Select an option

  • Save SDiamante13/29069fbf55050ee931199a5e3cad3300 to your computer and use it in GitHub Desktop.

Select an option

Save SDiamante13/29069fbf55050ee931199a5e3cad3300 to your computer and use it in GitHub Desktop.
Replace hardcoded values with proper algorithm. A leap year is divisible by 4.
package tech.pathtoprogramming.tdd;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class AYearShould {
@Test
void determineThatTheYearIsNotALeapYearForCommonCase() {
boolean isLeapYear = Year.isLeapYear(2001);
assertThat(isLeapYear).isFalse();
}
@Test
void determineThatTheYearIsAStandardLeapYear() {
boolean isLeapYear = Year.isLeapYear(1996);
assertThat(isLeapYear).isTrue();
}
@Test
void anotherLeapYear() {
boolean isLeapYear = Year.isLeapYear(1992);
assertThat(isLeapYear).isTrue();
}
}
class Year {
public static boolean isLeapYear(int year) {
if (year % 4 == 0) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment