Skip to content

Commit

Permalink
Fix #3857: Add support for HasSpecificTermEqualTo (#3859)
Browse files Browse the repository at this point in the history
* Add support for AABs, build flavors, and proguard.

There are a lot of details to cover here--see the PR for the complete
context.

* Lint & codeowner fixes.

* Fix failures.

- Add missing codeowner
- Add support for configuring base branch reference
- Update CI for dev/alpha AAB builds to use 'develop' since there's no
  origin configured by default in the workflows

* Different attempt to fix bad develop reference in CI.

* Initial commit.

This is needed to open a PR on GitHub. This commit is being made so that
the PR can start off in a broken Actions state.

This also initially disables most non-Bazel workflows to make workflow
iteration faster and less impacting on other team members.

* Introduce infrastructure for batching.

This introduces a new mechanism for passing lists of tests to sharded
test targets in CI, and hooks it up. No actual sharding is occurring
yet. This led to some simplifications in the CI workflow since the
script can be more dynamic in computing the full list of targets (which
also works around a previous bug with instrumentation tests being run).
Java proto lite also needed to be upgraded for the scripts to be able to
use it.

More testing/documentation needed as this functionality continues to
expand.

* Add bucketing strategy.

This simply partitions bucketed groups of targets into chunks of 10 for
each run. Only 3 buckets are currently retained to test sharding in CI
before introducing full support.

* Fix caching & stabilize builds.

Fixes some caching bucket and output bugs. Also, introduces while loop &
keep_going to introduce resilience against app test build failures (or
just test failures in general).

* Increase sharding & add randomization.

Also, enable other workflows.

Note that CI shouldn't fully pass yet since some documentation and
testing needs to be added yet, but this is meant to be a more realistic
test of the CI environment before the PR is finished.

* Improving partitionin & readability.

Adds a human-readable prefix to make the shards look a bit nicer.

Also, adds more fine-tuned partitioning to bucket & reduce shard counts
to improve overall timing. Will need to be tested in CI.

* Add new tests & fix static analysis errors.

* Fix script.

A newly computed variable wasn't updated to be used in an earlier
change.

* Fix broken tests & test configuration.

Add docstrings for proto.

* Fix mistake from earlier commit.

* Try 10 max parallel actions instead.

See
#3757 (comment)
for context.

* Fix another error from an earlier commit.

* Localisation updates from https://translatewiki.net.

* Fix mv command so it works on Linux & OSX.

Neither 'mv -t' nor piping to mv work on OSX so we needed to find an
alternative (in this case just trying to move everything). This actually
works a bit better since it's doing a per-file move rather than
accommodating for files that shouldn't be moved (which isn't an issue
since the destination directory is different than the one containing the
AAB file).

* Introduce initial domain layer for translations.

Documentation, thorough tests, and detailed description of these changes
are still needed.

* Initial app layer implementation for translations.

This demonstrates working string selection for system-based and
overwritten app languages, including necessary activity recreation &
layout direction overwriting.

This also includes a bunch of Dagger infra refactoring so that some app
layer packages can now be modularized (including the new packages).

* Domain changes needed per downstream UI changes.

* Add patterns & fixes.

This involves MANY broad changes to ensure consistent string retrieval
(for arrays and plurals), formatting, and string transformations
throughout the codebase. Some extra patterns to added to fix things that
were needed, and a few issues were fixed along the way.

* Add needed domain changes for downstream branch.

Also includes fixing circular dependency issue by splitting out some of
the locale components to be part of utility rather than domain (so that
utiltiy and other packages can depend on MachineLocale).

* Introduce support for content localization.

This includes a bunch of stuff that'll be described in more detail in
the PR description, but it essentially:
- Adds support for displaying content in explorations, questions,
  concept cards, and revision cards in a non-English language
- Adds support for submitting non-English answers
- Updates test structures to validate everything exception questions is
  working for localization

* Fix structures to work with parsing assumptions.

* Fix regex checks for translated strings.

Also, performance improvements for the regex check.

* Lint-ish fix.

* Fix failing regex checks.

* Add check for nested res subdirectories.

* Add remaining regex patterns & fixes.

* Clean up locale infra.

Add some other needed functionality.

* Attempt to delete strings to force history.

* Gate options behind compile-time flag.

Flag status is off by default until #52 is finished.

* Proguard fixes for Glide.

Update version code since 6 & 7 were shipped.

* Make AAB builds/runs manual-only targets.

* Fix broken tests.

* Fix lint issues & add KDocs.

Also, abstract ContentLocale for consistency & to disallow direct
construction.

* Add 6/11 test suites (& placeholders for other 4).

Silence one file missing a test suite (since it doesn't need one).

Also, some tweaks to the language support definitions.

* Add more test suites for domain layers.

Included introducing a new general purpose utility for testing data
providers + its own test suite.

* Introduce wrapper & fake for bidi wrapping.

Also, add test version of AssetRepository.

Add new placeholder tests & update all tests project-wide to make sure
that they build.

* Add remaining tests.

Included some shadow refactoring, and introducing new test-only
resources.

* Fix Gradle builds.

* Lint fixes.

* Resolve remaining incomplete TODOs.

* Add new codeowners.

* Post-merge fixes.

Make all non-app layer targets build (haven't run tests yet).

Audited existing bidi wrapping cases & converted strings over to being
%s-only.

* Fix most test targets (builds).

All non-app tests confirmed as passing.

* Fix all remaining test builds.

Introduce new TestActivity for scaffolding all non-activity tests.

* Fix all app layer tests.

Add fixes for question player & old answer displaying.

Add fix for guaranteed crash on startup after some changes between now &
the first build of MR3 (dueu to extra updates in
SplashActivityPresenter).

* Fix questions & profile issues.

* Type specifier pattern & fixes.

Address temporary TODO by removing kdoc.

* Add missing KDocs.

* Boilerplate & TODOs for needed tests.

* Add new needed test dep.

Required an update to truth proto lite import (due to an incompatible
update in the common Truth dep).

* Add needed testing coverage.

Other miscellaneous fixes needed to support new tests.

* Two fixes.

1. Introduce proper API compatibility for LocaleController
2. Ensure TranslationController is scoped (breaks test in downstream PR)

* Fix Gradle builds on branch.

* Resolve nearly all pending TODOs.

Only remainder is a test suite whose tests need to be migrated.

* Lint fixes.

* Re-add method removed from merge.

* Lint fixes.

This also fixes broken extra/unused imports from the merge.

Verified that the dev build works as of this commit. Haven't verified
anything else.

* Fix compute affected tests script.

Adds support for very large PR changesets.

* Fix failures found on CI.

* Fix remaining Gradle failures found in CI.

* Fix existing domain + app layer tests.

Some reworking was needed in QuestionAssessmentProgressControllerTest.

* Post-merge fix.

* Gradle Espresso test fix.

* Add missing KDocs, remove extra file, and other cleanups.

* Lint fixes.

* Fix CI & lint checks (except regex).

* Deflake DataProviderTestMonitorTest.

* Address reviewer comments.

* Lint fixes.

* Fix affected tests from earlier changes.

These failures were found from CI test workflows.

* Fix remaining Gradle failures.

This introduces a proper fallback mechanism for content strings that
allows Gradle builds & tests to work properly, and adds more robustness
in case misconfigurations actually happen.

* Add placeholders for new needed tests.

* Fix broken tests.

This came from the earlier commit's fix--the suite hadn't been updated.

* Add needed tests for new behaviors.

* Fix Gradle build & mechanism change failures.

* Lint fixes.

* Undo inadvertent change to Gradle jvmargs.

* Disable most tests on Espresso.

* Test fixes + make monitor Espresso-compatible.

* Fix broken tests.

Refactor how platform parameter module.

Add new options fragment tests.

* Add exemptions & regex check tests.

* Lint fixes.

* Lint fixes.

* Add new ratio input rule classifier.

* Fix broken tests (per CI).

Co-authored-by: translatewiki.net <[email protected]>
  • Loading branch information
BenHenning and translatewiki authored Oct 6, 2021
1 parent 0caaa7f commit 5daaa9e
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 6 deletions.
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))
}
}

0 comments on commit 5daaa9e

Please sign in to comment.