|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+import org.junit.Before;
|
|
|
2
|
+import org.junit.Ignore;
|
|
|
3
|
+import org.junit.Rule;
|
|
|
4
|
+import org.junit.Test;
|
|
|
5
|
+import org.junit.rules.ExpectedException;
|
|
|
6
|
+
|
|
|
7
|
+import static org.junit.Assert.assertEquals;
|
|
|
8
|
+
|
|
|
9
|
+/*
|
|
|
10
|
+ * version: 1.0.0
|
|
|
11
|
+ */
|
|
|
12
|
+public class CollatzCalculatorTest {
|
|
|
13
|
+
|
|
|
14
|
+ @Rule
|
|
|
15
|
+ public ExpectedException expectedException = ExpectedException.none();
|
|
|
16
|
+
|
|
|
17
|
+ private CollatzCalculator collatzCalculator;
|
|
|
18
|
+
|
|
|
19
|
+ @Before
|
|
|
20
|
+ public void setUp() {
|
|
|
21
|
+ collatzCalculator = new CollatzCalculator();
|
|
|
22
|
+ }
|
|
|
23
|
+
|
|
|
24
|
+ @Test
|
|
|
25
|
+ public void testZeroStepsRequiredWhenStartingFrom1() {
|
|
|
26
|
+ assertEquals(0, collatzCalculator.computeStepCount(1));
|
|
|
27
|
+ }
|
|
|
28
|
+
|
|
|
29
|
+ @Ignore("Remove to run test")
|
|
|
30
|
+ @Test
|
|
|
31
|
+ public void testCorrectNumberOfStepsWhenAllStepsAreDivisions() {
|
|
|
32
|
+ assertEquals(4, collatzCalculator.computeStepCount(16));
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ @Ignore("Remove to run test")
|
|
|
36
|
+ @Test
|
|
|
37
|
+ public void testCorrectNumberOfStepsWhenBothStepTypesAreNeeded() {
|
|
|
38
|
+ assertEquals(9, collatzCalculator.computeStepCount(12));
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ @Ignore("Remove to run test")
|
|
|
42
|
+ @Test
|
|
|
43
|
+ public void testZeroIsConsideredInvalidInput() {
|
|
|
44
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
45
|
+ expectedException.expectMessage("Only natural numbers are allowed");
|
|
|
46
|
+
|
|
|
47
|
+ collatzCalculator.computeStepCount(0);
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+ @Ignore("Remove to run test")
|
|
|
51
|
+ @Test
|
|
|
52
|
+ public void testNegativeIntegerIsConsideredInvalidInput() {
|
|
|
53
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
54
|
+ expectedException.expectMessage("Only natural numbers are allowed");
|
|
|
55
|
+
|
|
|
56
|
+ collatzCalculator.computeStepCount(-15);
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+}
|