|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+import org.junit.Test;
|
|
|
2
|
+
|
|
|
3
|
+import static org.junit.Assert.assertEquals;
|
|
|
4
|
+
|
|
|
5
|
+public class TriangleTest {
|
|
|
6
|
+
|
|
|
7
|
+ @Test
|
|
|
8
|
+ public void equilateralTriangleHaveEqualSides() throws Exception {
|
|
|
9
|
+ Triangle triangle = new Triangle(2, 2, 2);
|
|
|
10
|
+
|
|
|
11
|
+ assertEquals(triangle.getKind(), TriangleKind.EQUILATERAL);
|
|
|
12
|
+ }
|
|
|
13
|
+
|
|
|
14
|
+ @Test
|
|
|
15
|
+ public void largerEquilateralTrianglesAlsoHaveEqualSides() throws Exception {
|
|
|
16
|
+ Triangle triangle = new Triangle(10, 10, 10);
|
|
|
17
|
+
|
|
|
18
|
+ assertEquals(triangle.getKind(), TriangleKind.EQUILATERAL);
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+ @Test
|
|
|
22
|
+ public void isoscelesTrianglesHaveLastTwoSidesEqual() throws Exception {
|
|
|
23
|
+ Triangle triangle = new Triangle(3, 4, 4);
|
|
|
24
|
+
|
|
|
25
|
+ assertEquals(triangle.getKind(), TriangleKind.ISOSCELES);
|
|
|
26
|
+ }
|
|
|
27
|
+
|
|
|
28
|
+ @Test
|
|
|
29
|
+ public void isoscelesTrianglesHaveFirstAndLastSidesEqual() throws Exception {
|
|
|
30
|
+ Triangle triangle = new Triangle(4, 3, 4);
|
|
|
31
|
+
|
|
|
32
|
+ assertEquals(triangle.getKind(), TriangleKind.ISOSCELES);
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ @Test
|
|
|
36
|
+ public void isoscelesTrianglesHaveTwoFirstSidesEqual() throws Exception {
|
|
|
37
|
+ Triangle triangle = new Triangle(4, 4, 3);
|
|
|
38
|
+
|
|
|
39
|
+ assertEquals(triangle.getKind(), TriangleKind.ISOSCELES);
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ @Test
|
|
|
43
|
+ public void isoscelesTrianglesHaveInFactExactlyTwoSidesEqual() throws Exception {
|
|
|
44
|
+ Triangle triangle = new Triangle(10, 10, 2);
|
|
|
45
|
+
|
|
|
46
|
+ assertEquals(triangle.getKind(), TriangleKind.ISOSCELES);
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ @Test
|
|
|
50
|
+ public void scaleneTrianglesHaveNoEqualSides() throws Exception {
|
|
|
51
|
+ Triangle triangle = new Triangle(3, 4, 5);
|
|
|
52
|
+
|
|
|
53
|
+ assertEquals(triangle.getKind(), TriangleKind.SCALENE);
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ @Test
|
|
|
57
|
+ public void scaleneTrianglesHaveNoEqualSidesAtLargerScaleEither() throws Exception {
|
|
|
58
|
+ Triangle triangle = new Triangle(10, 11, 12);
|
|
|
59
|
+
|
|
|
60
|
+ assertEquals(triangle.getKind(), TriangleKind.SCALENE);
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ @Test
|
|
|
64
|
+ public void scaleneTrianglesHaveNoEqualSidesInDescendingOrderEither() throws Exception {
|
|
|
65
|
+ Triangle triangle = new Triangle(5, 4, 2);
|
|
|
66
|
+
|
|
|
67
|
+ assertEquals(triangle.getKind(), TriangleKind.SCALENE);
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ @Test
|
|
|
71
|
+ public void verySmallTrianglesAreLegal() throws Exception {
|
|
|
72
|
+ Triangle triangle = new Triangle(0.4, 0.6, 0.3);
|
|
|
73
|
+
|
|
|
74
|
+ assertEquals(triangle.getKind(), TriangleKind.SCALENE);
|
|
|
75
|
+ }
|
|
|
76
|
+
|
|
|
77
|
+ @Test(expected = TriangleException.class)
|
|
|
78
|
+ public void trianglesWithNoSizeAreIllegal() throws Exception {
|
|
|
79
|
+ new Triangle(0, 0, 0);
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ @Test(expected = TriangleException.class)
|
|
|
83
|
+ public void trianglesWithNegativeSidesAreIllegal() throws Exception {
|
|
|
84
|
+ new Triangle(3, 4, -5);
|
|
|
85
|
+ }
|
|
|
86
|
+
|
|
|
87
|
+ @Test(expected = TriangleException.class)
|
|
|
88
|
+ public void trianglesViolatingTriangleInequalityAreIllegal() throws Exception {
|
|
|
89
|
+ new Triangle(1, 1, 3);
|
|
|
90
|
+ }
|
|
|
91
|
+
|
|
|
92
|
+ @Test(expected = TriangleException.class)
|
|
|
93
|
+ public void trianglesViolatingTriangleInequalityAreIllegal2() throws Exception {
|
|
|
94
|
+ new Triangle(2, 4, 2);
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ @Test(expected = TriangleException.class)
|
|
|
98
|
+ public void trianglesViolatingTriangleInequalityAreIllegal3() throws Exception {
|
|
|
99
|
+ new Triangle(7, 3, 2);
|
|
|
100
|
+ }
|
|
|
101
|
+}
|