@@ -2,83 +2,117 @@ package org.odk.collect.android.widgets.range
22
33import org.hamcrest.MatcherAssert.assertThat
44import org.hamcrest.Matchers.equalTo
5+ import org.javarosa.core.model.Constants
6+ import org.javarosa.core.model.DataType
7+ import org.javarosa.core.model.RangeQuestion
58import org.javarosa.core.model.data.IntegerData
69import org.javarosa.form.api.FormEntryPrompt
710import org.junit.Test
811import org.mockito.kotlin.mock
912import org.mockito.kotlin.whenever
13+ import org.odk.collect.android.support.MockFormEntryPromptBuilder
1014import java.math.BigDecimal
1115
1216class RangePickerWidgetUtilsTest {
1317
1418 @Test
1519 fun `list of numbers should contain only rangeStart when range has equal start and end` () {
16- val rangeStart = BigDecimal (5.0 )
17- val rangeEnd = BigDecimal (5.0 )
18- val rangeStep = BigDecimal (1.0 )
20+ val rangeQuestion = RangeQuestion ()
21+ rangeQuestion.rangeStart = BigDecimal (5.0 )
22+ rangeQuestion.rangeEnd = BigDecimal (5.0 )
23+ rangeQuestion.rangeStep = BigDecimal (1.0 )
24+ val prompt = MockFormEntryPromptBuilder ()
25+ .withQuestion(rangeQuestion)
26+ .withDataType(Constants .DATATYPE_DECIMAL )
27+ .build()
1928
2029 assertThat(
21- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, false ),
30+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
2231 equalTo(arrayOf(" 5.0" ))
2332 )
2433 }
2534
2635 @Test
2736 fun `list of numbers should contain only rangeStart when step is bigger than range` () {
28- val rangeStart = BigDecimal (- 5 )
29- val rangeEnd = BigDecimal (5 )
30- val rangeStep = BigDecimal (100 )
37+ val rangeQuestion = RangeQuestion ()
38+ rangeQuestion.rangeStart = BigDecimal (- 5 )
39+ rangeQuestion.rangeEnd = BigDecimal (5 )
40+ rangeQuestion.rangeStep = BigDecimal (100 )
41+ val prompt = MockFormEntryPromptBuilder ()
42+ .withQuestion(rangeQuestion)
43+ .withDataType(Constants .DATATYPE_INTEGER )
44+ .build()
3145
3246 assertThat(
33- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, true ),
47+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
3448 equalTo(arrayOf(" -5" ))
3549 )
3650 }
3751
3852 @Test
3953 fun `list of numbers should contain numbers in ascending order when range is increasing` () {
40- val rangeStart = BigDecimal (- 5.0 )
41- val rangeEnd = BigDecimal (5.0 )
42- val rangeStep = BigDecimal (1.5 )
54+ val rangeQuestion = RangeQuestion ()
55+ rangeQuestion.rangeStart = BigDecimal (- 5.0 )
56+ rangeQuestion.rangeEnd = BigDecimal (5.0 )
57+ rangeQuestion.rangeStep = BigDecimal (1.5 )
58+ val prompt = MockFormEntryPromptBuilder ()
59+ .withQuestion(rangeQuestion)
60+ .withDataType(Constants .DATATYPE_DECIMAL )
61+ .build()
4362
4463 assertThat(
45- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, false ),
64+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
4665 equalTo(arrayOf(" -5.0" , " -3.5" , " -2.0" , " -0.5" , " 1.0" , " 2.5" , " 4.0" ))
4766 )
4867 }
4968
5069 @Test
5170 fun `list of numbers should contain numbers in ascending order when range is decreasing` () {
52- val rangeStart = BigDecimal (5 )
53- val rangeEnd = BigDecimal (- 5 )
54- val rangeStep = BigDecimal (1 )
71+ val rangeQuestion = RangeQuestion ()
72+ rangeQuestion.rangeStart = BigDecimal (5 )
73+ rangeQuestion.rangeEnd = BigDecimal (- 5 )
74+ rangeQuestion.rangeStep = BigDecimal (1 )
75+ val prompt = MockFormEntryPromptBuilder ()
76+ .withQuestion(rangeQuestion)
77+ .withDataType(Constants .DATATYPE_INTEGER )
78+ .build()
5579
5680 assertThat(
57- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, true ),
81+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
5882 equalTo(arrayOf(" -5" , " -4" , " -3" , " -2" , " -1" , " 0" , " 1" , " 2" , " 3" , " 4" , " 5" ))
5983 )
6084 }
6185
6286 @Test
6387 fun `list of numbers should contain numbers in ascending order when range is decreasing and step is a negative number` () {
64- val rangeStart = BigDecimal (5.0 )
65- val rangeEnd = BigDecimal (- 5.0 )
66- val rangeStep = BigDecimal (- 1.5 )
88+ val rangeQuestion = RangeQuestion ()
89+ rangeQuestion.rangeStart = BigDecimal (5.0 )
90+ rangeQuestion.rangeEnd = BigDecimal (- 5.0 )
91+ rangeQuestion.rangeStep = BigDecimal (- 1.5 )
92+ val prompt = MockFormEntryPromptBuilder ()
93+ .withQuestion(rangeQuestion)
94+ .withDataType(Constants .DATATYPE_DECIMAL )
95+ .build()
6796
6897 assertThat(
69- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, false ),
98+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
7099 equalTo(arrayOf(" -5.0" , " -3.5" , " -2.0" , " -0.5" , " 1.0" , " 2.5" , " 4.0" ))
71100 )
72101 }
73102
74103 @Test
75104 fun `list of numbers should contain numbers in ascending order when step is bigger than 1` () {
76- val rangeStart = BigDecimal (- 5 )
77- val rangeEnd = BigDecimal (5 )
78- val rangeStep = BigDecimal (2 )
105+ val rangeQuestion = RangeQuestion ()
106+ rangeQuestion.rangeStart = BigDecimal (- 5 )
107+ rangeQuestion.rangeEnd = BigDecimal (5 )
108+ rangeQuestion.rangeStep = BigDecimal (2 )
109+ val prompt = MockFormEntryPromptBuilder ()
110+ .withQuestion(rangeQuestion)
111+ .withDataType(Constants .DATATYPE_INTEGER )
112+ .build()
79113
80114 assertThat(
81- RangePickerWidgetUtils .getNumbersFromRangeAsc(rangeStart, rangeStep, rangeEnd, true ),
115+ RangePickerWidgetUtils .getNumbersFromRangeAsc(prompt ),
82116 equalTo(arrayOf(" -5" , " -3" , " -1" , " 1" , " 3" , " 5" ))
83117 )
84118 }
0 commit comments