Skip to content
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 #4121: Added tests for TokenSubject #5669

Merged
merged 24 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4138514
Added tests for TokenSubject
Jan 26, 2025
7855384
Merge branch 'develop' into token-subject-test
theayushyadav11 Jan 26, 2025
93c96c9
Removed Todo
Jan 26, 2025
53d32a0
check
Jan 26, 2025
302cc72
removed Todo
Jan 26, 2025
c895c5c
Merge branch 'develop' into token-subject-test
theayushyadav11 Jan 28, 2025
e78d25d
renamed functions
Jan 31, 2025
22a7ca5
removed from test_file_exemptions.textproto
Jan 31, 2025
50b0503
Merge branch 'develop' into token-subject-test
theayushyadav11 Jan 31, 2025
e2acea2
Merge branch 'develop' into token-subject-test
theayushyadav11 Feb 2, 2025
289a35a
Merge branch 'develop' into token-subject-test
theayushyadav11 Feb 9, 2025
b5d09d8
some cleanup
Feb 11, 2025
2fbc8cb
Merge branch 'develop' into token-subject-test
theayushyadav11 Feb 11, 2025
a311582
cleanup
Feb 11, 2025
2c7e0ad
fixed buildifier issue
Feb 11, 2025
ddc362b
resolving
Feb 11, 2025
6223c69
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
5328d78
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
e472aa7
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
4d05905
D
Feb 11, 2025
233d819
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
f1823dd
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
d87fcb4
Merge remote-tracking branch 'origin/token-subject-test' into token-s…
Feb 11, 2025
44f2bce
Merge branch 'develop' into token-subject-test
theayushyadav11 Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -4106,10 +4106,6 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/MathParsingErrorSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/mockito/MockitoKotlinHelper.kt"
test_file_not_required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import org.oppia.android.util.math.MathTokenizer.Companion.Token.RightParenthesi
import org.oppia.android.util.math.MathTokenizer.Companion.Token.SquareRootSymbol
import org.oppia.android.util.math.MathTokenizer.Companion.Token.VariableName

// TODO(#4121): Add tests for this class.

/**
* Truth subject for verifying properties of [Token]s.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,17 @@ oppia_android_test(
"//third_party:robolectric_android-all",
],
)

oppia_android_test(
name = "TokenSubjectTest",
srcs = ["TokenSubjectTest.kt"],
custom_package = "org.oppia.android.testing.math",
test_class = "org.oppia.android.testing.math.TokenSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//testing/src/main/java/org/oppia/android/testing/math:token_subject",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)
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()
}
}
}
Loading