|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+import org.junit.Test;
|
|
|
2
|
+
|
|
|
3
|
+import static org.junit.Assert.assertArrayEquals;
|
|
|
4
|
+import static org.junit.Assert.assertEquals;
|
|
|
5
|
+
|
|
|
6
|
+public class PascalsTriangleTest {
|
|
|
7
|
+
|
|
|
8
|
+ @Test
|
|
|
9
|
+ public void testTriangleWithFourRows() {
|
|
|
10
|
+ int[][] expectedOutput = new int[][]{
|
|
|
11
|
+ {1},
|
|
|
12
|
+ {1, 1},
|
|
|
13
|
+ {1, 2, 1},
|
|
|
14
|
+ {1, 3, 3, 1},
|
|
|
15
|
+ };
|
|
|
16
|
+
|
|
|
17
|
+ assertArrayEquals(expectedOutput, PascalsTriangle.computeTriangle(4));
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ @Test
|
|
|
21
|
+ public void testTriangleWithSixRows() {
|
|
|
22
|
+ int[][] expectedOutput = new int[][]{
|
|
|
23
|
+ {1},
|
|
|
24
|
+ {1, 1},
|
|
|
25
|
+ {1, 2, 1},
|
|
|
26
|
+ {1, 3, 3, 1},
|
|
|
27
|
+ {1, 4, 6, 4, 1},
|
|
|
28
|
+ {1, 5, 10, 10, 5, 1}
|
|
|
29
|
+ };
|
|
|
30
|
+
|
|
|
31
|
+ assertArrayEquals(expectedOutput, PascalsTriangle.computeTriangle(6));
|
|
|
32
|
+ }
|
|
|
33
|
+
|
|
|
34
|
+ @Test
|
|
|
35
|
+ public void testExpectEmptyTriangle() {
|
|
|
36
|
+ int[][] expectedOutput = new int[][]{
|
|
|
37
|
+
|
|
|
38
|
+ };
|
|
|
39
|
+
|
|
|
40
|
+ assertArrayEquals(expectedOutput, PascalsTriangle.computeTriangle(0));
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+ @Test
|
|
|
44
|
+ public void testValidInput() {
|
|
|
45
|
+ int[][] input = new int[][]{
|
|
|
46
|
+ {1},
|
|
|
47
|
+ {1, 1},
|
|
|
48
|
+ {1, 2, 1},
|
|
|
49
|
+ {1, 3, 3, 1},
|
|
|
50
|
+ {1, 4, 6, 4, 1},
|
|
|
51
|
+ };
|
|
|
52
|
+
|
|
|
53
|
+ assertEquals(true, PascalsTriangle.isTriangle(input));
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ @Test
|
|
|
57
|
+ public void testInvalidInput() {
|
|
|
58
|
+ int[][] input = new int[][]{
|
|
|
59
|
+ {1},
|
|
|
60
|
+ {1, 1},
|
|
|
61
|
+ {1, 2, 1},
|
|
|
62
|
+ {1, 4, 4, 1},
|
|
|
63
|
+ };
|
|
|
64
|
+
|
|
|
65
|
+ assertEquals(false, PascalsTriangle.isTriangle(input));
|
|
|
66
|
+ }
|
|
|
67
|
+
|
|
|
68
|
+ @Test(expected = IllegalArgumentException.class)
|
|
|
69
|
+ public void testValidatesNotNegativeRows() {
|
|
|
70
|
+ PascalsTriangle.computeTriangle(-1);
|
|
|
71
|
+ }
|
|
|
72
|
+}
|