Skip to content

Commit 596d751

Browse files
authored
Refactor BirdWatcherTest to use new array for each test
1 parent 1b9b968 commit 596d751

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.junit.jupiter.api.BeforeEach;
21
import org.junit.jupiter.api.DisplayName;
32
import org.junit.jupiter.api.Tag;
43
import org.junit.jupiter.api.Test;
@@ -7,105 +6,102 @@
76

87
public class BirdWatcherTest {
98

10-
private static final int DAY1 = 7;
11-
private static final int DAY2 = 0;
12-
private static final int DAY3 = 4;
13-
private static final int DAY4 = 8;
14-
private static final int DAY5 = 5;
15-
private static final int DAY6 = 2;
16-
private static final int TODAY = 3;
17-
18-
private BirdWatcher birdWatcher;
19-
private final int[] currentWeek = {DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, TODAY};
20-
private final int[] lastWeek = {0, 2, 5, 3, 7, 8, 4};
21-
22-
@BeforeEach
23-
public void setUp() {
24-
birdWatcher = new BirdWatcher(currentWeek);
25-
}
26-
279
@Test
2810
@Tag("task:1")
2911
@DisplayName("The getLastWeek method correctly returns last week's counts")
3012
public void itTestGetLastWeek() {
31-
assertThat(birdWatcher.getLastWeek())
32-
.isEqualTo(lastWeek);
13+
assertThat(BirdWatcher.getLastWeek()).isEqualTo(new int[] {0, 2, 5, 3, 7, 8, 4});
3314
}
3415

3516
@Test
3617
@Tag("task:2")
3718
@DisplayName("The getToday method correctly returns today's counts")
3819
public void itTestGetToday() {
39-
assertThat(birdWatcher.getToday()).isEqualTo(TODAY);
20+
int[] counts = new int[] {8, 8, 9, 5, 4, 7, 10};
21+
BirdWatched birdWatcher = new BirdWatcher(counts);
22+
assertThat(birdWatcher.getToday()).isEqualTo(10);
4023
}
4124

4225
@Test
4326
@Tag("task:3")
4427
@DisplayName("The incrementTodaysCount method correctly increments today's counts")
4528
public void itIncrementTodaysCount() {
29+
int[] counts = new int[] {8, 8, 9, 2, 1, 6, 4};
30+
BirdWatched birdWatcher = new BirdWatcher(counts);
4631
birdWatcher.incrementTodaysCount();
47-
assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1);
32+
assertThat(birdWatcher.getToday()).isEqualTo(5);
4833
}
4934

5035
@Test
5136
@Tag("task:3")
5237
@DisplayName("The incrementTodaysCount does not change count for other days")
5338
public void itIncrementDoesNotChangeCountForOtherDays() {
39+
int[] counts = new int[] {5, 1, 0, 4, 2, 3, 0};
40+
BirdWatched birdWatcher = new BirdWatcher(counts);
5441
birdWatcher.incrementTodaysCount();
55-
assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);
42+
assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(15);
5643
}
5744

5845
@Test
5946
@Tag("task:4")
6047
@DisplayName("The hasDayWithoutBirds method returns true when at least one day had no visits")
6148
public void itHasDayWithoutBirds() {
49+
int[] counts = new int[] {5, 5, 4, 0, 7, 6, 7};
50+
BirdWatched birdWatcher = new BirdWatcher(counts);
6251
assertThat(birdWatcher.hasDayWithoutBirds()).isTrue();
6352
}
6453

6554
@Test
6655
@Tag("task:4")
6756
@DisplayName("The hasDayWithoutBirds method returns false when no day had zero visits")
6857
public void itShouldNotHaveDaysWithoutBirds() {
69-
birdWatcher = new BirdWatcher(new int[]{1, 2, 5, 3, 7, 8, 4});
58+
int[] counts = new int[] {4, 5, 9, 10, 9, 4, 3};
59+
BirdWatched birdWatcher = new BirdWatcher(counts);
7060
assertThat(birdWatcher.hasDayWithoutBirds()).isFalse();
7161
}
7262

7363
@Test
7464
@Tag("task:4")
7565
@DisplayName("The hasDayWithoutBirds method returns true if the last day has zero visits")
7666
public void itHasLastDayWithoutBirds() {
77-
birdWatcher = new BirdWatcher(new int[]{1, 2, 5, 3, 7, 8, 0});
67+
int[] counts = new int[] {1, 2, 5, 3, 7, 8, 0};
68+
BirdWatched birdWatcher = new BirdWatcher(counts);
7869
assertThat(birdWatcher.hasDayWithoutBirds()).isTrue();
7970
}
8071

8172
@Test
8273
@Tag("task:5")
8374
@DisplayName("The getCountForFirstDays method returns correct visits' count for given number of days")
8475
public void itTestGetCountForFirstDays() {
85-
assertThat(birdWatcher.getCountForFirstDays(4)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4);
76+
int[] counts = new int[] {5, 9, 12, 6, 8, 8, 17};
77+
BirdWatched birdWatcher = new BirdWatcher(counts);
78+
assertThat(birdWatcher.getCountForFirstDays(4)).isEqualTo(32);
8679
}
8780

8881
@Test
8982
@Tag("task:5")
9083
@DisplayName("The getCountForFirstDays method returns overall count when number of days is higher than array size")
9184
public void itTestGetCountForMoreDaysThanTheArraySize() {
92-
assertThat(birdWatcher.getCountForFirstDays(10))
93-
.isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6 + TODAY);
85+
int[] counts = new int[] {5, 9, 12, 6, 8, 8, 17};
86+
BirdWatched birdWatcher = new BirdWatcher(counts);
87+
assertThat(birdWatcher.getCountForFirstDays(65)).isEqualTo();
9488
}
9589

9690
@Test
9791
@Tag("task:6")
9892
@DisplayName("The getBusyDays method returns the correct count of busy days")
9993
public void itTestGetCountForBusyDays() {
100-
// DAY1, DAY4 and DAY5 are all >= 5 birds
101-
assertThat(birdWatcher.getBusyDays()).isEqualTo(3);
94+
int[] counts = new int[] {4, 9, 5, 7, 8, 8, 2};
95+
BirdWatched birdWatcher = new BirdWatcher(counts);
96+
assertThat(birdWatcher.getBusyDays()).isEqualTo(5);
10297
}
10398

10499
@Test
105100
@Tag("task:6")
106101
@DisplayName("The getBusyDays method correctly returns zero in case of no busy days")
107102
public void itShouldNotHaveBusyDays() {
108-
birdWatcher = new BirdWatcher(new int[]{1, 2, 3, 3, 2, 1, 4});
103+
int[] counts = new int[] {1, 2, 3, 3, 2, 1, 4};
104+
BirdWatched birdWatcher = new BirdWatcher(counts);
109105
assertThat(birdWatcher.getBusyDays()).isEqualTo(0);
110106
}
111107
}

0 commit comments

Comments
 (0)