-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
Update tests two bucket #2877
base: main
Are you sure you want to change the base?
Update tests two bucket #2877
Conversation
I think with the error messages I think it is fine to leave them out of the exception. But, I think we should make our own exception instead of reusing |
@kahgoh, thank you for the suggestion—it does make a lot of sense to create a custom exception for this purpose. public class UnreachableGoalException extends RuntimeException {
public UnreachableGoalException() {
super();
}
public UnreachableGoalException(String message) {
super(message);
}
public UnreachableGoalException(String message, Throwable cause) {
super(message, cause);
}
} That said, when I think about this, we've used While your suggestion is undoubtedly a more "proper" and robust approach, it might feel a little inconsistent with the conventions used elsewhere. What are your thoughts on this? How do you think I should proceed? |
I think there is also precedence for making our own exceptions for our exercises, like BinarySearch and TreeBuilding. But yeah, the think the exception would look something like that. |
Sure, I'll get right on it as soon as possible, since I already have the body of the custom Exception ready. However, I'll implement it the way it's done in exercises like "Binary Search" and "Tree Building," instead of following the approach in "Calculator Conundrum," as that causes build failure issues for Windows users (as highlighted in the forum discussion). I was also considering implementing similar custom Exceptions in exercises like "Change," since an unassignable change value shouldn’t technically throw an |
Sounds good. Feel free to update "Calculator Conundrum" as well.
I'm reluctant to make this change in the other exercises. On one hand, I agree that there are other exercises where a custom exception makes sense. But on the other hand, wouldn't it mean solutions that students have already submitted become invalid if they use the custom exception? A lot of the community solutions would become invalid or outdated. The change would likely require the system to re-run tests on existing solutions, which incurs a cost (if you're interested, there is a note about expensive operations in Avoiding triggering unnecessary test runs). I'm not quite sure if the benefit is worth the cost from making the change. |
Great! I'll get to updating "Calculator Conundrum" and this exercise as soon as possible—sorry for the delay! Regarding the change to custom exceptions in other exercises, I completely agree with your point about the cost and the potential impact on existing solutions. Updating all exercises to use custom exceptions would indeed risk invalidating many community solutions, requiring a system-wide test rerun, which can be resource-intensive. For this particular exercise, however, the situation seems different. Since the tests have been updated from the problem-specification repository, community solutions for this exercise are already going to be invalidated. If updates from the problem-specification repo are frequent and similar changes would cause solutions to become outdated anyway, we could consider making this adjustment now. That said, it really comes down to the priority and whether the benefits of introducing custom exceptions outweigh the potential disruption. Let me know what you decide! |
I agree, I think updating the Two Buckets exercise to meet the problem specifications and using the custom exception is fine. Its only updating the other exercises to use a custom exception like "Change" I'm reluctant to if they currently "work" with |
1 similar comment
I agree, I think updating the Two Buckets exercise to meet the problem specifications and using the custom exception is fine. Its only updating the other exercises to use a custom exception like "Change" I'm reluctant to if they currently "work" with |
|
||
TwoBucket twoBucket = new TwoBucket(6, 15, 5, "one"); | ||
|
||
assertThatExceptionOfType(IllegalArgumentException.class) |
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 think it is a bit odd to have to have to assert that we get an exception three times in the test (I was expecting only one assertion). What do you think about refactoring to assert the exception just once? In the csharp implementation, the TwoBucket
class has a measure
method that the tests calls. It returns a "Result" object containing the number of moves, the final bucket and the other bucket or throws an exception if the goal can be reached.
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 think it is a bit odd to have to have to assert that we get an exception three times in the test
Even I found it a bit odd to assert the exception three times while implementing the tests but couldn’t think of a better alternative. However, your suggestion of returning a Result
object and handling everything within a single method is an excellent idea! This approach not only simplifies the implementation but also ensures the custom exception can be thrown effectively. Should I go ahead with this approach?
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.
Yeah, I think we can go ahead with this one as we both seem to agree it would be better this way.
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.
Yeah, I think we can go ahead with this one as we both seem to agree it would be better this way.
Pull Request
This PR adds 3 new tests to the Two Bucket exercise to sync with the
problem-specifications
repository. Two of the newly added tests check for error handling, which was not tested before. I am also unsure about the error message—should I keep it as it is in theproblem-specifications
repo or modify it to be more informative?Let me know your thoughts on this.
Reviewer Resources:
Track Policies