Skip to content

Conversation

@jagdish-15
Copy link
Member

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

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

@github-actions
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!

@jagdish-15 jagdish-15 requested a review from kahgoh January 11, 2026 20:27
@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.

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants