forked from oppia/oppia-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes oppia#4121 This pull request introduces a new test class `TokenSubjectTest` to the `oppia_android_test` suite, focusing on validating various aspects of the `Token` class from the `MathTokenizer` utility. The primary changes include the addition of the test class itself and the corresponding Bazel build rule. ### Key Changes: #### Addition of Test Class: * [`testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt`](diffhunk://#diff-aeecd58bdeac384c551e2a73a6debca08e2bdfb0492eb84007773ed78af057d0R1-R180): Added a new test class `TokenSubjectTest` with multiple test methods to verify the correctness of different `Token` types and their properties. #### Bazel Build Rule: * [`testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel`](diffhunk://#diff-8a86bceb0e654069d42dcb4e76a52f65aeea3bc7d76a9cdff53f5e4bdde93f08R70-R85): Added a new `oppia_android_test` target for `TokenSubjectTest`, specifying its dependencies and configuration. #### Screenshot of the passing tests.  ## Essential Checklist <!-- Please tick the relevant boxes by putting an "x" in them. --> - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)) --------- Co-authored-by: theayushyadav11 <your.email@example.com>
- Loading branch information
1 parent
1586f27
commit 893c7a2
Showing
4 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
package org.oppia.android.testing.math | ||
|
||
import org.junit.Assert.assertThrows | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
import org.oppia.android.util.math.MathTokenizer.Companion.Token | ||
|
||
/** Tests for [TokenSubject]. */ | ||
@RunWith(JUnit4::class) | ||
class TokenSubjectTest { | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCorrectStartIndex() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(10) | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_failsWithIncorrectStartIndex() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(11) | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCorrectEndIndex() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(15) | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_failsWithIncorrectEndIndex() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(14) | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCorrectPositiveIntegerValue() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(42) | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_failsWithIncorrectPositiveIntegerValue() { | ||
val token = Token.PositiveInteger(42, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(45) | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCoreectPositiveRealNumberValue() { | ||
val token = Token.PositiveRealNumber(3.14, 10, 15) | ||
TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(3.14) | ||
} | ||
|
||
fun testTokenSubject_failsWithIncorrectPositiveRealNumberValue() { | ||
val token = Token.PositiveRealNumber(3.14, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(25) | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCorrectVariableName() { | ||
val token = Token.VariableName("x", 10, 15) | ||
TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("x") | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_isVariableWhoseName_incorrectName_fails() { | ||
val token = Token.VariableName("x", 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("y") | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_passesWithCorrectFunctionNameAndAllowedStatus() { | ||
val token = Token.FunctionName("sqrt", true, 10, 15) | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasNameThat().isEqualTo("sqrt") | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_failsWithIncorrectFunctionNameAndAllowedStatus() { | ||
val token = Token.FunctionName("sqrt", true, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasNameThat().isEqualTo("sine") | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsMinusSymbol() { | ||
val token = Token.MinusSymbol(10, 11) | ||
TokenSubject.assertThat(token).isMinusSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsSquareRootSymbol() { | ||
val token = Token.SquareRootSymbol(10, 11) | ||
TokenSubject.assertThat(token).isSquareRootSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsPlusSymbol() { | ||
val token = Token.PlusSymbol(10, 11) | ||
TokenSubject.assertThat(token).isPlusSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsMultiplySymbol() { | ||
val token = Token.MultiplySymbol(10, 11) | ||
TokenSubject.assertThat(token).isMultiplySymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsDivideSymbol() { | ||
val token = Token.DivideSymbol(10, 11) | ||
TokenSubject.assertThat(token).isDivideSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsExponentiationSymbol() { | ||
val token = Token.ExponentiationSymbol(10, 11) | ||
TokenSubject.assertThat(token).isExponentiationSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsEqualsSymbol() { | ||
val token = Token.EqualsSymbol(10, 11) | ||
TokenSubject.assertThat(token).isEqualsSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsLeftParenthesisSymbol() { | ||
val token = Token.LeftParenthesisSymbol(10, 11) | ||
TokenSubject.assertThat(token).isLeftParenthesisSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_symbolIsRightParenthesisSymbol() { | ||
val token = Token.RightParenthesisSymbol(10, 11) | ||
TokenSubject.assertThat(token).isRightParenthesisSymbol() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_failsWithIncorrectSymbol() { | ||
val token = Token.RightParenthesisSymbol(10, 11) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).isMinusSymbol() | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_checkIsInvalidToken_passes() { | ||
val token = Token.InvalidToken(10, 11) | ||
TokenSubject.assertThat(token).isInvalidToken() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_checkIsInvalidToken_fails() { | ||
val token = Token.PositiveInteger(10, 11, 42) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token).isInvalidToken() | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_checkIsIncompleteFunctionName() { | ||
val token = Token.IncompleteFunctionName(10, 11) | ||
TokenSubject.assertThat(token).isIncompleteFunctionName() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_functionNameSubject_nameCheck_passes() { | ||
val token = Token.FunctionName("sqrt", true, 10, 15) | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasNameThat().isEqualTo("sqrt") | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_functionNameSubject_nameCheck_fails() { | ||
val token = Token.FunctionName("sqrt", true, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasNameThat().isEqualTo("sin") | ||
} | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_functionNameSubject_allowedPropertyCheck_passes() { | ||
val token = Token.FunctionName("sqrt", true, 10, 15) | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasIsAllowedPropertyThat().isTrue() | ||
} | ||
|
||
@Test | ||
fun testTokenSubject_functionNameSubject_allowedPropertyCheck_fails() { | ||
val token = Token.FunctionName("sqrt", false, 10, 15) | ||
assertThrows(AssertionError::class.java) { | ||
TokenSubject.assertThat(token) | ||
.isFunctionNameThat() | ||
.hasIsAllowedPropertyThat().isTrue() | ||
} | ||
} | ||
} |