-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
base: main
Are you sure you want to change the base?
Conversation
|
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. For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
| @BeforeEach | ||
| public void setUp() { | ||
| birdWatcher = new BirdWatcher(lastWeek); | ||
| birdWatcher = new BirdWatcher(currentWeek); |
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.
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.
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 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.
| birdWatcher.incrementTodaysCount(); | ||
| int firstSixDaysAfterIncrement = birdWatcher.getCountForFirstDays(6); | ||
| assertThat(birdWatcher.getToday()).isEqualTo(TODAY + 1); | ||
| assertThat(firstSixDaysAfterIncrement).isEqualTo(firstSixDaysBeforeIncrement); |
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.
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
getCountForFirstDaysin this test. I'd suggest moving to a separate test so that the test can be described in the@DisplayNameand test name. For example:
public void itIncrementDoesNotChangeCountForOtherDays() {
birdWatcher.incrementTodaysCount();
assertThat(birdWatcher.getCountForFirstDays(6)).isEqualTo(DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6);
}Added a test to verify that incrementTodaysCount does not affect counts for other days.
pull request
This would catch solutions like these:
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