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