diff --git a/exercises/concept/bird-watcher/.meta/src/reference/java/BirdWatcher.java b/exercises/concept/bird-watcher/.meta/src/reference/java/BirdWatcher.java index 027e38a4c..e0884d13e 100644 --- a/exercises/concept/bird-watcher/.meta/src/reference/java/BirdWatcher.java +++ b/exercises/concept/bird-watcher/.meta/src/reference/java/BirdWatcher.java @@ -6,7 +6,7 @@ public BirdWatcher(int[] birdsPerDay) { this.birdsPerDay = birdsPerDay.clone(); } - public int[] getLastWeek() { + public static int[] getLastWeek() { return new int[] { 0, 2, 5, 3, 7, 8, 4 }; } diff --git a/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java b/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java index c19dd38e6..ccdd53ad2 100644 --- a/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java +++ b/exercises/concept/bird-watcher/src/main/java/BirdWatcher.java @@ -6,7 +6,7 @@ public BirdWatcher(int[] birdsPerDay) { this.birdsPerDay = birdsPerDay.clone(); } - public int[] getLastWeek() { + public static int[] getLastWeek() { throw new UnsupportedOperationException("Please implement the BirdWatcher.getLastWeek() method"); } diff --git a/exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java b/exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java index 5b1746082..a811bf54a 100644 --- a/exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java +++ b/exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java @@ -1,55 +1,53 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.BeforeEach; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; public class BirdWatcherTest { - private static final int DAY1 = 0; - private static final int DAY2 = 2; - private static final int DAY3 = 5; - private static final int DAY4 = 3; - private static final int DAY5 = 7; - private static final int DAY6 = 8; - private static final int TODAY = 4; - - private BirdWatcher birdWatcher; - private final int[] lastWeek = {DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, TODAY}; - - @BeforeEach - public void setUp() { - birdWatcher = new BirdWatcher(lastWeek); - } - @Test @Tag("task:1") @DisplayName("The getLastWeek method correctly returns last week's counts") public void itTestGetLastWeek() { - assertThat(birdWatcher.getLastWeek()) - .containsExactly(DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, TODAY); + assertThat(BirdWatcher.getLastWeek()).isEqualTo(new int[] {0, 2, 5, 3, 7, 8, 4}); } @Test @Tag("task:2") @DisplayName("The getToday method correctly returns today's counts") public void itTestGetToday() { - assertThat(birdWatcher.getToday()).isEqualTo(TODAY); + int[] counts = new int[] {8, 8, 9, 5, 4, 7, 10}; + BirdWatcher birdWatcher = new BirdWatcher(counts); + assertThat(birdWatcher.getToday()).isEqualTo(10); } @Test @Tag("task:3") @DisplayName("The incrementTodaysCount method correctly increments today's counts") public void itIncrementTodaysCount() { + int[] counts = new int[] {8, 8, 9, 2, 1, 6, 4}; + BirdWatcher birdWatcher = new BirdWatcher(counts); + birdWatcher.incrementTodaysCount(); + assertThat(birdWatcher.getToday()).isEqualTo(5); + } + + @Test + @Tag("task:3") + @DisplayName("The incrementTodaysCount does not change count for other days") + public void itIncrementDoesNotChangeCountForOtherDays() { + int[] counts = new int[] {5, 1, 0, 4, 2, 3, 0}; + BirdWatcher birdWatcher = new BirdWatcher(counts); birdWatcher.incrementTodaysCount(); - assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1); + assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(15); } @Test @Tag("task:4") - @DisplayName("The hasDayWithoutBirds method returns true when day had no visits") + @DisplayName("The hasDayWithoutBirds method returns true when at least one day had no visits") public void itHasDayWithoutBirds() { + int[] counts = new int[] {5, 5, 4, 0, 7, 6, 7}; + BirdWatcher birdWatcher = new BirdWatcher(counts); assertThat(birdWatcher.hasDayWithoutBirds()).isTrue(); } @@ -57,7 +55,8 @@ public void itHasDayWithoutBirds() { @Tag("task:4") @DisplayName("The hasDayWithoutBirds method returns false when no day had zero visits") public void itShouldNotHaveDaysWithoutBirds() { - birdWatcher = new BirdWatcher(new int[]{1, 2, 5, 3, 7, 8, 4}); + int[] counts = new int[] {4, 5, 9, 10, 9, 4, 3}; + BirdWatcher birdWatcher = new BirdWatcher(counts); assertThat(birdWatcher.hasDayWithoutBirds()).isFalse(); } @@ -65,7 +64,8 @@ public void itShouldNotHaveDaysWithoutBirds() { @Tag("task:4") @DisplayName("The hasDayWithoutBirds method returns true if the last day has zero visits") public void itHasLastDayWithoutBirds() { - birdWatcher = new BirdWatcher(new int[]{1, 2, 5, 3, 7, 8, 0}); + int[] counts = new int[] {1, 2, 5, 3, 7, 8, 0}; + BirdWatcher birdWatcher = new BirdWatcher(counts); assertThat(birdWatcher.hasDayWithoutBirds()).isTrue(); } @@ -73,30 +73,35 @@ public void itHasLastDayWithoutBirds() { @Tag("task:5") @DisplayName("The getCountForFirstDays method returns correct visits' count for given number of days") public void itTestGetCountForFirstDays() { - assertThat(birdWatcher.getCountForFirstDays(4)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4); + int[] counts = new int[] {5, 9, 12, 6, 8, 8, 17}; + BirdWatcher birdWatcher = new BirdWatcher(counts); + assertThat(birdWatcher.getCountForFirstDays(4)).isEqualTo(32); } @Test @Tag("task:5") @DisplayName("The getCountForFirstDays method returns overall count when number of days is higher than array size") public void itTestGetCountForMoreDaysThanTheArraySize() { - assertThat(birdWatcher.getCountForFirstDays(10)) - .isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6 + TODAY); + int[] counts = new int[] {5, 9, 12, 6, 8, 8, 17}; + BirdWatcher birdWatcher = new BirdWatcher(counts); + assertThat(birdWatcher.getCountForFirstDays(10)).isEqualTo(65); } @Test @Tag("task:6") @DisplayName("The getBusyDays method returns the correct count of busy days") public void itTestGetCountForBusyDays() { - // DAY3, DAY5 and DAY6 are all >= 5 birds - assertThat(birdWatcher.getBusyDays()).isEqualTo(3); + int[] counts = new int[] {4, 9, 5, 7, 8, 8, 2}; + BirdWatcher birdWatcher = new BirdWatcher(counts); + assertThat(birdWatcher.getBusyDays()).isEqualTo(5); } @Test @Tag("task:6") @DisplayName("The getBusyDays method correctly returns zero in case of no busy days") public void itShouldNotHaveBusyDays() { - birdWatcher = new BirdWatcher(new int[]{1, 2, 3, 3, 2, 1, 4}); + int[] counts = new int[] {1, 2, 3, 3, 2, 1, 4}; + BirdWatcher birdWatcher = new BirdWatcher(counts); assertThat(birdWatcher.getBusyDays()).isEqualTo(0); } }