Skip to content

Commit

Permalink
Fix #4202: Add support for parsing HasIntegerPartEqualTo rule type. (#…
Browse files Browse the repository at this point in the history
…5610)

Fixes #4202 : This PR adds support for parsing the
"HasIntegerPartEqualTo" rule type for fractions in the Oppia Android
app.

### Changes Made
- **Updated** `test_exp_id_2.json` to include the
"HasIntegerPartEqualTo" rule type to ensure the rule is tested properly.
- **Updated** `StateRetriever.kt` to handle the "HasIntegerPartEqualTo"
rule in the `createExactInputForFractionInput()` method.
- **Added** parsing logic for the "HasIntegerPartEqualTo" rule by adding
a new check in `createExactInputForFractionInput()` to handle this rule
type.
---

## Essential Checklist
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [ ] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

---------

Co-authored-by: Adhiambo Peres <[email protected]>
  • Loading branch information
TanishMoral11 and adhiamboperes authored Jan 27, 2025
1 parent d823685 commit db0094a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion domain/src/main/assets/test_exp_id_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,14 @@
"denominator": 2
}
}
}],
},
{
"rule_type": "HasIntegerPartEqualTo",
"inputs": {
"x": 1
}
}
],
"outcome": {
"dest": "MultipleChoice",
"feedback": {
Expand Down
9 changes: 9 additions & 0 deletions domain/src/main/assets/test_exp_id_2.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit db0094a

Please sign in to comment.