From da6256c4a9a7c19a096e03a597793f807b885583 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 27 Aug 2020 00:43:14 +0530 Subject: [PATCH 1/4] check fork --- .../player/state/itemviewmodel/SelectionInteractionViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt index d5ec8c67620..1e83f8ac271 100644 --- a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt @@ -11,7 +11,7 @@ import org.oppia.app.player.state.answerhandling.InteractionAnswerErrorOrAvailab import org.oppia.app.player.state.answerhandling.InteractionAnswerHandler import org.oppia.app.player.state.answerhandling.InteractionAnswerReceiver import org.oppia.app.viewmodel.ObservableArrayList - +/**this is my change*/ /** Corresponds to the type of input that should be used for an item selection interaction view. */ enum class SelectionItemInputType { CHECKBOXES, From 398b582453e5ddd9d8cee2891273a6fb6ecb173f Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 27 Aug 2020 00:46:14 +0530 Subject: [PATCH 2/4] local develop branch synced with remote branch --- .../player/state/itemviewmodel/SelectionInteractionViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt index 1e83f8ac271..d5ec8c67620 100644 --- a/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt +++ b/app/src/main/java/org/oppia/app/player/state/itemviewmodel/SelectionInteractionViewModel.kt @@ -11,7 +11,7 @@ import org.oppia.app.player.state.answerhandling.InteractionAnswerErrorOrAvailab import org.oppia.app.player.state.answerhandling.InteractionAnswerHandler import org.oppia.app.player.state.answerhandling.InteractionAnswerReceiver import org.oppia.app.viewmodel.ObservableArrayList -/**this is my change*/ + /** Corresponds to the type of input that should be used for an item selection interaction view. */ enum class SelectionItemInputType { CHECKBOXES, From e3d3ced9456887e44eb5d82b643650dbf4e9edf4 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 3 Sep 2020 00:39:09 +0530 Subject: [PATCH 3/4] Added tests for NumericInputIsLessThanOrEqualToRuleClassifierProvider --- ...LessThanOrEqualToRuleClassifierProvider.kt | 1 - ...ThanOrEqualToRuleClassifierProviderTest.kt | 237 ++++++++++++++++++ 2 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt diff --git a/domain/src/main/java/org/oppia/domain/classify/rules/numericinput/NumericInputIsLessThanOrEqualToRuleClassifierProvider.kt b/domain/src/main/java/org/oppia/domain/classify/rules/numericinput/NumericInputIsLessThanOrEqualToRuleClassifierProvider.kt index dd7f27a1722..359dab7a32b 100644 --- a/domain/src/main/java/org/oppia/domain/classify/rules/numericinput/NumericInputIsLessThanOrEqualToRuleClassifierProvider.kt +++ b/domain/src/main/java/org/oppia/domain/classify/rules/numericinput/NumericInputIsLessThanOrEqualToRuleClassifierProvider.kt @@ -23,7 +23,6 @@ internal class NumericInputIsLessThanOrEqualToRuleClassifierProvider @Inject con ) } - // TODO(#210): Add tests for this classifier. override fun matches(answer: Double, input: Double): Boolean { return answer <= input } diff --git a/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt b/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt new file mode 100644 index 00000000000..66944ccc0d4 --- /dev/null +++ b/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt @@ -0,0 +1,237 @@ +package org.oppia.domain.classify.rules + +import android.app.Application +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.google.common.truth.Truth.assertThat +import dagger.BindsInstance +import dagger.Component +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.oppia.app.model.InteractionObject +import org.oppia.domain.classify.rules.numericinput.NumericInputIsLessThanOrEqualToRuleClassifierProvider +import org.robolectric.annotation.Config +import org.robolectric.annotation.LooperMode +import javax.inject.Inject +import javax.inject.Singleton +import kotlin.reflect.KClass +import kotlin.reflect.full.cast +import kotlin.test.fail + +/** Tests for [NumericInputIsLessThanOrEqualToRuleClassifierProvider]. */ +@RunWith(AndroidJUnit4::class) +@LooperMode(LooperMode.Mode.PAUSED) +@Config(manifest = Config.NONE) +class NumericInputIsLessThanOrEqualToRuleClassifierProviderTest { + + private val POSITIVE_REAL_VALUE_1_5 = createReal(value = 1.5) + private val POSITIVE_REAL_VALUE_3_5 = createReal(value = 3.5) + private val NEGATIVE_REAL_VALUE_1_5 = createReal(value = -1.5) + private val NEGATIVE_REAL_VALUE_3_5 = createReal(value = -3.5) + private val STRING_VALUE = createString(value = "test") + private val POSITIVE_INT_VALUE_3 = createInt(value = 3) + private val POSITIVE_INT_VALUE_1 = createInt(value = 1) + private val NEGATIVE_INT_VALUE_1 = createInt(value = -1) + private val NEGATIVE_INT_VALUE_3 = createInt(value = -3) + + @Inject + internal lateinit var numericInputIsLessThanOrEqualToRuleClassifierProvider: + NumericInputIsLessThanOrEqualToRuleClassifierProvider + + private val inputIsLessThanOrEqualToRuleClassifier by lazy { + numericInputIsLessThanOrEqualToRuleClassifierProvider.createRuleClassifier() + } + + @Before + fun setUp() { + setUpTestApplicationComponent() + } + + @Test + fun testPositiveRealAnswer_positiveRealInput_sameExactValues_answerLesserOrEqual() { + val inputs = mapOf("x" to POSITIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_1_5, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testNegativeRealAnswer_negativeRealInput_sameExactValues_answerLesserOrEqual() { + val inputs = mapOf("x" to NEGATIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = NEGATIVE_REAL_VALUE_1_5, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testPositiveRealAnswer_positiveRealInput_answerValueLesser_answerLesserOrEqual() { + val inputs = mapOf("x" to POSITIVE_REAL_VALUE_3_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_1_5, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testPositiveRealAnswer_positiveRealInput_answerValueGreater_answerNotLesserOrEqual() { + val inputs = mapOf("x" to POSITIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_3_5, inputs = inputs) + + assertThat(matches).isFalse() + } + + @Test + fun testNegativeRealAnswer_negativeRealInput_answerValueLesser_answerLesserOrEqual() { + val inputs = mapOf("x" to NEGATIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = NEGATIVE_REAL_VALUE_3_5, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testNegativeRealAnswer_negativeRealInput_answerValueGreater_answerNotLesserOrEqual() { + val inputs = mapOf("x" to NEGATIVE_REAL_VALUE_3_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = NEGATIVE_REAL_VALUE_1_5, inputs = inputs) + + assertThat(matches).isFalse() + } + + @Test + fun testNegativeRealAnswer_positiveRealInput_answerValueLesser_answerLesserOrEqual() { + val inputs = mapOf("x" to POSITIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = NEGATIVE_REAL_VALUE_3_5, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testPositiveRealAnswer_negativeRealInput_answerValueGreater_answerNotLesserOrEqual() { + val inputs = mapOf("x" to NEGATIVE_REAL_VALUE_1_5) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_1_5, inputs = inputs) + + assertThat(matches).isFalse() + } + + @Test + fun testPositiveIntAnswer_negativeIntInput_answerValueGreater_answerNotLesserOrEqual() { + val inputs = mapOf("x" to NEGATIVE_INT_VALUE_3) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_INT_VALUE_1, inputs = inputs) + + assertThat(matches).isFalse() + } + + @Test + fun testNegativeIntAnswer_positiveIntInput_answerValueLesser_answerLesserOrEqual() { + val inputs = mapOf("x" to POSITIVE_INT_VALUE_3) + + val matches = + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = NEGATIVE_INT_VALUE_1, inputs = inputs) + + assertThat(matches).isTrue() + } + + @Test + fun testRealAnswer_missingInput_throwsException() { + val inputs = mapOf("y" to POSITIVE_REAL_VALUE_1_5) + + val exception = assertThrows(IllegalStateException::class) { + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_1_5, inputs = inputs) + } + + assertThat(exception) + .hasMessageThat() + .contains("Expected classifier inputs to contain parameter with name 'x'") + } + + @Test + fun testRealAnswer_stringInput_throwsException() { + val inputs = mapOf("x" to STRING_VALUE) + + val exception = assertThrows(IllegalStateException::class) { + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_REAL_VALUE_1_5, inputs = inputs) + } + + assertThat(exception) + .hasMessageThat() + .contains("Expected input value to be of type REAL not NORMALIZED_STRING") + } + + private fun createReal(value: Double): InteractionObject { + return InteractionObject.newBuilder().setReal(value).build() + } + + private fun createString(value: String): InteractionObject { + return InteractionObject.newBuilder().setNormalizedString(value).build() + } + + private fun createInt(value: Int): InteractionObject { + return InteractionObject.newBuilder().setReal(value.toDouble()).build() + } + + private fun setUpTestApplicationComponent() { + DaggerNumericInputIsLessThanOrEqualToRuleClassifierProviderTest_TestApplicationComponent + .builder() + .setApplication(ApplicationProvider.getApplicationContext()) + .build() + .inject(this) + } + + // TODO(#89): Move to a common test library. + private fun assertThrows(type: KClass, 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 + } + } + + // TODO(#89): Move this to a common test application component. + @Singleton + @Component(modules = []) + interface TestApplicationComponent { + @Component.Builder + interface Builder { + @BindsInstance + fun setApplication(application: Application): Builder + + fun build(): TestApplicationComponent + } + + fun inject(test: NumericInputIsLessThanOrEqualToRuleClassifierProviderTest) + } +} From f77983f3a7fd1c9d9db6e66df21d9d09537a1c97 Mon Sep 17 00:00:00 2001 From: prayutsu Date: Thu, 3 Sep 2020 10:55:43 +0530 Subject: [PATCH 4/4] Added more tests for Integers --- ...ThanOrEqualToRuleClassifierProviderTest.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt b/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt index 66944ccc0d4..7477cdccccf 100644 --- a/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt +++ b/domain/src/test/java/org/oppia/domain/classify/rules/NumericInputIsLessThanOrEqualToRuleClassifierProviderTest.kt @@ -186,6 +186,34 @@ class NumericInputIsLessThanOrEqualToRuleClassifierProviderTest { .contains("Expected input value to be of type REAL not NORMALIZED_STRING") } + @Test + fun testIntAnswer_missingInput_throwsException() { + val inputs = mapOf("y" to POSITIVE_INT_VALUE_1) + + val exception = assertThrows(IllegalStateException::class) { + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_INT_VALUE_1, inputs = inputs) + } + + assertThat(exception) + .hasMessageThat() + .contains("Expected classifier inputs to contain parameter with name 'x'") + } + + @Test + fun testIntAnswer_stringInput_throwsException() { + val inputs = mapOf("x" to STRING_VALUE) + + val exception = assertThrows(IllegalStateException::class) { + inputIsLessThanOrEqualToRuleClassifier + .matches(answer = POSITIVE_INT_VALUE_1, inputs = inputs) + } + + assertThat(exception) + .hasMessageThat() + .contains("Expected input value to be of type REAL not NORMALIZED_STRING") + } + private fun createReal(value: Double): InteractionObject { return InteractionObject.newBuilder().setReal(value).build() }