1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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());
}
}
|