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 #1897: Add tests for ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProvider #2238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions domain/BUILD.bazel
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ domain_test(
deps = TEST_DEPS,
)

domain_test(
name = "ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest",
srcs = [
"src/test/java/org/oppia/android/domain/classify/rules/textinput/ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest.kt",
],
test_class = "org.oppia.android.domain.classify.rules.textinput.ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest",
deps = TEST_DEPS,
)

domain_test(
name = "TextInputEqualsRuleClassifierProviderTest",
srcs = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProvide
)
}

// TODO(#210): Add tests for this classifier.
override fun matches(answer: StringList, input: StringList): Boolean {
return answer.htmlList.toSet().intersect(input.htmlList).isEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package org.oppia.android.domain.classify.rules.itemselectioninput

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.android.domain.classify.InteractionObjectTestBuilder
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProvider]. */
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(manifest = Config.NONE)
class ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest {
fsharpasharp marked this conversation as resolved.
Show resolved Hide resolved

private val ITEM_SELECTION_SET_5 =
fsharpasharp marked this conversation as resolved.
Show resolved Hide resolved
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test1", "test2", "test3", "test4", "test5")
)

private val ITEM_SELECTION_SET_SUBSET =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test1")
)

private val ITEM_SELECTION_SET_ONE_ELEMENT_PRESENT =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test1", "test6")
)

private val ITEM_SELECTION_SET_TWO_ELEMENTS_PRESENT_NO_EXTRA_ELEMENT =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test1", "test2")
)

private val ITEM_SELECTION_SET_TWO_ELEMENTS_PRESENT_WITH_EXTRA_ELEMENT =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test1", "test2", "test6")
)

private val ITEM_SELECTION_SET_EMPTY =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList()
)

private val ITEM_SELECTION_SET_EXCLUSIVE =
InteractionObjectTestBuilder.createHtmlStringListInteractionObject(
InteractionObjectTestBuilder
.createHtmlStringList("test6")
)

@Inject
internal lateinit var itemSelectionInputDesNotContainAtLeastOneOfRuleClassifierProvider:
ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProvider

private val inputDoesNotContainAtLeastOneOfRuleClassifier by lazy {
itemSelectionInputDesNotContainAtLeastOneOfRuleClassifierProvider.createRuleClassifier()
}

@Before
fun setUp() {
setUpTestApplicationComponent()
}

@Test
fun testItemSet_setAnswer_inputIsASubset_answerContainsInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_SUBSET)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isFalse()
}

@Test
fun testItemSet_setAnswer_inputHasOneElementInSet_answerContainsInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_ONE_ELEMENT_PRESENT)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isFalse()
}

@Test
fun testItemSet_setAnswer_inputHasTwoElementsInSetNoneExtra_answerContainsInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_TWO_ELEMENTS_PRESENT_NO_EXTRA_ELEMENT)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isFalse()
}

@Test
fun testItemSet_setAnswer_inputHasTwoElementsInSetOneExtra_answerContainsInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_TWO_ELEMENTS_PRESENT_WITH_EXTRA_ELEMENT)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isFalse()
}

@Test
fun testItemSet_setAnswer_inputIsEmptySet_answerDoesNotContainInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_EMPTY)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isTrue()
}

@Test
fun testItemSet_setAnswer_inputIsExclusiveOfSet_answerDoesNotContainInput() {
val inputs = mapOf("x" to ITEM_SELECTION_SET_EXCLUSIVE)

val matches = inputDoesNotContainAtLeastOneOfRuleClassifier.matches(
answer = ITEM_SELECTION_SET_5,
inputs = inputs
)

assertThat(matches).isTrue()
}

private fun setUpTestApplicationComponent() {
DaggerItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest_TestApplicationComponent // ktlint-disable max-line-length
.builder()
.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: ItemSelectionInputDoesNotContainAtLeastOneOfRuleClassifierProviderTest)
}
}