Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
67 changes: 36 additions & 31 deletions exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java
Original file line number Diff line number Diff line change
@@ -1,102 +1,107 @@
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);
Copy link
Copy Markdown
Member

@kahgoh kahgoh May 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if using getCountForFirstDays here might be confusing for students (implementing getCountForFirstDays is task 5, which comes later). Would it make sense to tag it "task:5" and move it after the other getCountForFirstDays test? The assertThat is still using getCountForFirstDays. The test could also be described in terms of getCountForFirstDays instead. For example "incrementTodaysCount adds one to getCountForFirstDays"

}

@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();
}

@Test
@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();
}

@Test
@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();
}

@Test
@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);
}
}