-
-
Notifications
You must be signed in to change notification settings - Fork 759
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
Open
jagdish-15
wants to merge
10
commits into
exercism:main
Choose a base branch
from
jagdish-15:update-tests-bird-watcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−33
Open
Changes from all commits
Commits
Show all changes
10 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 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
67 changes: 36 additions & 31 deletions
67
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,107 @@ | ||
| 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(5); | ||
| } | ||
|
|
||
| @Test | ||
| @Tag("task:3") | ||
| @DisplayName("The incrementTodaysCount does not change count for other days") | ||
| public void itIncrementDoesNotChangeCountForOtherDays() { | ||
| int[] counts = new int[] {5, 1, 0, 4, 2, 3, 0}; | ||
| BirdWatcher birdWatcher = new BirdWatcher(counts); | ||
| birdWatcher.incrementTodaysCount(); | ||
| assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1); | ||
| assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(15); | ||
| } | ||
|
|
||
| @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: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.
Uh oh!
There was an error while loading. Please reload this page.
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 wonder if using
getCountForFirstDayshere might be confusing for students (implementinggetCountForFirstDaysis task 5, which comes later). Would it make sense to tag it "task:5" and move it after the othergetCountForFirstDaystest? TheassertThatis still usinggetCountForFirstDays. The test could also be described in terms ofgetCountForFirstDaysinstead. For example "incrementTodaysCount adds one to getCountForFirstDays"