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 #3857: Add support for HasSpecificTermEqualTo #3859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
919ab2b
Add support for AABs, build flavors, and proguard.
BenHenning Sep 1, 2021
c31b07b
Merge branch 'develop' into add-bundles-proguard-build-flavors
BenHenning Sep 1, 2021
ceb1179
Lint & codeowner fixes.
BenHenning Sep 1, 2021
cbe5e76
Fix failures.
BenHenning Sep 1, 2021
d7945d5
Different attempt to fix bad develop reference in CI.
BenHenning Sep 1, 2021
366ab4d
Initial commit.
BenHenning Sep 1, 2021
c38b95c
Merge branch 'develop' into introduce-test-batching
BenHenning Sep 1, 2021
ac73dd6
Introduce infrastructure for batching.
BenHenning Sep 2, 2021
3aec233
Add bucketing strategy.
BenHenning Sep 2, 2021
650570b
Fix caching & stabilize builds.
BenHenning Sep 2, 2021
d66bb2c
Increase sharding & add randomization.
BenHenning Sep 2, 2021
3969a6d
Improving partitionin & readability.
BenHenning Sep 2, 2021
e7b2a0d
Add new tests & fix static analysis errors.
BenHenning Sep 2, 2021
d1da067
Fix script.
BenHenning Sep 2, 2021
fbb3838
Fix broken tests & test configuration.
BenHenning Sep 2, 2021
e9cb61b
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
601ff0a
Merge branch 'add-bundles-proguard-build-flavors' of github.com:oppia…
BenHenning Sep 2, 2021
6c91da9
Fix mistake from earlier commit.
BenHenning Sep 2, 2021
e3eb6f2
Try 10 max parallel actions instead.
BenHenning Sep 2, 2021
3ff775f
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
62576a1
Fix another error from an earlier commit.
BenHenning Sep 2, 2021
d4f4448
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 2, 2021
0644f70
Localisation updates from https://translatewiki.net.
translatewiki Sep 2, 2021
f2a412d
Fix mv command so it works on Linux & OSX.
BenHenning Sep 2, 2021
aa29739
Merge branch 'translatewiki-prs' into temp-branch-combine-prework-and…
BenHenning Sep 2, 2021
c8248ca
Introduce initial domain layer for translations.
BenHenning Sep 4, 2021
512f0b3
Initial app layer implementation for translations.
BenHenning Sep 8, 2021
6b8298d
Domain changes needed per downstream UI changes.
BenHenning Sep 8, 2021
2aa4470
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 8, 2021
014ac54
Add patterns & fixes.
BenHenning Sep 10, 2021
583a05c
Add needed domain changes for downstream branch.
BenHenning Sep 10, 2021
ceb66d9
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 10, 2021
b4915d1
Merge commit '0c98a6cc1688c3a96bed67246ebd429e79077479' into introduc…
BenHenning Sep 10, 2021
385ad6a
Merge branch 'introduce-test-batching' into add-bundles-proguard-buil…
BenHenning Sep 10, 2021
7160477
Merge branch 'develop' into add-bundles-proguard-build-flavors
BenHenning Sep 10, 2021
7b4b282
Introduce support for content localization.
BenHenning Sep 14, 2021
2f7dc24
Fix structures to work with parsing assumptions.
BenHenning Sep 14, 2021
3f92b84
Fix regex checks for translated strings.
BenHenning Sep 14, 2021
96f31ed
Merge branch 'develop' into fix-regex-checks-for-translated-strings
BenHenning Sep 14, 2021
99130f0
Lint-ish fix.
BenHenning Sep 14, 2021
b48cca6
Merge commit '92ce46b81b2183283e04c4d592fc8682338e1404' into add-bund…
BenHenning Sep 14, 2021
3fcc1e5
Merge branch 'add-bundles-proguard-build-flavors' into temp-branch-co…
BenHenning Sep 14, 2021
060c37e
Merge branch 'fix-regex-checks-for-translated-strings' into temp-bran…
BenHenning Sep 14, 2021
6d556fb
Fix failing regex checks.
BenHenning Sep 14, 2021
abb2164
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 14, 2021
4a266ba
Add check for nested res subdirectories.
BenHenning Sep 14, 2021
2ef0ea7
Add remaining regex patterns & fixes.
BenHenning Sep 15, 2021
3746880
Clean up locale infra.
BenHenning Sep 15, 2021
cb80423
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 15, 2021
fafe5c3
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 15, 2021
68f6c1d
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 15, 2021
1021a89
Merge commit '2d47a87b9020b95355e86e96254b1ad68f3843b2' into fix-rege…
BenHenning Sep 15, 2021
e58e422
Merge branch 'fix-regex-checks-for-translated-strings' into temp-bran…
BenHenning Sep 15, 2021
2ad1f41
Attempt to delete strings to force history.
BenHenning Sep 15, 2021
c0f8b45
Merge branch 'develop' into temp-branch-combine-prework-and-translations
BenHenning Sep 15, 2021
87f84a8
Merge branch 'temp-branch-combine-prework-and-translations' into loca…
BenHenning Sep 15, 2021
ebe2262
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 15, 2021
d863e20
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 15, 2021
b266b0c
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 15, 2021
b168091
Gate options behind compile-time flag.
BenHenning Sep 15, 2021
b1de8ed
Proguard fixes for Glide.
BenHenning Sep 15, 2021
f059838
Make AAB builds/runs manual-only targets.
BenHenning Sep 15, 2021
85e7574
Fix broken tests.
BenHenning Sep 15, 2021
7a9d952
Fix lint issues & add KDocs.
BenHenning Sep 16, 2021
4348fb1
Add 6/11 test suites (& placeholders for other 4).
BenHenning Sep 17, 2021
e8afb60
Add more test suites for domain layers.
BenHenning Sep 18, 2021
08a8219
Introduce wrapper & fake for bidi wrapping.
BenHenning Sep 20, 2021
0112762
Add remaining tests.
BenHenning Sep 20, 2021
2015e8e
Fix Gradle builds.
BenHenning Sep 21, 2021
2acb592
Lint fixes.
BenHenning Sep 21, 2021
0238557
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 21, 2021
826545a
Resolve remaining incomplete TODOs.
BenHenning Sep 21, 2021
703f770
Add new codeowners.
BenHenning Sep 21, 2021
2cc7c07
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 21, 2021
db3a3a8
Post-merge fixes.
BenHenning Sep 21, 2021
d667639
Fix most test targets (builds).
BenHenning Sep 21, 2021
267c6d6
Fix all remaining test builds.
BenHenning Sep 22, 2021
670c5e8
Fix all app layer tests.
BenHenning Sep 22, 2021
cccd1b4
Fix questions & profile issues.
BenHenning Sep 22, 2021
ee88628
Type specifier pattern & fixes.
BenHenning Sep 22, 2021
07b7823
Add missing KDocs.
BenHenning Sep 23, 2021
8ad41f3
Boilerplate & TODOs for needed tests.
BenHenning Sep 23, 2021
f876784
Add new needed test dep.
BenHenning Sep 23, 2021
180bd52
Add needed testing coverage.
BenHenning Sep 24, 2021
e879c04
Two fixes.
BenHenning Sep 24, 2021
326d5d9
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 24, 2021
86a50b7
Fix Gradle builds on branch.
BenHenning Sep 25, 2021
afb80e5
Resolve nearly all pending TODOs.
BenHenning Sep 25, 2021
970d561
Lint fixes.
BenHenning Sep 25, 2021
271fbd9
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 25, 2021
f17f479
Re-add method removed from merge.
BenHenning Sep 25, 2021
3b65ce3
Lint fixes.
BenHenning Sep 25, 2021
20e0d5e
Fix compute affected tests script.
BenHenning Sep 25, 2021
b7f63c3
Fix failures found on CI.
BenHenning Sep 26, 2021
3a85c49
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 26, 2021
0fa47f7
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 26, 2021
d37cdd2
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 26, 2021
74593a8
Fix remaining Gradle failures found in CI.
BenHenning Sep 26, 2021
5c37975
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 26, 2021
d7e39f9
Fix existing domain + app layer tests.
BenHenning Sep 27, 2021
51fb398
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 27, 2021
e66c24d
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 27, 2021
ce9446f
Post-merge fix.
BenHenning Sep 27, 2021
3de427e
Gradle Espresso test fix.
BenHenning Sep 27, 2021
d7cf31a
Merge branch 'develop' into localization-part4-introduce-controller-a…
BenHenning Sep 27, 2021
37e852f
Merge branch 'localization-part4-introduce-controller-and-protos' int…
BenHenning Sep 27, 2021
dd11beb
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 27, 2021
c84b19e
Add missing KDocs, remove extra file, and other cleanups.
BenHenning Sep 27, 2021
a3c167b
Lint fixes.
BenHenning Sep 27, 2021
6c97de0
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 27, 2021
f240bf6
Fix CI & lint checks (except regex).
BenHenning Sep 27, 2021
eec5a9f
Deflake DataProviderTestMonitorTest.
BenHenning Sep 27, 2021
44f47b6
Address reviewer comments.
BenHenning Sep 27, 2021
085fa41
Merge branch 'develop' into localization-part5-introduce-app-string-t…
BenHenning Sep 27, 2021
2377ee5
Lint fixes.
BenHenning Sep 27, 2021
ec58dce
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 27, 2021
5a89f05
Fix affected tests from earlier changes.
BenHenning Sep 27, 2021
6748464
Fix remaining Gradle failures.
BenHenning Sep 28, 2021
700dfb1
Add placeholders for new needed tests.
BenHenning Sep 28, 2021
a1b0fb0
Fix broken tests.
BenHenning Sep 28, 2021
cb8b797
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 28, 2021
1e7c3c9
Add needed tests for new behaviors.
BenHenning Sep 29, 2021
b21525a
Fix Gradle build & mechanism change failures.
BenHenning Sep 29, 2021
171a1b8
Lint fixes.
BenHenning Sep 29, 2021
13ad6d5
Merge commit '3a0afb4eb8222d4ff3acd2e2e660b85911d35229' into localiza…
BenHenning Sep 29, 2021
0459300
Merge branch 'localization-part5-introduce-app-string-translations-su…
BenHenning Sep 29, 2021
c97b61a
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Sep 29, 2021
4a3d53b
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 29, 2021
7af6cc1
Undo inadvertent change to Gradle jvmargs.
BenHenning Sep 29, 2021
d108d95
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 29, 2021
e20b742
Disable most tests on Espresso.
BenHenning Sep 29, 2021
8448350
Test fixes + make monitor Espresso-compatible.
BenHenning Sep 30, 2021
cd73e07
Fix broken tests.
BenHenning Sep 30, 2021
261adbb
Add exemptions & regex check tests.
BenHenning Sep 30, 2021
6d07512
Lint fixes.
BenHenning Sep 30, 2021
48ef103
Lint fixes.
BenHenning Sep 30, 2021
00bc30c
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Sep 30, 2021
11bb929
Add new ratio input rule classifier.
BenHenning Sep 30, 2021
d99392c
Fix broken tests (per CI).
BenHenning Sep 30, 2021
69ff8e8
Merge branch 'localization-part7-add-gate-for-selecting-written-langu…
BenHenning Sep 30, 2021
612e17d
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Oct 6, 2021
93e68ac
Merge branch 'develop' into localization-part6-introduce-content-and-…
BenHenning Oct 6, 2021
81ec28f
Merge branch 'localization-part6-introduce-content-and-answer-transla…
BenHenning Oct 6, 2021
9373da8
Merge branch 'develop' into localization-part7-add-gate-for-selecting…
BenHenning Oct 6, 2021
e405132
Merge branch 'localization-part7-add-gate-for-selecting-written-langu…
BenHenning Oct 6, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.oppia.android.domain.classify.rules.ratioinput

import org.oppia.android.app.model.InteractionObject
import org.oppia.android.app.model.RatioExpression
import org.oppia.android.app.model.WrittenTranslationContext
import org.oppia.android.domain.classify.RuleClassifier
import org.oppia.android.domain.classify.rules.GenericRuleClassifier
import org.oppia.android.domain.classify.rules.RuleClassifierProvider
import javax.inject.Inject

/**
* Provider for a classifier that determines whether a particular component within an answer ratio
* has a specific value.
*/
// TODO(#1580): Re-restrict access using Bazel visibilities
class RatioInputHasSpecificTermEqualToRuleClassifierProvider @Inject constructor(
private val classifierFactory: GenericRuleClassifier.Factory
) : RuleClassifierProvider,
GenericRuleClassifier.MultiTypeDoubleInputMatcher<RatioExpression, Int, Int> {

override fun createRuleClassifier(): RuleClassifier {
return classifierFactory.createDoubleInputClassifier(
expectedAnswerObjectType = InteractionObject.ObjectTypeCase.RATIO_EXPRESSION,
expectedObjectType1 = InteractionObject.ObjectTypeCase.NON_NEGATIVE_INT,
firstInputParameterName = "x",
expectedObjectType2 = InteractionObject.ObjectTypeCase.NON_NEGATIVE_INT,
secondInputParameterName = "y",
matcher = this
)
}

override fun matches(
answer: RatioExpression,
firstInput: Int,
secondInput: Int,
writtenTranslationContext: WrittenTranslationContext
): Boolean = answer.ratioComponentList.getOrNull(firstInput - 1) == secondInput
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@ class RatioInputModule {

@Provides
@IntoMap
@StringKey("IsEquivalent")
@StringKey("HasNumberOfTermsEqualTo")
@RatioExpressionInputRules
internal fun provideRatioInputIsEquivalentRuleClassifier(
classifierProvider: RatioInputIsEquivalentRuleClassifierProvider
internal fun provideRatioInputHasNumberOfTermsEqualToRuleClassifier(
classifierProvider: RatioInputHasNumberOfTermsEqualToClassifierProvider
): RuleClassifier = classifierProvider.createRuleClassifier()

@Provides
@IntoMap
@StringKey("HasNumberOfTermsEqualTo")
@StringKey("HasSpecificTermEqualTo")
@RatioExpressionInputRules
internal fun provideRatioInputHasNumberOfTermsEqualToRuleClassifier(
classifierProvider: RatioInputHasNumberOfTermsEqualToClassifierProvider
internal fun provideRatioInputHasSpecificTermEqualToRuleClassifierProvider(
classifierProvider: RatioInputHasSpecificTermEqualToRuleClassifierProvider
): RuleClassifier = classifierProvider.createRuleClassifier()

@Provides
@IntoMap
@StringKey("IsEquivalent")
@RatioExpressionInputRules
internal fun provideRatioInputIsEquivalentRuleClassifier(
classifierProvider: RatioInputIsEquivalentRuleClassifierProvider
): RuleClassifier = classifierProvider.createRuleClassifier()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
package org.oppia.android.domain.classify.rules.ratioinput

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.app.model.WrittenTranslationContext
import org.oppia.android.domain.classify.InteractionObjectTestBuilder
import org.oppia.android.domain.classify.RuleClassifier
import org.oppia.android.testing.assertThrows
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

/** Tests for [RatioInputHasSpecificTermEqualToRuleClassifierProvider]. */
// FunctionName: test names are conventionally named with underscores.
@Suppress("FunctionName")
@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
@Config(manifest = Config.NONE)
class RatioInputHasSpecificTermEqualToRuleClassifierProviderTest {
@Inject
internal lateinit var ratioInputHasSpecificTermEqualToRuleClassifierProvider:
RatioInputHasSpecificTermEqualToRuleClassifierProvider

private val hasSpecificTermEqualToClassifierProvider: RuleClassifier by lazy {
ratioInputHasSpecificTermEqualToRuleClassifierProvider.createRuleClassifier()
}

@Before
fun setUp() {
setUpTestApplicationComponent()
}

@Test
fun testAnswer_oneTerm_expectFirstIndex_matchingValue_matchesCorrectly() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_1, "y" to NON_NEGATIVE_VALUE_TEST_3)

// Note that the test for a single-value ratio is just for robustness since the classifier
// technically allows this even though the data definition specifies that it should never
// happen.
val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

assertThat(matches).isTrue()
}

@Test
fun testAnswer_oneTerm_expectFirstIndex_unmatchingValue_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_1, "y" to NON_NEGATIVE_VALUE_TEST_2)

// Note that the test for a single-value ratio is just for robustness since the classifier
// technically allows this even though the data definition specifies that it should never
// happen.
val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// The ratio has value 3, but the value 2 was expected.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_oneTerm_expectSecondIndex_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_2, "y" to NON_NEGATIVE_VALUE_TEST_2)

// Note that the test for a single-value ratio is just for robustness since the classifier
// technically allows this even though the data definition specifies that it should never
// happen.
val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// A value was expected at index 2, but the ratio doesn't have that.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_twoTerms_expectFirstIndex_matchingValue_matchesCorrectly() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_1, "y" to NON_NEGATIVE_VALUE_TEST_3)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3_2,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

assertThat(matches).isTrue()
}

@Test
fun testAnswer_twoTerms_expectFirstIndex_unmatchingValue_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_1, "y" to NON_NEGATIVE_VALUE_TEST_2)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3_2,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// The ratio has value 3 at index 1, but the value 2 was expected.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_twoTerms_expectSecondIndex_matchingValue_matchesCorrectly() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_2, "y" to NON_NEGATIVE_VALUE_TEST_2)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3_2,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

assertThat(matches).isTrue()
}

@Test
fun testAnswer_twoTerms_expectSecondIndex_unmatchingValue_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_2, "y" to NON_NEGATIVE_VALUE_TEST_3)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3_2,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// The ratio has value 2 at index 2, but the value 3 was expected.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_twoTerms_expectThirdIndex_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_3, "y" to NON_NEGATIVE_VALUE_TEST_3)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_3_2,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// A value was expected at index 3, but the ratio doesn't have that.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_threeTerms_expectZeroIndex_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_0, "y" to NON_NEGATIVE_VALUE_TEST_1)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// A value was expected at index 0, but the ratio doesn't have that.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_threeTerms_expectFourthIndex_doesNotMatch() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_4, "y" to NON_NEGATIVE_VALUE_TEST_3)

val matches =
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)

// A value was expected at index 4, but the ratio doesn't have that.
assertThat(matches).isFalse()
}

@Test
fun testAnswer_threeTerms_indexInputWithIncorrectType_throwsException() {
val inputs = mapOf("x" to STRING_VALUE, "y" to NON_NEGATIVE_VALUE_TEST_3)

val exception = assertThrows(IllegalStateException::class) {
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)
}

assertThat(exception)
.hasMessageThat()
.contains("Expected input value to be of type NON_NEGATIVE_INT not NORMALIZED_STRING")
}

@Test
fun testAnswer_threeTerms_valueInputWithIncorrectType_throwsException() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_4, "y" to STRING_VALUE)

val exception = assertThrows(IllegalStateException::class) {
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)
}

assertThat(exception)
.hasMessageThat()
.contains("Expected input value to be of type NON_NEGATIVE_INT not NORMALIZED_STRING")
}

@Test
fun testAnswer_threeTerms_missingIndexInput_throwsException() {
val inputs = mapOf("y" to NON_NEGATIVE_VALUE_TEST_3)

val exception = assertThrows(IllegalStateException::class) {
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)
}

assertThat(exception)
.hasMessageThat()
.contains("Expected classifier inputs to contain parameter with name 'x' but had: [y]")
}

@Test
fun testAnswer_threeTerms_missingValueInput_throwsException() {
val inputs = mapOf("x" to NON_NEGATIVE_VALUE_TEST_4)

val exception = assertThrows(IllegalStateException::class) {
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = inputs,
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)
}

assertThat(exception)
.hasMessageThat()
.contains("Expected classifier inputs to contain parameter with name 'y' but had: [x]")
}

@Test
fun testAnswer_threeTerms_missingBothInputs_throwsException() {
val exception = assertThrows(IllegalStateException::class) {
hasSpecificTermEqualToClassifierProvider.matches(
answer = RATIO_VALUE_TEST_1_2_3,
inputs = mapOf(),
writtenTranslationContext = WrittenTranslationContext.getDefaultInstance()
)
}

assertThat(exception)
.hasMessageThat()
.contains("Expected classifier inputs to contain parameter with name 'x' but had: []")
}

private fun setUpTestApplicationComponent() {
DaggerRatioInputHasSpecificTermEqualToRuleClassifierProviderTest_TestApplicationComponent
.builder()
.setApplication(ApplicationProvider.getApplicationContext()).build().inject(this)
}

// 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: RatioInputHasSpecificTermEqualToRuleClassifierProviderTest)
}

private companion object {
private val NON_NEGATIVE_VALUE_TEST_0 = InteractionObjectTestBuilder.createNonNegativeInt(0)
private val NON_NEGATIVE_VALUE_TEST_1 = InteractionObjectTestBuilder.createNonNegativeInt(1)
private val NON_NEGATIVE_VALUE_TEST_2 = InteractionObjectTestBuilder.createNonNegativeInt(2)
private val NON_NEGATIVE_VALUE_TEST_3 = InteractionObjectTestBuilder.createNonNegativeInt(3)
private val NON_NEGATIVE_VALUE_TEST_4 = InteractionObjectTestBuilder.createNonNegativeInt(4)
private val STRING_VALUE = InteractionObjectTestBuilder.createString("test str")
private val RATIO_VALUE_TEST_3 = InteractionObjectTestBuilder.createRatio(listOf(3))
private val RATIO_VALUE_TEST_3_2 = InteractionObjectTestBuilder.createRatio(listOf(3, 2))
private val RATIO_VALUE_TEST_1_2_3 = InteractionObjectTestBuilder.createRatio(listOf(1, 2, 3))
}
}