-
Notifications
You must be signed in to change notification settings - Fork 548
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
Fix #1889 : Throughly test NumericInputIsWithinToleranceRuleClassifier
#1922
Fix #1889 : Throughly test NumericInputIsWithinToleranceRuleClassifier
#1922
Conversation
@MohamedMedhat1998 PTAL |
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
fun testIntAnswer_secondStringInput_throwsException() { |
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 one seems a bit redundant to me as we have already checked that the second input won't work with string. Fix this elsewhere too
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.
Done
@aggarwalpulkit596 I have also updated the screenshot in the PR description. Please take a look. |
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
fun testIntAnswer_missingSecondInput_throwsException() { |
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.
same as above
} | ||
|
||
@Test | ||
fun testRealAnswer_firstStringInput_throwsException() { |
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.
Add a test case with 3 inputs as well and I guess i wasn't clear enough in my previous comments but what i wanted was to have kept the existing test cases in which there was incorrect input variable like c
or anything
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.
If I test with 3 inputs, exception's error is a bit weird
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.
@aggarwalpulkit596 Also isn't that case covered in missing inputs and incorrect inputs ?
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.
@prayutsu what's the error for 3 inputs?
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.
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.
@MohamedMedhat1998 What do you think?
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.
@prayutsu having test cases that check the case where we have 3 inputs is a good idea.
I suggest trying to pass a map
that contains both "x" and "tol" + some other value ("y" for example) and observe which exception you will get. After you know the exception, you can write a test case that checks whether this exception is thrown or not.
It's kinda weird to gerenrate an exception then test whether it is generated or not 😅, but I think it is ok.
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.
@MohamedMedhat1998 I tried the same, but see the exception in the screenshot, it does not throw the exception of the "same type" that we get in other test cases
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.
@aggarwalpulkit596 I think this will not work because, currently exception message is of the form
Expected classifier inputs to contain parameter with name 'x' but had: [c, tol]
but in case of three inputs it can't display the range
Please, see this comment @MohamedMedhat1998
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.
@MohamedMedhat1998 I tried the same, but see the exception in the screenshot, it does not throw the exception of the "same type" that we get in other test cases
Can you share your code, please?
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.
The overall PR is very good but I have left some comments, PTAL.
} | ||
|
||
@Test | ||
fun testPositiveIntAnswer_positiveRealInput_positiveRealTolerance_answerWithinTolerance() { |
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.
testPositiveIntAnswer_positiveRealInput_positiveRealTolerance_answerWithinTolerance
to testPositiveRealAnswer_positiveRealInput_positiveRealTolerance_answerWithinTolerance
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.
@MohamedMedhat1998 Test cases with Int are covering separate tests, they have been added intentionally, please confirm once and I'll change it.
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 that you have added test cases for both int
and real
, but in this test case you are using real
as an answer (POSITIVE_REAL_VALUE_2_5
) but the name is int
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.
Okay this would be fixed in the next commit
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
fun testNegativeRealAnswer_negativeRealInput_positiveIntTolerance_answerWithinTolerance() { |
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.
testNegativeRealAnswer_negativeRealInput_positiveIntTolerance_answerWithinTolerance
to testNegativeIntAnswer_negativeIntInput_positiveIntTolerance_answerWithinTolerance
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.
Was this fixed?
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.
yup, this is fixed now
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
...domain/classify/rules/numberinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Outdated
Show resolved
Hide resolved
@MohamedMedhat1998 Note - All changes are not fixed yet |
|
||
@Test | ||
fun testIntAnswer_extraInput_throwsException() { | ||
val inputs = mapOf( |
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.
@MohamedMedhat1998 This is the testcase
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.
Ok, thanks.
Btw you didn't have to push the changes. If you are unsure of the code and you don't want to push it, you can simply add it as a code snippet in a comment like this:
@Test
fun testIntAnswer_extraInput_throwsException() {
val inputs = mapOf(
"c" to POSITIVE_INT_VALUE_2,
"x" to POSITIVE_INT_VALUE_3,
"tol" to POSITIVE_INT_VALUE_1
)
val exception = assertThrows(IllegalStateException::class) {
inputIsWithinToleranceRuleClassifier
.matches(answer = POSITIVE_INT_VALUE_2, inputs = inputs)
}
assertThat(exception)
.hasMessageThat()
.contains("Expected classifier inputs to contain parameter with name 'tol' but had: [x]")
}
Try removing any assertion related to the exception and simply use an incorrect map in the normal test cases like testNegativeRealAnswer_negativeRealInput_positiveRealTolerance_answerWithinTolerance
and observe the output
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.
okay, thanks
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 tried this -
@Test
fun testIntAnswer_extraInput_throwsException() {
val inputs = mapOf(
"c" to POSITIVE_INT_VALUE_2,
"x" to POSITIVE_INT_VALUE_3,
"tol" to POSITIVE_INT_VALUE_1
)
val matches =
inputIsWithinToleranceRuleClassifier
.matches(answer = POSITIVE_INT_VALUE_2, inputs = inputs)
assertThat(matches).isFalse()
}
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.
private fun <T : Throwable> assertThrows(type: KClass<T>, operation: () -> Unit): T {
try {
operation()
fail("Expected to encounter exception of $type")
} catch (t: Throwable) {
if (type.isInstance(t)) {
return type.cast(t)
}
// Unexpected exception; throw it.
throw t
}
}
@MohamedMedhat1998 I think we are getting an unexpected exception
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 sort of a general "how do we handle exceptional cases" question. In this case, adding a check for extra input helps make things more predictable, but extra parameters don't actually interfere with the classifier's ability to do its job.
I'm also curious to know what others think about this.
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.
@MohamedMedhat1998 I think we can add test to check exceptions.
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.
@MohamedMedhat1998 I think we can add test to check exceptions.
But actually, no exception is thrown in this case. So, whenever we add test cases for the exceptions, they fail.
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.
@BenHenning Any suggestions here as per above comment?
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.
That's actually what I was curious about other people weighing in on. :)
I'm actually on the fence here, but given that I think we should just add the check & a new exception for it.
This should probably be tracked in a separate issue since will need to retroactively add tests for this case in each classifier being tested so far.
@aggarwalpulkit596 @MohamedMedhat1998 Any updates on this? |
@prayutsu concerning the multiple inputs tests, we still need the opinions of the others. Concerning the negative tolerance, I don't think we need them, but let's wait for the final decision from Rajat, @rt4914 can you finalize this, please? Other than that, everything is really simple (removing some existing tests or leaving them - we can finalize this quickly), but for now, let's focus on the multiple inputs tests first. |
@MohamedMedhat1998 Sure |
@rt4914 @aggarwalpulkit596 @BenHenning @MohamedMedhat1998 |
@rt4914 @aggarwalpulkit596 Can we please have a final verdict on this? |
@prayutsu @MohamedMedhat1998 I have replied to all the comments addressed to me. This PR is blocked on two points:
|
Update: I have message @aggarwalpulkit596 personally to have a look at this PR. Lets wait for him. |
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.
Thanks @prayutsu! This is looking really good to me. I have a suggestions for a few more tests, then I think this PR will be ready for merging.
...omain/classify/rules/numericinput/NumericInputIsWithinToleranceRuleClassifierProviderTest.kt
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
fun testPositiveRealAnswer_negativeRealInput_negativeRealTolerance_answerNotWithinTolerance() { |
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.
Thanks. I actually intended that we add an exception to catch this case, but I'm backing off on that. I think we should instead:
- Add a test here to verify that negative tolerance fails in a case where it would have passed for positive tolerance (to verify that we properly "no-op" in this case)
- @rt4914 or someone else involved with this PR should file an Oppia web issue to add validation to ensure tolerance is always >= 0
@prayutsu can you take care of (1)?
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.
Thanks @prayutsu. This LGTM!
Given other approvals, I'm going to go ahead and merge this if all checks pass. @rt4914 see the comment thread above when you get a chance. |
@BenHenning Thanks |
@BenHenning Can you please put a comment - "give @prayutsu 25 points" ? |
@MohamedMedhat1998 or @aggarwalpulkit596 could you do the scoring here? @prayutsu since I'm not an SLoP mentor, I can't actually score the PRs. |
No issues, @MohamedMedhat1998 will update this tomorrow, thanks for merging it |
give @prayutsu 25 points |
Issue filed for following comment: #1922 (comment) |
Explanation
Fixes #1889 : Test cases are added to thoroughly test
NumericInputIsWithinToleranceRuleClassifier
Checklist
All tests are passing -
