Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 4 commits into exercism:main
base: main
Choose a base branch
Loading
from jagdish-15:update-tests-bird-watcher

Conversation

@jagdish-15
Copy link
Member

@jagdish-15 jagdish-15 commented Jan 11, 2026
edited
Loading

pull request

This would catch solutions like these:

 public int[] getLastWeek() {
 return birdsPerDay;
 }
 public void incrementTodaysCount() {
 for (int i = 1; i < birdsPerDay.length; i++) {
 birdsPerDay[i] = birdsPerDay[i] + 1;
 }
 }

Variants like this have appeared in student solutions and currently pass the tests, even though they don’t align with the exercise instructions


Reviewer Resources:

Track Policies

Copy link
Contributor

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

@BeforeEach
public void setUp() {
birdWatcher = new BirdWatcher(lastWeek);
birdWatcher = new BirdWatcher(currentWeek);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to invalidate solutions that return the array in getLastWeek, like this one.

If our objective is to just capture the incrementTodaysCount, I think we could just change itIncrementTodaysCount.

Copy link
Member Author

@jagdish-15 jagdish-15 Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you’re getting at, but this solution is fundamentally incorrect:

 public int[] getLastWeek() {
 return birdsPerDay;
 }

This method returns the current week, not the previous week.
According to the exercise instructions: "For comparison purposes, you always keep a copy of last week's counts nearby, which were: 0, 2, 5, 3, 7, 8 and 4. "

If birdsPerDay were truly representing the previous week, then the last index of the array could not correspond to today. That alone makes this implementation inconsistent with the intended model.

These solutions were effectively getting a free pass because the test data happened to use the same values for both the current week and the "previous week" mentioned in the introduction. As a result, logically incorrect implementations still passed the tests.

Curious to hear your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see where you are coming from. The instructions for getLastWeek seem to imply students should always be defining the returned array. This would be within scope of this exercise (design.md mentions one of the objects is to be able to define an array).

But I think the setup with the two arrays in the test class could be confusing as their usage or intent might not be as clear. I prefer the C# implementation, where each test creates the BirdWatcher with its own input and getLastWeek is like a static method (so that we don't have to make an instance of BirdWatcher to call getLastWeek).

Alternatively, if we were to stick with a common array that gets reused, I'd preferring sticking to just one array in the test class that is used by the test method instead of having two arrays. In this case, we could change the array contents in this PR so that it is no longer the matches the expected lastWeek.

jagdish-15 reacted with thumbs up emoji
birdWatcher.incrementTodaysCount();
int firstSixDaysAfterIncrement = birdWatcher.getCountForFirstDays(6);
assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1);
assertThat(firstSixDaysAfterIncrement).isEqualTo(firstSixDaysBeforeIncrement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is a clever way (using getCountForFirstDays). Just couple of minor comments for this one:

  • We could simplify this by doing calculating the expected value directly, like we currently do in the other test for getCountForFirstDays (i.e. assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);).
  • I think it can be confusing why we're asserting getCountForFirstDays in this test. I'd suggest moving to a separate test so that the test can be described in the @DisplayName and test name. For example:
public void itIncrementDoesNotChangeCountForOtherDays() {
 birdWatcher.incrementTodaysCount();
 assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);
}

jagdish-15 reacted with heart emoji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kahgoh kahgoh kahgoh left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /