summaryrefslogtreecommitdiff
path: root/tst
diff options
context:
space:
mode:
Diffstat (limited to 'tst')
-rw-r--r--tst/com/p4square/grow/model/CircleQuestionTest.java92
-rw-r--r--tst/com/p4square/grow/model/ImageQuestionTest.java74
-rw-r--r--tst/com/p4square/grow/model/QuadQuestionTest.java92
-rw-r--r--tst/com/p4square/grow/model/ScoreTest.java111
-rw-r--r--tst/com/p4square/grow/model/SliderQuestionTest.java58
-rw-r--r--tst/com/p4square/grow/model/TextQuestionTest.java74
-rw-r--r--tst/com/p4square/grow/model/TrainingRecordTest.java178
-rw-r--r--tst/com/p4square/grow/model/trainingrecord.json18
8 files changed, 697 insertions, 0 deletions
diff --git a/tst/com/p4square/grow/model/CircleQuestionTest.java b/tst/com/p4square/grow/model/CircleQuestionTest.java
new file mode 100644
index 0000000..222cda5
--- /dev/null
+++ b/tst/com/p4square/grow/model/CircleQuestionTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for CircleQuestion.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class CircleQuestionTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(CircleQuestionTest.class.getName());
+ }
+
+ private CircleQuestion mQuestion;
+
+ @Before
+ public void setUp() {
+ mQuestion = new CircleQuestion();
+
+ Answer a1 = new Answer();
+ a1.setScore(2);
+
+ Answer a2 = new Answer();
+ a2.setScore(4);
+
+ mQuestion.getAnswers().put("1.00,0.00", a1);
+ mQuestion.getAnswers().put("-1.00,0.00", a2);
+ }
+
+ /**
+ * Verify the getters and setters function correctly.
+ */
+ @Test
+ public void testGetAndSet() {
+ mQuestion.setTopLeft("TopLeft String");
+ assertEquals("TopLeft String", mQuestion.getTopLeft());
+
+ mQuestion.setTopRight("TopRight String");
+ assertEquals("TopRight String", mQuestion.getTopRight());
+
+ mQuestion.setBottomRight("BottomRight String");
+ assertEquals("BottomRight String", mQuestion.getBottomRight());
+
+ mQuestion.setBottomLeft("BottomLeft String");
+ assertEquals("BottomLeft String", mQuestion.getBottomLeft());
+ }
+
+ /**
+ * The ScoringEngines are tested extensively independently, so simply
+ * verify that we get the expected results for our input.
+ */
+ @Test
+ public void testScoreAnswer() {
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ answer.setAnswerId("0.5,0.5");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(2, score.sum, DELTA);
+ assertEquals(1, score.count);
+
+ answer.setAnswerId("-0.5,-0.5");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(6, score.sum, DELTA);
+ assertEquals(2, score.count);
+
+ try {
+ answer.setAnswerId("notAPoint");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ fail("Should have thrown exception.");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Verify the correct type string is returned.
+ */
+ @Test
+ public void testType() {
+ assertEquals("circle", mQuestion.getType().toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/ImageQuestionTest.java b/tst/com/p4square/grow/model/ImageQuestionTest.java
new file mode 100644
index 0000000..28ccdb2
--- /dev/null
+++ b/tst/com/p4square/grow/model/ImageQuestionTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for ImageQuestion.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class ImageQuestionTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(ImageQuestionTest.class.getName());
+ }
+
+ private Question mQuestion;
+
+ @Before
+ public void setUp() {
+ mQuestion = new ImageQuestion();
+
+ Answer a1 = new Answer();
+ a1.setScore(2);
+
+ Answer a2 = new Answer();
+ a2.setScore(4);
+
+ mQuestion.getAnswers().put("a1", a1);
+ mQuestion.getAnswers().put("a2", a2);
+ }
+
+ /**
+ * The ScoringEngines are tested extensively independently, so simply
+ * verify that we get the expected results for our input.
+ */
+ @Test
+ public void testScoreAnswer() {
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ answer.setAnswerId("a1");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(2, score.sum, DELTA);
+ assertEquals(1, score.count);
+
+ answer.setAnswerId("a2");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(6, score.sum, DELTA);
+ assertEquals(2, score.count);
+
+ try {
+ answer.setAnswerId("unknown");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ fail("Should have thrown exception.");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Verify the correct type string is returned.
+ */
+ @Test
+ public void testType() {
+ assertEquals("image", mQuestion.getType().toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/QuadQuestionTest.java b/tst/com/p4square/grow/model/QuadQuestionTest.java
new file mode 100644
index 0000000..389148a
--- /dev/null
+++ b/tst/com/p4square/grow/model/QuadQuestionTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for QuadQuestion.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class QuadQuestionTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(QuadQuestionTest.class.getName());
+ }
+
+ private QuadQuestion mQuestion;
+
+ @Before
+ public void setUp() {
+ mQuestion = new QuadQuestion();
+
+ Answer a1 = new Answer();
+ a1.setScore(2);
+
+ Answer a2 = new Answer();
+ a2.setScore(4);
+
+ mQuestion.getAnswers().put("1.00,0.00", a1);
+ mQuestion.getAnswers().put("-1.00,0.00", a2);
+ }
+
+ /**
+ * Verify the getters and setters function correctly.
+ */
+ @Test
+ public void testGetAndSet() {
+ mQuestion.setTop("Top String");
+ assertEquals("Top String", mQuestion.getTop());
+
+ mQuestion.setBottom("Bottom String");
+ assertEquals("Bottom String", mQuestion.getBottom());
+
+ mQuestion.setLeft("Left String");
+ assertEquals("Left String", mQuestion.getLeft());
+
+ mQuestion.setRight("Right String");
+ assertEquals("Right String", mQuestion.getRight());
+ }
+
+ /**
+ * The ScoringEngines are tested extensively independently, so simply
+ * verify that we get the expected results for our input.
+ */
+ @Test
+ public void testScoreAnswer() {
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ answer.setAnswerId("0.5,0.5");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(2, score.sum, DELTA);
+ assertEquals(1, score.count);
+
+ answer.setAnswerId("-0.5,-0.5");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(6, score.sum, DELTA);
+ assertEquals(2, score.count);
+
+ try {
+ answer.setAnswerId("notAPoint");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ fail("Should have thrown exception.");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Verify the correct type string is returned.
+ */
+ @Test
+ public void testType() {
+ assertEquals("quad", mQuestion.getType().toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/ScoreTest.java b/tst/com/p4square/grow/model/ScoreTest.java
new file mode 100644
index 0000000..dd3522a
--- /dev/null
+++ b/tst/com/p4square/grow/model/ScoreTest.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for the Score class.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class ScoreTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(ScoreTest.class.getName());
+ }
+
+ private Score mScore;
+
+ @Before
+ public void setUp() {
+ mScore = new Score();
+ }
+
+ /**
+ * Verify getters and setters function.
+ */
+ @Test
+ public void testGetAndSet() {
+ // getSum()
+ mScore.sum = 1.1;
+ assertEquals(1.1, mScore.getSum(), DELTA);
+
+ // getCount()
+ mScore.count = 5;
+ assertEquals(5, mScore.getCount());
+ }
+
+ /**
+ * Verify that the average is computed by getScore().
+ */
+ @Test
+ public void testGetScore() {
+ mScore.sum = 7;
+ mScore.count = 2;
+ assertEquals(3.5, mScore.getScore(), DELTA);
+ }
+
+ /**
+ * Verify that numericScore() returns the correct mappings.
+ */
+ @Test
+ public void testNumericScore() {
+ assertEquals(4, Score.numericScore("teacher"));
+ assertEquals(3, Score.numericScore("disciple"));
+ assertEquals(2, Score.numericScore("believer"));
+ assertEquals(1, Score.numericScore("seeker"));
+ }
+
+ /**
+ * Verify that toString() returns the correct mappings.
+ */
+ @Test
+ public void testToString() {
+ mScore.count = 1;
+
+ // Seeker is defined as score < 2
+ mScore.sum = 0;
+ assertEquals("seeker", mScore.toString());
+ mScore.sum = 0.5;
+ assertEquals("seeker", mScore.toString());
+ mScore.sum = 1;
+ assertEquals("seeker", mScore.toString());
+ mScore.sum = 1.5;
+ assertEquals("seeker", mScore.toString());
+ mScore.sum = 1.99;
+ assertEquals("seeker", mScore.toString());
+
+ // Believer is defined as 2 <= score < 3
+ mScore.sum = 2;
+ assertEquals("believer", mScore.toString());
+ mScore.sum = 2.5;
+ assertEquals("believer", mScore.toString());
+ mScore.sum = 2.99;
+ assertEquals("believer", mScore.toString());
+
+ // Disciple is defined as 3 <= score < 4
+ mScore.sum = 3;
+ assertEquals("disciple", mScore.toString());
+ mScore.sum = 3.5;
+ assertEquals("disciple", mScore.toString());
+ mScore.sum = 3.99;
+ assertEquals("disciple", mScore.toString());
+
+ // Teacher is defined as 4 <= score
+ mScore.sum = 4;
+ assertEquals("teacher", mScore.toString());
+ mScore.sum = 4.5;
+ assertEquals("teacher", mScore.toString());
+ mScore.sum = 4.99;
+ assertEquals("teacher", mScore.toString());
+ mScore.sum = 5;
+ assertEquals("teacher", mScore.toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/SliderQuestionTest.java b/tst/com/p4square/grow/model/SliderQuestionTest.java
new file mode 100644
index 0000000..eaa67b5
--- /dev/null
+++ b/tst/com/p4square/grow/model/SliderQuestionTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for SliderQuestion.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class SliderQuestionTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(SliderQuestionTest.class.getName());
+ }
+
+ private Question mQuestion;
+
+ @Before
+ public void setUp() {
+ mQuestion = new SliderQuestion();
+ }
+
+ /**
+ * The ScoringEngines are tested extensively independently, so simply
+ * verify that we get the expected results for our input.
+ */
+ @Test
+ public void testScoreAnswer() {
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ answer.setAnswerId("0.66666");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(3, score.sum, DELTA);
+ assertEquals(1, score.count);
+
+ answer.setAnswerId("1");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(7, score.sum, DELTA);
+ assertEquals(2, score.count);
+ }
+
+ /**
+ * Verify the correct type string is returned.
+ */
+ @Test
+ public void testType() {
+ assertEquals("slider", mQuestion.getType().toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/TextQuestionTest.java b/tst/com/p4square/grow/model/TextQuestionTest.java
new file mode 100644
index 0000000..d85ed86
--- /dev/null
+++ b/tst/com/p4square/grow/model/TextQuestionTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for TextQuestion.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class TextQuestionTest {
+ private static final double DELTA = 1e-4;
+
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(TextQuestionTest.class.getName());
+ }
+
+ private Question mQuestion;
+
+ @Before
+ public void setUp() {
+ mQuestion = new TextQuestion();
+
+ Answer a1 = new Answer();
+ a1.setScore(2);
+
+ Answer a2 = new Answer();
+ a2.setScore(4);
+
+ mQuestion.getAnswers().put("a1", a1);
+ mQuestion.getAnswers().put("a2", a2);
+ }
+
+ /**
+ * The ScoringEngines are tested extensively independently, so simply
+ * verify that we get the expected results for our input.
+ */
+ @Test
+ public void testScoreAnswer() {
+ Score score = new Score();
+ RecordedAnswer answer = new RecordedAnswer();
+
+ answer.setAnswerId("a1");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(2, score.sum, DELTA);
+ assertEquals(1, score.count);
+
+ answer.setAnswerId("a2");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ assertEquals(6, score.sum, DELTA);
+ assertEquals(2, score.count);
+
+ try {
+ answer.setAnswerId("unknown");
+ assertTrue(mQuestion.scoreAnswer(score, answer));
+ fail("Should have thrown exception.");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Verify the correct type string is returned.
+ */
+ @Test
+ public void testType() {
+ assertEquals("text", mQuestion.getType().toString());
+ }
+}
diff --git a/tst/com/p4square/grow/model/TrainingRecordTest.java b/tst/com/p4square/grow/model/TrainingRecordTest.java
new file mode 100644
index 0000000..246d6ff
--- /dev/null
+++ b/tst/com/p4square/grow/model/TrainingRecordTest.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2013 Jesse Morgan
+ */
+
+package com.p4square.grow.model;
+
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test TrainingRecord, Playlist, and Chapter.
+ *
+ * @author Jesse Morgan <jesse@jesterpm.net>
+ */
+public class TrainingRecordTest {
+ public static void main(String... args) {
+ org.junit.runner.JUnitCore.main(TrainingRecordTest.class.getName());
+ }
+
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ /**
+ * Test deserialization of a JSON Training record.
+ */
+ @Test
+ public void testDeserialization() throws Exception {
+ InputStream in = getClass().getResourceAsStream("trainingrecord.json");
+ TrainingRecord record = MAPPER.readValue(in, TrainingRecord.class);
+
+ // Last Video
+ assertEquals("teacher-1", record.getLastVideo());
+
+ // Playlist
+ Playlist playlist = record.getPlaylist();
+
+ // Find video successfully
+ VideoRecord r = playlist.find("teacher-1");
+ assertEquals(true, r.getRequired());
+ assertEquals(true, r.getComplete());
+ assertEquals(new Date(1379288806266L), r.getCompletionDate());
+
+ // Find non-existent video
+ r = playlist.find("not-a-video");
+ assertEquals(null, r);
+
+ // isChapterComplete
+ assertTrue(playlist.isChapterComplete("seeker")); // Complete because not required.
+ assertTrue(playlist.isChapterComplete("disciple")); // Required and completed.
+ assertFalse(playlist.isChapterComplete("teacher")); // Not complete.
+
+ // getChapterStatuses
+ Map<String, Boolean> statuses = playlist.getChapterStatuses();
+ assertTrue(statuses.get("seeker")); // Complete because not required.
+ assertTrue(statuses.get("disciple")); // Required and completed.
+ assertFalse(statuses.get("teacher")); // Not complete.
+ }
+
+ /**
+ * Tests for VideoRecord.
+ */
+ @Test
+ public void testVideoRecord() {
+ VideoRecord record = new VideoRecord();
+
+ // Verify defaults
+ assertTrue(record.getRequired());
+ assertFalse(record.getComplete());
+ assertEquals(null, record.getCompletionDate());
+
+ // Verify completion
+ long now = System.currentTimeMillis();
+ record.complete();
+ assertTrue(record.getRequired());
+ assertTrue(record.getComplete());
+ assertTrue(now <= record.getCompletionDate().getTime());
+ }
+
+ /**
+ * Tests for Playlist and Chapter methods not covered in the deserialization test.
+ */
+ @Test
+ public void testPlaylistAndChapter() {
+ // Create a playlist for the test
+ Playlist playlist = new Playlist();
+ playlist.add("chapter1", "video1");
+ playlist.add("chapter1", "video2");
+
+ // Chapter should not be complete
+ assertFalse(playlist.isChapterComplete("chapter1"));
+
+ // We should find the chapter in the map
+ Map<String, Chapter> chapterMap = playlist.getChaptersMap();
+ Chapter chapter1 = chapterMap.get("chapter1");
+ assertTrue(null != chapter1);
+
+ // We should find the videos in the map.
+ Map<String, VideoRecord> videoMap = chapter1.getVideos();
+ assertTrue(null != videoMap.get("video1"));
+ assertTrue(null != videoMap.get("video2"));
+ assertTrue(null == videoMap.get("video3"));
+
+ // Mark the videos as complete
+ VideoRecord video1 = videoMap.get("video1");
+ VideoRecord video2 = videoMap.get("video2");
+ video1.complete();
+ video2.complete();
+
+ // Chapter should be complete now.
+ assertTrue(playlist.isChapterComplete("chapter1"));
+ assertFalse(playlist.isChapterComplete("bogusChapter"));
+ }
+
+ /**
+ * Tests for Playlist default values.
+ */
+ @Test
+ public void testPlaylistDefaults() {
+ Date before = new Date();
+ Playlist p = new Playlist();
+
+ // Verify that a playlist without an explicit lastUpdated date is older than now.
+ assertTrue(p.getLastUpdated().before(before));
+ }
+
+ /**
+ * Tests for the Playlist merge method.
+ */
+ @Test
+ public void testMergePlaylist() {
+ Playlist oldList = new Playlist();
+ oldList.add("chapter1", "video1").setRequired(true);
+ oldList.add("chapter2", "video2").setRequired(false);
+ oldList.add("chapter2", "video3").complete();
+ oldList.setLastUpdated(new Date(100));
+
+ Playlist newList = new Playlist();
+ newList.add("chapter1", "video4").setRequired(true);
+ newList.add("chapter2", "video5").setRequired(false);
+ newList.add("chapter3", "video6").setRequired(false);
+ newList.setLastUpdated(new Date(500));
+
+ // Verify that you can't merge the old into the new
+ newList.merge(oldList);
+ assertTrue(null == newList.find("video2"));
+
+ // Merge the new list into the old and verify results
+ oldList.merge(newList);
+
+ // All Videos Present
+ assertTrue(oldList.find("video1").getRequired());
+ assertFalse(oldList.find("video2").getRequired());
+ assertTrue(oldList.find("video3").getComplete());
+ assertTrue(oldList.find("video4").getRequired());
+ assertFalse(oldList.find("video5").getRequired());
+ assertFalse(oldList.find("video6").getRequired());
+
+ // New Chapter added
+ Map<String, Chapter> chapters = oldList.getChaptersMap();
+ assertEquals(3, chapters.size());
+ assertTrue(null != chapters.get("chapter3"));
+
+ // Date updated
+ assertEquals(newList.getLastUpdated(), oldList.getLastUpdated());
+
+ // Video objects are actually independent
+ VideoRecord oldVideo4 = oldList.find("video4");
+ VideoRecord newVideo4 = newList.find("video4");
+ assertTrue(oldVideo4 != newVideo4);
+ }
+}
diff --git a/tst/com/p4square/grow/model/trainingrecord.json b/tst/com/p4square/grow/model/trainingrecord.json
new file mode 100644
index 0000000..ea214f3
--- /dev/null
+++ b/tst/com/p4square/grow/model/trainingrecord.json
@@ -0,0 +1,18 @@
+{
+ "lastVideo": "teacher-1",
+ "playlist": {
+ "seeker": {
+ "seeker-2":{"required":false,"complete":false,"completionDate":null},
+ "seeker-1":{"required":false,"complete":false,"completionDate":null}
+ },
+ "disciple":{
+ "disciple-8":{"required":true,"complete":true,"completionDate":1379288805010},
+ "disciple-9":{"required":true,"complete":true,"completionDate":1379288805220},
+ "disciple-1":{"required":true,"complete":true,"completionDate":1379288805266}
+ },
+ "teacher":{
+ "teacher-2":{"required":true,"complete":false,"completionDate":null},
+ "teacher-1":{"required":true,"complete":true,"completionDate":1379288806266}
+ }
+ }
+}