Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions exercises/concept/bird-watcher/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"samuelteixeiras",
"ystromm"
],
"contributors": [
"jagdish-15"
],
"files": {
"solution": [
"src/main/java/BirdWatcher.java"
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() {
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
72 changes: 41 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,112 @@
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(TODAY + 1);
assertThat(birdWatcher.getToday()).isEqualTo(5);
}

@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:5")
@DisplayName("The incrementTodaysCount method adds one to getCountForFirstDays method")
public void itIncrementDoesNotChangeCountForOtherDays() {
int[] counts = new int[] {5, 1, 0, 4, 2, 3, 0};
BirdWatcher birdWatcher = new BirdWatcher(counts);

int countPriorIncrement = birdWatcher.getCountForFirstDays(7);
birdWatcher.incrementTodaysCount();
int countAfterIncrement = birdWatcher.getCountForFirstDays(7);

assertThat(countPriorIncrement).isEqualTo(15);
assertThat(countAfterIncrement).isEqualTo(16);
}

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