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

Fixes #1896: Thoroughly test ItemSelectionInputContainsAtLeastOneOfRuleClassifier #2073

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package org.oppia.android.domain.classify.rules.itemselectioninput

import org.oppia.android.app.model.InteractionObject
navneetsaluja marked this conversation as resolved.
Show resolved Hide resolved
import org.oppia.android.app.model.StringList
import javax.inject.Inject
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.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Singleton

/** Tests for [ItemSelectionInputContainsAtLeastOneOfRuleClassifierProvider]. */
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(manifest = Config.NONE)

anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
class ItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest {
private val ITEM_SELECTION_SET_2_LOWERCASE = createStringList(StringList.newBuilder().addHtml("test1").addHtml("test2").build())
private val ITEM_SELECTION_SET_2_UPPERCASE = createStringList(StringList.newBuilder().addHtml("TEST1").addHtml("TEST2").build())
navneetsaluja marked this conversation as resolved.
Show resolved Hide resolved

navneetsaluja marked this conversation as resolved.
Show resolved Hide resolved
@Inject
internal lateinit var itemSelectionInputContainsAtLeastOneOfRuleClassifierProvider:
ItemSelectionInputContainsAtLeastOneOfRuleClassifierProvider

private val inputContainsAtLeastOneOfRuleClassifier by lazy {
itemSelectionInputContainsAtLeastOneOfRuleClassifierProvider.createRuleClassifier()
}

@Before
fun setUp() {
setUpTestApplicationComponent()
}

navneetsaluja marked this conversation as resolved.
Show resolved Hide resolved
@Test
fun testEquals_lowerCaseAnswer_lowerCaseInput_bothValuesMatch() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_2_LOWERCASE)

val matches = inputContainsAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_2_LOWERCASE,
inputs = inputs
)

assertThat(matches).isTrue()
}

@Test
fun testEquals_lowerCaseAnswer_upperCaseInput_bothValuesDoNotMatch() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_2_UPPERCASE)

val matches = inputContainsAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_2_LOWERCASE,
inputs = inputs
)

assertThat(matches).isFalse()
}

@Test
fun testEquals_upperCaseAnswer_upperCaseInput_bothValuesMatch() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_2_UPPERCASE)

val matches = inputContainsAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_2_UPPERCASE,
inputs = inputs
)

assertThat(matches).isTrue()
}

@Test
fun testEquals_upperCaseAnswer_lowerCaseInput_bothValuesDoNotMatch() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_2_LOWERCASE)

val matches = inputContainsAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_2_UPPERCASE,
inputs = inputs
)

assertThat(matches).isFalse()
}

private fun createStringList(value: StringList): InteractionObject {
return InteractionObject.newBuilder().setSetOfHtmlString(value).build()
}

private fun setUpTestApplicationComponent() {
DaggerItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest_TestApplicationComponent.builder()
navneetsaluja marked this conversation as resolved.
Show resolved Hide resolved
.setApplication(ApplicationProvider.getApplicationContext())
.build()
.inject(this)
}

@Singleton
@Component(modules = [])
interface TestApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun setApplication(application: Application): Builder

fun build(): TestApplicationComponent
}

fun inject(test: ItemSelectionInputContainsAtLeastOneOfRuleClassifierProviderTest)
}
}