summaryrefslogtreecommitdiff
path: root/src/test/java/com/p4square/grow/model/AnswerTest.java
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-04-09 14:22:20 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-04-09 15:48:01 -0700
commit3102d8bce3426d9cf41aeaf201c360d342677770 (patch)
tree38c4f1e8828f9af9c4b77a173bee0d312b321698 /src/test/java/com/p4square/grow/model/AnswerTest.java
parentbbf907e51dfcf157bdee24dead1d531122aa25db (diff)
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'src/test/java/com/p4square/grow/model/AnswerTest.java')
-rw-r--r--src/test/java/com/p4square/grow/model/AnswerTest.java137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/test/java/com/p4square/grow/model/AnswerTest.java b/src/test/java/com/p4square/grow/model/AnswerTest.java
new file mode 100644
index 0000000..1747773
--- /dev/null
+++ b/src/test/java/com/p4square/grow/model/AnswerTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for the Answer class.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class AnswerTest {
+ private static final double DELTA = 1e-15;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(AnswerTest.class.getName());
+ }
+
+ /**
+ * Verify that the correct default values are returned.
+ */
+ @Test
+ public void testDefaults() {
+ Answer a = new Answer();
+
+ // Type should default to AVERAGE
+ assertEquals(Answer.ScoreType.AVERAGE, a.getType());
+
+ // NextQuestion should default to null
+ assertNull(a.getNextQuestion());
+ }
+
+ /**
+ * Verify that getters and setters function correctly.
+ */
+ @Test
+ public void testGetAndSet() {
+ Answer a = new Answer();
+
+ a.setText("Answer Text");
+ assertEquals("Answer Text", a.getText());
+
+ a.setType(Answer.ScoreType.TRUMP);
+ assertEquals(Answer.ScoreType.TRUMP, a.getType());
+
+ a.setScore(10);
+ assertEquals(10, a.getScore(), DELTA);
+
+ a.setNextQuestion("nextQuestion");
+ assertEquals("nextQuestion", a.getNextQuestion());
+ }
+
+ /**
+ * Verify that when the ScoreType is NONE, the score is 0.
+ */
+ @Test
+ public void testScoreTypeNone() {
+ Answer a = new Answer();
+
+ a.setScore(10);
+ assertEquals(10, a.getScore(), DELTA);
+
+ a.setType(Answer.ScoreType.NONE);
+ assertEquals(0, a.getScore(), DELTA);
+ }
+
+ /**
+ * Test score() with type TRUMP.
+ */
+ @Test
+ public void testScoreTrump() {
+ Score score = new Score();
+ score.sum = 10;
+ score.count = 2;
+
+ Answer a = new Answer();
+ a.setType(Answer.ScoreType.TRUMP);
+ a.setScore(5);
+
+ assertFalse(a.score(score));
+
+ assertEquals(5, score.getSum(), DELTA);
+ assertEquals(1, score.getCount());
+ }
+
+ /**
+ * Test score() with type NONE.
+ */
+ @Test
+ public void testScoreNone() {
+ Score score = new Score();
+ score.sum = 10;
+ score.count = 2;
+
+ Answer a = new Answer();
+ a.setScore(5);
+ a.setType(Answer.ScoreType.NONE);
+
+ assertTrue(a.score(score));
+
+ assertEquals(10, score.getSum(), DELTA);
+ assertEquals(2, score.getCount());
+ }
+
+ /**
+ * Test score() with type AVERAGE.
+ */
+ @Test
+ public void testScoreAverage() {
+ Score score = new Score();
+ score.sum = 10;
+ score.count = 2;
+
+ Answer a = new Answer();
+ a.setScore(5);
+ a.setType(Answer.ScoreType.AVERAGE);
+
+ assertTrue(a.score(score));
+
+ assertEquals(15, score.getSum(), DELTA);
+ assertEquals(3, score.getCount());
+ }
+
+ /**
+ * Verify that ScoreType.toString() returns the proper strings.
+ */
+ @Test
+ public void testScoreTypeToString() {
+ assertEquals("none", Answer.ScoreType.NONE.toString());
+ assertEquals("average", Answer.ScoreType.AVERAGE.toString());
+ assertEquals("trump", Answer.ScoreType.TRUMP.toString());
+ }
+}