summaryrefslogtreecommitdiff
path: root/tst
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2014-02-08 15:49:03 -0800
committerJesse Morgan <jesse@jesterpm.net>2014-02-08 15:49:03 -0800
commitc91558898921c2063762c3b346eaa36a259b6391 (patch)
tree31a9c712a3409a3d1b558550f815a4afa680d49e /tst
parent8c6d308cc269e568c05b79ead2d06f6b16595386 (diff)
Changing the scoring process for slider questions.
Previously sliders were scored as a value between 1 and 4 based on the percentage across the screen that the slider was slid. This required you to slide fully to the right to get a 4. Now the slider is divided into n sections, where n is the number of answers on the slider. With 4 answers the score will be exactly 1, 2, 3, or 4. With more answers you may get a decimals, but the last section of the slider will always result in a 4.
Diffstat (limited to 'tst')
-rw-r--r--tst/com/p4square/grow/model/SliderQuestionTest.java6
-rw-r--r--tst/com/p4square/grow/model/SliderScoringEngineTest.java74
2 files changed, 77 insertions, 3 deletions
diff --git a/tst/com/p4square/grow/model/SliderQuestionTest.java b/tst/com/p4square/grow/model/SliderQuestionTest.java
index eaa67b5..b5c4e83 100644
--- a/tst/com/p4square/grow/model/SliderQuestionTest.java
+++ b/tst/com/p4square/grow/model/SliderQuestionTest.java
@@ -26,6 +26,12 @@ public class SliderQuestionTest {
@Before
public void setUp() {
mQuestion = new SliderQuestion();
+
+ // Add some "answers" for the scoring engine.
+ mQuestion.getAnswers().put("1", new Answer());
+ mQuestion.getAnswers().put("2", new Answer());
+ mQuestion.getAnswers().put("3", new Answer());
+ mQuestion.getAnswers().put("4", new Answer());
}
/**
diff --git a/tst/com/p4square/grow/model/SliderScoringEngineTest.java b/tst/com/p4square/grow/model/SliderScoringEngineTest.java
index fdbfd6f..1ea0d4c 100644
--- a/tst/com/p4square/grow/model/SliderScoringEngineTest.java
+++ b/tst/com/p4square/grow/model/SliderScoringEngineTest.java
@@ -4,6 +4,8 @@
package com.p4square.grow.model;
+import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
@@ -32,10 +34,13 @@ public class SliderScoringEngineTest {
}
/**
- * Test the scoreAnswer() method.
+ * Test the scoreAnswer() method with four answers.
*/
@Test
- public void testScoreAnswer() {
+ public void testScoreAnswerFourAnswers() {
+ // Create the four answers.
+ createAnswers(4);
+
Score score = new Score();
RecordedAnswer answer = new RecordedAnswer();
@@ -51,11 +56,59 @@ public class SliderScoringEngineTest {
assertEquals(2, score.count);
assertEquals(5, score.sum, DELTA);
- // Test fraction (0.33)
+ // Test 0.33. Should be 2.
answer.setAnswerId("0.33333");
assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
assertEquals(3, score.count);
assertEquals(7, score.sum, DELTA);
+
+ // Test 0.9, should be 4.
+ answer.setAnswerId("0.9");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(4, score.count);
+ assertEquals(11, score.sum, DELTA);
+ }
+
+ /**
+ * Test the scoreAnswer() method with six answers.
+ */
+ @Test
+ public void testScoreAnswerSixAnswers() {
+ // Create the four answers.
+ createAnswers(6);
+
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ // Test 0
+ answer.setAnswerId("0");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(1, score.count);
+ assertEquals(1, score.sum, DELTA);
+
+ // Test 1
+ answer.setAnswerId("1");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(2, score.count);
+ assertEquals(5, score.sum, DELTA);
+
+ // Test 0.33. Should score as 1.33
+ answer.setAnswerId("0.33333");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(3, score.count);
+ assertEquals(6.3333, score.sum, DELTA);
+
+ // Test 0.55. Should score as 2.66
+ answer.setAnswerId("0.55");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(4, score.count);
+ assertEquals(9, score.sum, DELTA);
+
+ // Test 0.9. Should score as 4.
+ answer.setAnswerId("0.90");
+ assertTrue(mEngine.scoreAnswer(score, mQuestion, answer));
+ assertEquals(5, score.count);
+ assertEquals(13, score.sum, DELTA);
}
/**
@@ -74,6 +127,7 @@ public class SliderScoringEngineTest {
*/
@Test(expected = IllegalArgumentException.class)
public void testNegativeAnswer() {
+ createAnswers(4);
Score score = new Score();
RecordedAnswer answer = new RecordedAnswer();
answer.setAnswerId("-1");
@@ -85,9 +139,23 @@ public class SliderScoringEngineTest {
*/
@Test(expected = IllegalArgumentException.class)
public void testAnswerOutOfBounds() {
+ createAnswers(4);
Score score = new Score();
RecordedAnswer answer = new RecordedAnswer();
answer.setAnswerId("1.1");
mEngine.scoreAnswer(score, mQuestion, answer);
}
+
+ /**
+ * Helper method to create a number of questions on the slider.
+ *
+ * @param count Number of answers on the questions.
+ */
+ private void createAnswers(int count) {
+ Map<String, Answer> answers = mQuestion.getAnswers();
+ answers.clear();
+ for (int i = 0; i < count; i++) {
+ answers.put(String.valueOf(i), new Answer());
+ }
+ }
}