|
1 | | -import org.junit.jupiter.api.BeforeEach; |
2 | 1 | import org.junit.jupiter.api.DisplayName; |
3 | 2 | import org.junit.jupiter.api.Tag; |
4 | 3 | import org.junit.jupiter.api.Test; |
|
7 | 6 |
|
8 | 7 | public class BirdWatcherTest { |
9 | 8 |
|
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 | | - |
27 | 9 | @Test |
28 | 10 | @Tag("task:1") |
29 | 11 | @DisplayName("The getLastWeek method correctly returns last week's counts") |
30 | 12 | public void itTestGetLastWeek() { |
31 | | - assertThat(birdWatcher.getLastWeek()) |
32 | | - .isEqualTo(lastWeek); |
| 13 | + assertThat(BirdWatcher.getLastWeek()).isEqualTo(new int[] {0, 2, 5, 3, 7, 8, 4}); |
33 | 14 | } |
34 | 15 |
|
35 | 16 | @Test |
36 | 17 | @Tag("task:2") |
37 | 18 | @DisplayName("The getToday method correctly returns today's counts") |
38 | 19 | 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); |
40 | 23 | } |
41 | 24 |
|
42 | 25 | @Test |
43 | 26 | @Tag("task:3") |
44 | 27 | @DisplayName("The incrementTodaysCount method correctly increments today's counts") |
45 | 28 | public void itIncrementTodaysCount() { |
| 29 | + int[] counts = new int[] {8, 8, 9, 2, 1, 6, 4}; |
| 30 | + BirdWatched birdWatcher = new BirdWatcher(counts); |
46 | 31 | birdWatcher.incrementTodaysCount(); |
47 | | - assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1); |
| 32 | + assertThat(birdWatcher.getToday()).isEqualTo(5); |
48 | 33 | } |
49 | 34 |
|
50 | 35 | @Test |
51 | 36 | @Tag("task:3") |
52 | 37 | @DisplayName("The incrementTodaysCount does not change count for other days") |
53 | 38 | public void itIncrementDoesNotChangeCountForOtherDays() { |
| 39 | + int[] counts = new int[] {5, 1, 0, 4, 2, 3, 0}; |
| 40 | + BirdWatched birdWatcher = new BirdWatcher(counts); |
54 | 41 | birdWatcher.incrementTodaysCount(); |
55 | | - assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6); |
| 42 | + assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(15); |
56 | 43 | } |
57 | 44 |
|
58 | 45 | @Test |
59 | 46 | @Tag("task:4") |
60 | 47 | @DisplayName("The hasDayWithoutBirds method returns true when at least one day had no visits") |
61 | 48 | public void itHasDayWithoutBirds() { |
| 49 | + int[] counts = new int[] {5, 5, 4, 0, 7, 6, 7}; |
| 50 | + BirdWatched birdWatcher = new BirdWatcher(counts); |
62 | 51 | assertThat(birdWatcher.hasDayWithoutBirds()).isTrue(); |
63 | 52 | } |
64 | 53 |
|
65 | 54 | @Test |
66 | 55 | @Tag("task:4") |
67 | 56 | @DisplayName("The hasDayWithoutBirds method returns false when no day had zero visits") |
68 | 57 | 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); |
70 | 60 | assertThat(birdWatcher.hasDayWithoutBirds()).isFalse(); |
71 | 61 | } |
72 | 62 |
|
73 | 63 | @Test |
74 | 64 | @Tag("task:4") |
75 | 65 | @DisplayName("The hasDayWithoutBirds method returns true if the last day has zero visits") |
76 | 66 | 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); |
78 | 69 | assertThat(birdWatcher.hasDayWithoutBirds()).isTrue(); |
79 | 70 | } |
80 | 71 |
|
81 | 72 | @Test |
82 | 73 | @Tag("task:5") |
83 | 74 | @DisplayName("The getCountForFirstDays method returns correct visits' count for given number of days") |
84 | 75 | 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); |
86 | 79 | } |
87 | 80 |
|
88 | 81 | @Test |
89 | 82 | @Tag("task:5") |
90 | 83 | @DisplayName("The getCountForFirstDays method returns overall count when number of days is higher than array size") |
91 | 84 | 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(); |
94 | 88 | } |
95 | 89 |
|
96 | 90 | @Test |
97 | 91 | @Tag("task:6") |
98 | 92 | @DisplayName("The getBusyDays method returns the correct count of busy days") |
99 | 93 | 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); |
102 | 97 | } |
103 | 98 |
|
104 | 99 | @Test |
105 | 100 | @Tag("task:6") |
106 | 101 | @DisplayName("The getBusyDays method correctly returns zero in case of no busy days") |
107 | 102 | 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); |
109 | 105 | assertThat(birdWatcher.getBusyDays()).isEqualTo(0); |
110 | 106 | } |
111 | 107 | } |
0 commit comments