diff --git a/domain/src/main/assets/test_exp_id_2.json b/domain/src/main/assets/test_exp_id_2.json index 494f1937677..69c992ad580 100644 --- a/domain/src/main/assets/test_exp_id_2.json +++ b/domain/src/main/assets/test_exp_id_2.json @@ -496,7 +496,14 @@ "denominator": 2 } } - }], + }, + { + "rule_type": "HasIntegerPartEqualTo", + "inputs": { + "x": 1 + } + } + ], "outcome": { "dest": "MultipleChoice", "feedback": { diff --git a/domain/src/main/assets/test_exp_id_2.textproto b/domain/src/main/assets/test_exp_id_2.textproto index 1fc383fbf27..2917343097e 100644 --- a/domain/src/main/assets/test_exp_id_2.textproto +++ b/domain/src/main/assets/test_exp_id_2.textproto @@ -806,6 +806,15 @@ states { } rule_type: "IsExactlyEqualTo" } + rule_specs { + input { + key: "x" + value { + signed_int: 1 + } + } + rule_type: "HasIntegerPartEqualTo" + } } solution { answer_is_exclusive: true diff --git a/domain/src/main/java/org/oppia/android/domain/util/StateRetriever.kt b/domain/src/main/java/org/oppia/android/domain/util/StateRetriever.kt index 227079a0640..a17bf9301e4 100644 --- a/domain/src/main/java/org/oppia/android/domain/util/StateRetriever.kt +++ b/domain/src/main/java/org/oppia/android/domain/util/StateRetriever.kt @@ -318,6 +318,10 @@ class StateRetriever @Inject constructor() { InteractionObject.newBuilder() .setNonNegativeInt(inputJson.getInt(keyName)) .build() + "HasIntegerPartEqualTo" -> + InteractionObject.newBuilder() + .setSignedInt(inputJson.getInt(keyName)) + .build() else -> InteractionObject.newBuilder() .setFraction(parseFraction(inputJson.getJSONObject(keyName))) diff --git a/domain/src/test/java/org/oppia/android/domain/util/StateRetrieverTest.kt b/domain/src/test/java/org/oppia/android/domain/util/StateRetrieverTest.kt index b0a2d882258..4a4f2adc574 100644 --- a/domain/src/test/java/org/oppia/android/domain/util/StateRetrieverTest.kt +++ b/domain/src/test/java/org/oppia/android/domain/util/StateRetrieverTest.kt @@ -630,6 +630,32 @@ class StateRetrieverTest { assertThat(state.linkedSkillId).isEqualTo("test_skill_id_2") } + @Test + fun testParseState_withFractionInputInteraction_parsesRuleHasIntegerPartEqualToRuleSpec() { + val state = loadStateFromJson( + stateName = "Fractions", + explorationName = TEST_EXPLORATION_ID_2 + ) + + val ruleSpecMap = state.interaction.answerGroupsList + .flatMap(AnswerGroup::getRuleSpecsList) + .associateBy(RuleSpec::getRuleType) + assertThat(ruleSpecMap).containsKey("HasIntegerPartEqualTo") + } + + @Test + fun testParseState_withFractionInput_parsesRuleHasIntegerPartEqualToValueAtX() { + val state = loadStateFromJson( + stateName = "Fractions", + explorationName = TEST_EXPLORATION_ID_2 + ) + + val ruleSpecMap = lookUpRuleSpec(state, "HasIntegerPartEqualTo") + val expectedInputInteractionObject = + InteractionObject.newBuilder().setSignedInt(1).build() + assertThat(ruleSpecMap.inputMap["x"]).isEqualTo(expectedInputInteractionObject) + } + /** * Return the first [RuleSpec] in the specified [State] matching the specified rule type, or fails * if one cannot be found.