|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+import org.junit.Before;
|
|
|
2
|
+import org.junit.Test;
|
|
|
3
|
+import org.junit.Ignore;
|
|
|
4
|
+import org.junit.Rule;
|
|
|
5
|
+import org.junit.rules.ExpectedException;
|
|
|
6
|
+
|
|
|
7
|
+
|
|
|
8
|
+import static org.junit.Assert.assertArrayEquals;
|
|
|
9
|
+import static org.junit.Assert.assertEquals;
|
|
|
10
|
+
|
|
|
11
|
+/*
|
|
|
12
|
+ * version: 1.0.0
|
|
|
13
|
+ */
|
|
|
14
|
+public class PascalsTriangleGeneratorTest {
|
|
|
15
|
+
|
|
|
16
|
+ private PascalsTriangleGenerator pascalsTriangleGenerator;
|
|
|
17
|
+
|
|
|
18
|
+ @Before
|
|
|
19
|
+ public void setUp() {
|
|
|
20
|
+ pascalsTriangleGenerator = new PascalsTriangleGenerator();
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ @Rule
|
|
|
24
|
+ public ExpectedException thrown = ExpectedException.none();
|
|
|
25
|
+
|
|
|
26
|
+ @Test
|
|
|
27
|
+ public void testTriangleWithZeroRows() {
|
|
|
28
|
+ int[][] expectedOutput = new int[][]{};
|
|
|
29
|
+
|
|
|
30
|
+ assertArrayEquals(expectedOutput, pascalsTriangleGenerator.generateTriangle(0));
|
|
|
31
|
+ }
|
|
|
32
|
+
|
|
|
33
|
+ @Ignore
|
|
|
34
|
+ @Test
|
|
|
35
|
+ public void testTriangleWithOneRow() {
|
|
|
36
|
+ int[][] expectedOutput = new int[][]{
|
|
|
37
|
+ {1}
|
|
|
38
|
+ };
|
|
|
39
|
+
|
|
|
40
|
+ assertArrayEquals(expectedOutput, pascalsTriangleGenerator.generateTriangle(1));
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+ @Ignore
|
|
|
44
|
+ @Test
|
|
|
45
|
+ public void testTriangleWithTwoRows() {
|
|
|
46
|
+ int[][] expectedOutput = new int[][]{
|
|
|
47
|
+ {1},
|
|
|
48
|
+ {1, 1}
|
|
|
49
|
+ };
|
|
|
50
|
+
|
|
|
51
|
+ assertArrayEquals(expectedOutput, pascalsTriangleGenerator.generateTriangle(2));
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ @Ignore
|
|
|
55
|
+ @Test
|
|
|
56
|
+ public void testTriangleWithThreeRows() {
|
|
|
57
|
+ int[][] expectedOutput = new int[][]{
|
|
|
58
|
+ {1},
|
|
|
59
|
+ {1, 1},
|
|
|
60
|
+ {1, 2, 1}
|
|
|
61
|
+ };
|
|
|
62
|
+
|
|
|
63
|
+ assertArrayEquals(expectedOutput, pascalsTriangleGenerator.generateTriangle(3));
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ @Ignore
|
|
|
67
|
+ @Test
|
|
|
68
|
+ public void testTriangleWithFourRows() {
|
|
|
69
|
+ int[][] expectedOutput = new int[][]{
|
|
|
70
|
+ {1},
|
|
|
71
|
+ {1, 1},
|
|
|
72
|
+ {1, 2, 1},
|
|
|
73
|
+ {1, 3, 3, 1}
|
|
|
74
|
+ };
|
|
|
75
|
+
|
|
|
76
|
+ assertArrayEquals(expectedOutput, pascalsTriangleGenerator.generateTriangle(4));
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Ignore
|
|
|
80
|
+ @Test
|
|
|
81
|
+ public void testValidatesNotNegativeRows() {
|
|
|
82
|
+ thrown.expect(IllegalArgumentException.class);
|
|
|
83
|
+ pascalsTriangleGenerator.generateTriangle(-1);
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
|
86
|
+}
|