Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import org.junit.jupiter.api.BeforeEach;
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 static final int DAY1 = 7;
private static final int DAY2 = 0;
private static final int DAY3 = 4;
private static final int DAY4 = 8;
private static final int DAY5 = 5;
private static final int DAY6 = 2;
private static final int TODAY = 3;

private BirdWatcher birdWatcher;
private final int[] lastWeek = {DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, TODAY};
private final int[] currentWeek = {DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, TODAY};
private final int[] lastWeek = {0, 2, 5, 3, 7, 8, 4};

@BeforeEach
public void setUp() {
birdWatcher = new BirdWatcher(lastWeek);
birdWatcher = new BirdWatcher(currentWeek);
Copy link
Member

Choose a reason for hiding this comment

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

This is going to invalidate solutions that return the array in getLastWeek, like this one.

If our objective is to just capture the incrementTodaysCount, I think we could just change itIncrementTodaysCount.

}

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

@Test
Expand All @@ -42,13 +43,16 @@ public void itTestGetToday() {
@Tag("task:3")
@DisplayName("The incrementTodaysCount method correctly increments today's counts")
public void itIncrementTodaysCount() {
int firstSixDaysBeforeIncrement = birdWatcher.getCountForFirstDays(6);
birdWatcher.incrementTodaysCount();
int firstSixDaysAfterIncrement = birdWatcher.getCountForFirstDays(6);
assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1);
assertThat(firstSixDaysAfterIncrement).isEqualTo(firstSixDaysBeforeIncrement);
Copy link
Member

Choose a reason for hiding this comment

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

Ah, this is a clever way (using getCountForFirstDays). Just couple of minor comments for this one:

  • We could simplify this by doing calculating the expected value directly, like we currently do in the other test for getCountForFirstDays (i.e. assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);).
  • I think it can be confusing why we're asserting getCountForFirstDays in this test. I'd suggest moving to a separate test so that the test can be described in the @DisplayName and test name. For example:
public void itIncrementDoesNotChangeCountForOtherDays() {
  birdWatcher.incrementTodaysCount();
  assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);
}

}

@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() {
assertThat(birdWatcher.hasDayWithoutBirds()).isTrue();
}
Expand Down Expand Up @@ -88,7 +92,7 @@ public void itTestGetCountForMoreDaysThanTheArraySize() {
@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
// DAY1, DAY4 and DAY5 are all >= 5 birds
assertThat(birdWatcher.getBusyDays()).isEqualTo(3);
}

Expand Down