-
-
Save SDiamante13/5d9d84b3098ea0dc6509406e1e9bc18b to your computer and use it in GitHub Desktop.
Remove parameter year from isLeapYear and instead use the instance variable that the private methods make use of.
This file contains hidden or 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
| package tech.pathtoprogramming.tdd; | |
| import org.junit.jupiter.params.ParameterizedTest; | |
| import org.junit.jupiter.params.provider.CsvSource; | |
| import static org.assertj.core.api.Assertions.assertThat; | |
| class AYearShould { | |
| @ParameterizedTest | |
| @CsvSource({ | |
| "2001,false", | |
| "1996,true", | |
| "1992,true", | |
| "1900,false", | |
| "2000,true" | |
| }) | |
| void determineWhetherAGivenYearIsALeapYearOrNot(int givenYear, boolean isExpectedLeapYear) { | |
| boolean isLeapYear = new Year(givenYear).isLeapYear(); | |
| assertThat(isLeapYear).isEqualTo(isExpectedLeapYear); | |
| } | |
| } | |
| class Year { | |
| private int year; | |
| public Year(int year) { | |
| this.year = year; | |
| } | |
| public boolean isLeapYear() { | |
| if (isDivisibleBy(4) && (isNotDivisibleBy(100) || isDivisibleBy(400))) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| private boolean isDivisibleBy(int number) { | |
| return this.year % number == 0; | |
| } | |
| private boolean isNotDivisibleBy(int number) { | |
| return this.year % number != 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment