-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* introduce interaction object helper class * nit change * format fix
- Loading branch information
1 parent
351a72e
commit 19faa4f
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
domain/src/test/java/org/oppia/android/domain/classify/InteractionObjectTestBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.oppia.android.domain.classify | ||
|
||
import org.oppia.android.app.model.Fraction | ||
import org.oppia.android.app.model.InteractionObject | ||
import org.oppia.android.app.model.ListOfSetsOfHtmlStrings | ||
import org.oppia.android.app.model.StringList | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Helper class for test cases which can provide the [InteractionObject] | ||
* of a particular ObjectTypeCase. | ||
*/ | ||
class InteractionObjectTestBuilder @Inject constructor() { | ||
|
||
fun createNonNegativeInt(value: Int): InteractionObject { | ||
return InteractionObject.newBuilder().setNonNegativeInt(value).build() | ||
} | ||
|
||
fun createString(value: String): InteractionObject { | ||
return InteractionObject.newBuilder().setNormalizedString(value).build() | ||
} | ||
|
||
fun createListOfSetsOfHtmlStrings(listOfStringList: List<StringList>): InteractionObject { | ||
val listOfSetsOfHtmlStrings = ListOfSetsOfHtmlStrings.newBuilder() | ||
.addAllSetOfHtmlStrings( | ||
listOfStringList | ||
) | ||
.build() | ||
|
||
return InteractionObject.newBuilder().setListOfSetsOfHtmlString(listOfSetsOfHtmlStrings).build() | ||
} | ||
|
||
fun createHtmlStringList(vararg items: String): StringList { | ||
return StringList.newBuilder().addAllHtml(items.toList()).build() | ||
} | ||
|
||
fun createWholeNumber(isNegative: Boolean, value: Int): InteractionObject { | ||
// Whole number fractions imply '0/1' fractional parts. | ||
return InteractionObject.newBuilder().setFraction( | ||
Fraction.newBuilder() | ||
.setIsNegative(isNegative) | ||
.setWholeNumber(value) | ||
.setNumerator(0) | ||
.setDenominator(1) | ||
.build() | ||
).build() | ||
} | ||
|
||
fun createFraction( | ||
isNegative: Boolean, | ||
numerator: Int, | ||
denominator: Int | ||
): InteractionObject { | ||
// Fraction-only numbers imply no whole number. | ||
return InteractionObject.newBuilder().setFraction( | ||
Fraction.newBuilder() | ||
.setIsNegative(isNegative) | ||
.setNumerator(numerator) | ||
.setDenominator(denominator) | ||
.build() | ||
).build() | ||
} | ||
|
||
fun createMixedNumber( | ||
isNegative: Boolean, | ||
wholeNumber: Int, | ||
numerator: Int, | ||
denominator: Int | ||
): InteractionObject { | ||
return InteractionObject.newBuilder().setFraction( | ||
Fraction.newBuilder() | ||
.setIsNegative(isNegative) | ||
.setWholeNumber(wholeNumber) | ||
.setNumerator(numerator) | ||
.setDenominator(denominator) | ||
.build() | ||
).build() | ||
} | ||
|
||
fun createSignedInt(value: Int): InteractionObject { | ||
return InteractionObject.newBuilder().setSignedInt(value).build() | ||
} | ||
|
||
fun createReal(value: Double): InteractionObject { | ||
return InteractionObject.newBuilder().setReal(value).build() | ||
} | ||
|
||
fun createInt(value: Int): InteractionObject { | ||
return InteractionObject.newBuilder().setReal(value.toDouble()).build() | ||
} | ||
} |