-
-
Notifications
You must be signed in to change notification settings - Fork 764
Update tests bird watcher #3077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jagdish-15
merged 13 commits into
exercism:main
from
jagdish-15:update-tests-bird-watcher
May 16, 2026
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4b33771
Update tests bird watcher
jagdish-15 eba04ea
Merge branch 'main' into update-tests-bird-watcher
jagdish-15 a7cce70
Add itIncrementDoesNotChangeCountForOtherDays test
jagdish-15 1b9b968
Fix indentation
jagdish-15 596d751
Refactor BirdWatcherTest to use new array for each test
jagdish-15 b37271b
Change getLastWeek to static method
jagdish-15 17088b2
Change getLastWeek to static method
jagdish-15 f89eb67
Fix class name from BirdWatched to BirdWatcher
jagdish-15 3a1f2f2
Fix assertion in getCountForFirstDays test
jagdish-15 f702535
Merge branch 'main' into update-tests-bird-watcher
jagdish-15 35f9340
Shift new test to the end of task 5
jagdish-15 425cb95
Fix test for incrementTodaysCount method
jagdish-15 7ddc904
Add contributor to config.json
jagdish-15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 38 additions & 31 deletions
69
exercises/concept/bird-watcher/src/test/java/BirdWatcherTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,102 +1,109 @@ | ||
| 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(countAfterIncrement - 1); | ||
| } | ||
|
|
||
| @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); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using
assertThat(countPriorIncrement).isEqualTo(15);andassertThat(countAfterIncrement ).isEqualTo(16);instead. If bothcountPriorIncrementandcountAfterIncrementare wrong, it may still be possible forassertThat(countPriorIncrement).isEqualTo(countAfterIncrement - 1)to pass.