From 413851476633d0ffd728e070f6d17369784a906f Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Mon, 27 Jan 2025 01:05:57 +0530 Subject: [PATCH 1/8] Added tests for TokenSubject --- .../oppia/android/testing/math/BUILD.bazel | 16 ++ .../android/testing/math/TokenSubjectTest.kt | 180 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt diff --git a/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel b/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel index 354acf48077..c6e97e829f0 100644 --- a/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel +++ b/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel @@ -67,3 +67,19 @@ 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 = [ + "//model/src/main/proto:math_java_proto_lite", + "//testing/src/main/java/org/oppia/android/testing/math:token_subject", + "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", + "//third_party:com_google_truth_truth", + "//third_party:junit_junit", + "//third_party:robolectric_android-all", + ], +) diff --git a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt new file mode 100644 index 00000000000..bba6865de4d --- /dev/null +++ b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt @@ -0,0 +1,180 @@ +package org.oppia.android.testing.math + +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 testHasStartIndexThat_correctIndex_passes() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(10) + } + + @Test(expected = AssertionError::class) + fun testHasStartIndexThat_incorrectIndex_fails() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(11) + } + + @Test + fun testHasEndIndexThat_correctIndex_passes() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(15) + } + + @Test(expected = AssertionError::class) + fun testHasEndIndexThat_incorrectIndex_fails() { + val token = Token.PositiveInteger(10, 15, 42) + TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(14) + } + + @Test + fun testIsPositiveIntegerWhoseValue_correctValue_passes() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(42) + } + + @Test(expected = AssertionError::class) + fun testIsPositiveIntegerWhoseValue_incorrectType_fails() { + val token = Token.VariableName("x", 15, 10) + TokenSubject.assertThat(token).isPositiveIntegerWhoseValue() + } + + @Test + fun testIsPositiveRealNumberWhoseValue_correctValue_passes() { + val token = Token.PositiveRealNumber(3.14, 15, 10) + TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(3.14) + } + + fun testIisPositiveRealNumberWhoseValue_incorrectType_fails() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isNotEqualTo(25) + } + + @Test + fun testIsVariableWhoseName_correctName_passes() { + val token = Token.VariableName("x", 10, 15) + TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("x") + } + + @Test(expected = AssertionError::class) + fun testIsVariableWhoseName_incorrectType_fails() { + val token = Token.PositiveInteger(42, 10, 15) + TokenSubject.assertThat(token).isVariableWhoseName() + } + + @Test + fun testIsFunctionNameThat_correctNameAndAllowedStatus_passes() { + val token = Token.FunctionName("sqrt", true, 10, 15) + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasNameThat().isEqualTo("sqrt") + } + + @Test + fun testSymbol_IsMinusSymbol() { + val token = Token.MinusSymbol(10, 11) + TokenSubject.assertThat(token).isMinusSymbol() + } + + @Test + fun testSymbol_IsSquareRootSymbol() { + val token = Token.SquareRootSymbol(10, 11) + TokenSubject.assertThat(token).isSquareRootSymbol() + } + + @Test + fun testSymbol_IsPlusSymbol() { + val token = Token.PlusSymbol(10, 11) + TokenSubject.assertThat(token).isPlusSymbol() + } + + @Test + fun testSymbol_IsMultiplySymbol() { + val token = Token.MultiplySymbol(10, 11) + TokenSubject.assertThat(token).isMultiplySymbol() + } + + @Test + fun testSymbol_IsDivideSymbol() { + val token = Token.DivideSymbol(10, 11) + TokenSubject.assertThat(token).isDivideSymbol() + } + + @Test + fun testSymbol_IsExponentiationSymbol() { + val token = Token.ExponentiationSymbol(10, 11) + TokenSubject.assertThat(token).isExponentiationSymbol() + } + + @Test + fun testSymbol_IsEqualsSymbol() { + val token = Token.EqualsSymbol(10, 11) + TokenSubject.assertThat(token).isEqualsSymbol() + } + + @Test + fun testSymbol_IsLeftParenthesisSymbol() { + val token = Token.LeftParenthesisSymbol(10, 11) + TokenSubject.assertThat(token).isLeftParenthesisSymbol() + } + + @Test + fun testSymbol_IsRightParenthesisSymbol() { + val token = Token.RightParenthesisSymbol(10, 11) + TokenSubject.assertThat(token).isRightParenthesisSymbol() + } + + @Test(expected = AssertionError::class) + fun testSymbolMethods_incorrectType_fails() { + TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isMinusSymbol() + } + + @Test + fun testInvalidTokenMethods_correctTypes_pass() { + TokenSubject.assertThat(Token.InvalidToken(10, 11)).isInvalidToken() + TokenSubject.assertThat(Token.IncompleteFunctionName(10, 11)).isIncompleteFunctionName() + } + + @Test(expected = AssertionError::class) + fun testInvalidTokenMethods_incorrectType_fails() { + TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isInvalidToken() + } + + @Test + fun testFunctionNameSubject_nameCheck_passes() { + val token = Token.FunctionName("sqrt", true, 10, 15) + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasNameThat().isEqualTo("sqrt") + } + + @Test(expected = AssertionError::class) + fun testFunctionNameSubject_nameCheck_fails() { + val token = Token.FunctionName("sqrt", true, 10, 15) + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasNameThat().isEqualTo("sin") + } + + @Test + fun testFunctionNameSubject_allowedPropertyCheck_passes() { + val token = Token.FunctionName("sqrt", true, 10, 15) + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasIsAllowedPropertyThat().isTrue() + } + + @Test(expected = AssertionError::class) + fun testFunctionNameSubject_allowedPropertyCheck_fails() { + val token = Token.FunctionName("sqrt", false, 10, 15) + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasIsAllowedPropertyThat().isTrue() + } +} From 93c96c9c92b02e9a957fa7f7dcfe74acce393d5c Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Mon, 27 Jan 2025 02:05:36 +0530 Subject: [PATCH 2/8] Removed Todo --- .../src/main/java/org/oppia/android/testing/math/TokenSubject.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt index 737de61a7b9..8567ad32d25 100644 --- a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt +++ b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt @@ -26,7 +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. From 53d32a0878e4f0c74c41660d5422cbd1364d7ba4 Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Mon, 27 Jan 2025 02:15:24 +0530 Subject: [PATCH 3/8] check --- .../src/main/java/org/oppia/android/testing/math/TokenSubject.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt index 8567ad32d25..737de61a7b9 100644 --- a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt +++ b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt @@ -26,6 +26,7 @@ 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. From 302cc724d8886d745287d149b938640d34472da6 Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Mon, 27 Jan 2025 02:19:17 +0530 Subject: [PATCH 4/8] removed Todo --- .../main/java/org/oppia/android/testing/math/TokenSubject.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt index 737de61a7b9..49cce0f2030 100644 --- a/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt +++ b/testing/src/main/java/org/oppia/android/testing/math/TokenSubject.kt @@ -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. * From e78d25d50dd518a75bb2d6c85d36738eeb15f7fb Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Fri, 31 Jan 2025 12:51:54 +0530 Subject: [PATCH 5/8] renamed functions --- .../oppia/android/testing/math/BUILD.bazel | 2 - .../android/testing/math/TokenSubjectTest.kt | 118 ++++++++++-------- 2 files changed, 68 insertions(+), 52 deletions(-) diff --git a/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel b/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel index c6e97e829f0..648abb7e4ab 100644 --- a/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel +++ b/testing/src/test/java/org/oppia/android/testing/math/BUILD.bazel @@ -75,9 +75,7 @@ oppia_android_test( test_class = "org.oppia.android.testing.math.TokenSubjectTest", test_manifest = "//testing:test_manifest", deps = [ - "//model/src/main/proto:math_java_proto_lite", "//testing/src/main/java/org/oppia/android/testing/math:token_subject", - "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", "//third_party:com_google_truth_truth", "//third_party:junit_junit", "//third_party:robolectric_android-all", diff --git a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt index bba6865de4d..8c1074a2946 100644 --- a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt +++ b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt @@ -1,5 +1,6 @@ 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 @@ -10,66 +11,74 @@ import org.oppia.android.util.math.MathTokenizer.Companion.Token class TokenSubjectTest { @Test - fun testHasStartIndexThat_correctIndex_passes() { + fun testTokenSubject_hasStartIndexThat_correctIndex_passes() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(10) } - @Test(expected = AssertionError::class) - fun testHasStartIndexThat_incorrectIndex_fails() { + @Test + fun testTokenSubject_hasStartIndexThat_incorrectIndex_fails() { val token = Token.PositiveInteger(42, 10, 15) - TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(11) + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(11) + } } @Test - fun testHasEndIndexThat_correctIndex_passes() { + fun testTokenSubject_hasEndIndexThat_correctIndex_passes() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(15) } - @Test(expected = AssertionError::class) - fun testHasEndIndexThat_incorrectIndex_fails() { - val token = Token.PositiveInteger(10, 15, 42) - TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(14) + @Test + fun testTokenSubject_hasEndIndexThat_incorrectIndex_fails() { + val token = Token.PositiveInteger(42, 10, 15) + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(14) + } } @Test - fun testIsPositiveIntegerWhoseValue_correctValue_passes() { + fun testTokenSubject_isPositiveIntegerWhoseValue_correctValue_passes() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(42) } - @Test(expected = AssertionError::class) - fun testIsPositiveIntegerWhoseValue_incorrectType_fails() { - val token = Token.VariableName("x", 15, 10) - TokenSubject.assertThat(token).isPositiveIntegerWhoseValue() + @Test + fun testTokenSubject_isPositiveIntegerWhoseValue_incorrectType_fails() { + val token = Token.VariableName("x", 10, 15) + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).isPositiveIntegerWhoseValue() + } } @Test - fun testIsPositiveRealNumberWhoseValue_correctValue_passes() { - val token = Token.PositiveRealNumber(3.14, 15, 10) + fun testTokenSubject_isPositiveRealNumberWhoseValue_correctValue_passes() { + val token = Token.PositiveRealNumber(3.14, 10, 15) TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(3.14) } - fun testIisPositiveRealNumberWhoseValue_incorrectType_fails() { + fun testTokenSubject_isPositiveRealNumberWhoseValue_incorrectType_fails() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isNotEqualTo(25) } @Test - fun testIsVariableWhoseName_correctName_passes() { + fun testTokenSubject_isVariableWhoseName_correctName_passes() { val token = Token.VariableName("x", 10, 15) TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("x") } - @Test(expected = AssertionError::class) - fun testIsVariableWhoseName_incorrectType_fails() { + @Test + fun testTokenSubject_isVariableWhoseName_incorrectType_fails() { val token = Token.PositiveInteger(42, 10, 15) - TokenSubject.assertThat(token).isVariableWhoseName() + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).isVariableWhoseName() + } } @Test - fun testIsFunctionNameThat_correctNameAndAllowedStatus_passes() { + fun testTokenSubject_isFunctionNameThat_correctNameAndAllowedStatus_passes() { val token = Token.FunctionName("sqrt", true, 10, 15) TokenSubject.assertThat(token) .isFunctionNameThat() @@ -77,104 +86,113 @@ class TokenSubjectTest { } @Test - fun testSymbol_IsMinusSymbol() { + fun testTokenSubject_symbolIsMinusSymbol() { val token = Token.MinusSymbol(10, 11) TokenSubject.assertThat(token).isMinusSymbol() } @Test - fun testSymbol_IsSquareRootSymbol() { + fun testTokenSubject_symbolIsSquareRootSymbol() { val token = Token.SquareRootSymbol(10, 11) TokenSubject.assertThat(token).isSquareRootSymbol() } @Test - fun testSymbol_IsPlusSymbol() { + fun testTokenSubject_symbolIsPlusSymbol() { val token = Token.PlusSymbol(10, 11) TokenSubject.assertThat(token).isPlusSymbol() } @Test - fun testSymbol_IsMultiplySymbol() { + fun testTokenSubject_symbolIsMultiplySymbol() { val token = Token.MultiplySymbol(10, 11) TokenSubject.assertThat(token).isMultiplySymbol() } @Test - fun testSymbol_IsDivideSymbol() { + fun testTokenSubject_symbolIsDivideSymbol() { val token = Token.DivideSymbol(10, 11) TokenSubject.assertThat(token).isDivideSymbol() } @Test - fun testSymbol_IsExponentiationSymbol() { + fun testTokenSubject_symbolIsExponentiationSymbol() { val token = Token.ExponentiationSymbol(10, 11) TokenSubject.assertThat(token).isExponentiationSymbol() } @Test - fun testSymbol_IsEqualsSymbol() { + fun testTokenSubject_symbolIsEqualsSymbol() { val token = Token.EqualsSymbol(10, 11) TokenSubject.assertThat(token).isEqualsSymbol() } @Test - fun testSymbol_IsLeftParenthesisSymbol() { + fun testTokenSubject_symbolIsLeftParenthesisSymbol() { val token = Token.LeftParenthesisSymbol(10, 11) TokenSubject.assertThat(token).isLeftParenthesisSymbol() } @Test - fun testSymbol_IsRightParenthesisSymbol() { + fun testTokenSubject_symbolIsRightParenthesisSymbol() { val token = Token.RightParenthesisSymbol(10, 11) TokenSubject.assertThat(token).isRightParenthesisSymbol() } - @Test(expected = AssertionError::class) - fun testSymbolMethods_incorrectType_fails() { - TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isMinusSymbol() + @Test + fun testTokenSubject_symbolMethodsWithIncorrectType_fails() { + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isMinusSymbol() + } } @Test - fun testInvalidTokenMethods_correctTypes_pass() { + fun testTokenSubject_invalidTokenMethods_correctTypes_pass() { TokenSubject.assertThat(Token.InvalidToken(10, 11)).isInvalidToken() TokenSubject.assertThat(Token.IncompleteFunctionName(10, 11)).isIncompleteFunctionName() } - @Test(expected = AssertionError::class) - fun testInvalidTokenMethods_incorrectType_fails() { - TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isInvalidToken() + @Test + fun testTokenSubject_invalidTokenMethods_incorrectType_fails() { + val token = Token.PositiveInteger(10, 11, 42) + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).isInvalidToken() + } } @Test - fun testFunctionNameSubject_nameCheck_passes() { + fun testTokenSubject_functionNameSubject_nameCheck_passes() { val token = Token.FunctionName("sqrt", true, 10, 15) TokenSubject.assertThat(token) .isFunctionNameThat() .hasNameThat().isEqualTo("sqrt") } - @Test(expected = AssertionError::class) - fun testFunctionNameSubject_nameCheck_fails() { + @Test + fun testTokenSubject_functionNameSubject_nameCheck_fails() { val token = Token.FunctionName("sqrt", true, 10, 15) - TokenSubject.assertThat(token) - .isFunctionNameThat() - .hasNameThat().isEqualTo("sin") + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasNameThat().isEqualTo("sin") + } } @Test - fun testFunctionNameSubject_allowedPropertyCheck_passes() { + fun testTokenSubject_functionNameSubject_allowedPropertyCheck_passes() { val token = Token.FunctionName("sqrt", true, 10, 15) TokenSubject.assertThat(token) .isFunctionNameThat() .hasIsAllowedPropertyThat().isTrue() } - @Test(expected = AssertionError::class) - fun testFunctionNameSubject_allowedPropertyCheck_fails() { + @Test + fun testTokenSubject_functionNameSubject_allowedPropertyCheck_fails() { val token = Token.FunctionName("sqrt", false, 10, 15) - TokenSubject.assertThat(token) - .isFunctionNameThat() - .hasIsAllowedPropertyThat().isTrue() + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token) + .isFunctionNameThat() + .hasIsAllowedPropertyThat().isTrue() + } } } From 22a7ca511692758cd5b05345a29f32c4b5185c2d Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Fri, 31 Jan 2025 13:17:59 +0530 Subject: [PATCH 6/8] removed from test_file_exemptions.textproto --- scripts/assets/test_file_exemptions.textproto | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/assets/test_file_exemptions.textproto b/scripts/assets/test_file_exemptions.textproto index 0baccac8151..598edca0021 100644 --- a/scripts/assets/test_file_exemptions.textproto +++ b/scripts/assets/test_file_exemptions.textproto @@ -4126,10 +4126,6 @@ test_file_exemption { exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/RealSubject.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 From b5d09d8d95e2e184415af3aa89da9494b4d93ea3 Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Tue, 11 Feb 2025 16:57:07 +0530 Subject: [PATCH 7/8] some cleanup --- scripts/assets/test_file_exemptions.textproto | 4 -- .../android/testing/math/TokenSubjectTest.kt | 65 ++++++++++++------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/scripts/assets/test_file_exemptions.textproto b/scripts/assets/test_file_exemptions.textproto index d56f56c6e36..12362ec9dcb 100644 --- a/scripts/assets/test_file_exemptions.textproto +++ b/scripts/assets/test_file_exemptions.textproto @@ -4110,10 +4110,6 @@ test_file_exemption { exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/PolynomialSubject.kt" test_file_not_required: true } -test_file_exemption { - exempted_file_path: "testing/src/main/java/org/oppia/android/testing/math/RealSubject.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 diff --git a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt index 8c1074a2946..d1b128fbef3 100644 --- a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt +++ b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt @@ -11,13 +11,13 @@ import org.oppia.android.util.math.MathTokenizer.Companion.Token class TokenSubjectTest { @Test - fun testTokenSubject_hasStartIndexThat_correctIndex_passes() { + fun testTokenSubject_passesWithCorrectStartIndex() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(10) } @Test - fun testTokenSubject_hasStartIndexThat_incorrectIndex_fails() { + fun testTokenSubject_failsWithIncorrectStartIndex() { val token = Token.PositiveInteger(42, 10, 15) assertThrows(AssertionError::class.java) { TokenSubject.assertThat(token).hasStartIndexThat().isEqualTo(11) @@ -25,13 +25,13 @@ class TokenSubjectTest { } @Test - fun testTokenSubject_hasEndIndexThat_correctIndex_passes() { + fun testTokenSubject_passesWithCorrectEndIndex() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(15) } @Test - fun testTokenSubject_hasEndIndexThat_incorrectIndex_fails() { + fun testTokenSubject_failsWithIncorrectEndIndex() { val token = Token.PositiveInteger(42, 10, 15) assertThrows(AssertionError::class.java) { TokenSubject.assertThat(token).hasEndIndexThat().isEqualTo(14) @@ -39,52 +39,64 @@ class TokenSubjectTest { } @Test - fun testTokenSubject_isPositiveIntegerWhoseValue_correctValue_passes() { + fun testTokenSubject_passesWithCorrectPositiveIntegerValue() { val token = Token.PositiveInteger(42, 10, 15) TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(42) } @Test - fun testTokenSubject_isPositiveIntegerWhoseValue_incorrectType_fails() { - val token = Token.VariableName("x", 10, 15) + fun testTokenSubject_failsWithIncorrectPositiveIntegerValue() { + val token = Token.PositiveInteger(42, 10, 15) assertThrows(AssertionError::class.java) { - TokenSubject.assertThat(token).isPositiveIntegerWhoseValue() + TokenSubject.assertThat(token).isPositiveIntegerWhoseValue().isEqualTo(45) } } @Test - fun testTokenSubject_isPositiveRealNumberWhoseValue_correctValue_passes() { + fun testTokenSubject_passesWithCoreectPositiveRealNumberValue() { val token = Token.PositiveRealNumber(3.14, 10, 15) TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(3.14) } - fun testTokenSubject_isPositiveRealNumberWhoseValue_incorrectType_fails() { - val token = Token.PositiveInteger(42, 10, 15) - TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isNotEqualTo(25) + fun testTokenSubject_failsWithIncorrectPositiveRealNumberValue() { + val token = Token.PositiveRealNumber(3.14, 10, 15) + assertThrows(AssertionError::class.java) { + TokenSubject.assertThat(token).isPositiveRealNumberWhoseValue().isEqualTo(25) + } } @Test - fun testTokenSubject_isVariableWhoseName_correctName_passes() { + fun testTokenSubject_passesWithCorrectVariableName() { val token = Token.VariableName("x", 10, 15) TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("x") } @Test - fun testTokenSubject_isVariableWhoseName_incorrectType_fails() { - val token = Token.PositiveInteger(42, 10, 15) + fun testTokenSubject_failsWithIncorrectVariableWhoseName() { + val token = Token.VariableName("x", 10, 15) assertThrows(AssertionError::class.java) { - TokenSubject.assertThat(token).isVariableWhoseName() + TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("y") } } @Test - fun testTokenSubject_isFunctionNameThat_correctNameAndAllowedStatus_passes() { + 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) @@ -140,26 +152,33 @@ class TokenSubjectTest { } @Test - fun testTokenSubject_symbolMethodsWithIncorrectType_fails() { + fun testTokenSubject_failsWithIncorrectSymbol() { + val token = Token.RightParenthesisSymbol(10, 11) assertThrows(AssertionError::class.java) { - TokenSubject.assertThat(Token.PositiveInteger(10, 11, 42)).isMinusSymbol() + TokenSubject.assertThat(token).isMinusSymbol() } } @Test - fun testTokenSubject_invalidTokenMethods_correctTypes_pass() { - TokenSubject.assertThat(Token.InvalidToken(10, 11)).isInvalidToken() - TokenSubject.assertThat(Token.IncompleteFunctionName(10, 11)).isIncompleteFunctionName() + fun testTokenSubject_checkIsInvalidToken_passes() { + val token = Token.InvalidToken(10, 11) + TokenSubject.assertThat(token).isInvalidToken() } @Test - fun testTokenSubject_invalidTokenMethods_incorrectType_fails() { + 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) From a3115827e15e93d18271d32c99a3fece239ff3d0 Mon Sep 17 00:00:00 2001 From: theayushyadav11 Date: Tue, 11 Feb 2025 17:21:08 +0530 Subject: [PATCH 8/8] cleanup --- .../java/org/oppia/android/testing/math/TokenSubjectTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt index d1b128fbef3..a50967aa57d 100644 --- a/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt +++ b/testing/src/test/java/org/oppia/android/testing/math/TokenSubjectTest.kt @@ -72,7 +72,7 @@ class TokenSubjectTest { } @Test - fun testTokenSubject_failsWithIncorrectVariableWhoseName() { + fun testTokenSubject_isVariableWhoseName_incorrectName_fails() { val token = Token.VariableName("x", 10, 15) assertThrows(AssertionError::class.java) { TokenSubject.assertThat(token).isVariableWhoseName().isEqualTo("y")