|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
|
2
|
+import java.util.Arrays;
|
|
|
3
|
+import java.util.HashMap;
|
|
|
4
|
+import java.util.List;
|
|
|
5
|
+import java.util.Map;
|
|
|
6
|
+import java.util.stream.Collectors;
|
|
|
7
|
+import static org.junit.Assert.assertEquals;
|
|
|
8
|
+import static org.junit.Assert.assertFalse;
|
|
|
9
|
+import static org.junit.Assert.assertTrue;
|
|
|
10
|
+import org.junit.Test;
|
|
|
11
|
+import org.junit.Ignore;
|
|
|
12
|
+
|
|
|
13
|
+public class PythagoreanTripletTest {
|
|
|
14
|
+
|
|
|
15
|
+ @Test
|
|
|
16
|
+ public void shouldCalculateSum() {
|
|
|
17
|
+ PythagoreanTriplet sut = new PythagoreanTriplet(3, 4, 5);
|
|
|
18
|
+ final int expected = 12;
|
|
|
19
|
+ final int actual = sut.calculateSum();
|
|
|
20
|
+ assertEquals(expected, actual);
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ @Test
|
|
|
24
|
+ @Ignore
|
|
|
25
|
+ public void shouldCalculateProduct() {
|
|
|
26
|
+ PythagoreanTriplet sut = new PythagoreanTriplet(3, 4, 5);
|
|
|
27
|
+ final long expected = 60l;
|
|
|
28
|
+ final long actual = sut.calculateProduct();
|
|
|
29
|
+ assertEquals(expected, actual);
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
|
32
|
+ @Test
|
|
|
33
|
+ @Ignore
|
|
|
34
|
+ public void testIsPythagoreanOK() {
|
|
|
35
|
+ PythagoreanTriplet sut = new PythagoreanTriplet(3, 4, 5);
|
|
|
36
|
+ assertTrue(sut.isPythagorean());
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ @Test
|
|
|
40
|
+ @Ignore
|
|
|
41
|
+ public void testIsPythagoreanFail() {
|
|
|
42
|
+ PythagoreanTriplet sut = new PythagoreanTriplet(5, 6, 7);
|
|
|
43
|
+ assertFalse(sut.isPythagorean());
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ @Test
|
|
|
47
|
+ @Ignore
|
|
|
48
|
+ public void shouldMakeTripletsUpToTen() {
|
|
|
49
|
+ final List<Long> actual
|
|
|
50
|
+ = PythagoreanTriplet
|
|
|
51
|
+ .makeTripletsList()
|
|
|
52
|
+ .withFactorsLessThanOrEqualTo(10)
|
|
|
53
|
+ .build()
|
|
|
54
|
+ .stream()
|
|
|
55
|
+ .map(t -> t.calculateProduct())
|
|
|
56
|
+ .sorted()
|
|
|
57
|
+ .collect(Collectors.toList());
|
|
|
58
|
+ final List<Long> expected = Arrays.asList(60l, 480l);
|
|
|
59
|
+ assertEquals(expected, actual);
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+ @Test
|
|
|
63
|
+ @Ignore
|
|
|
64
|
+ public void shouldMakeTripletsElevenToTwenty() {
|
|
|
65
|
+ final List<Long> actual
|
|
|
66
|
+ = PythagoreanTriplet
|
|
|
67
|
+ .makeTripletsList()
|
|
|
68
|
+ .withFactorsGreaterThanOrEqualTo(11)
|
|
|
69
|
+ .withFactorsLessThanOrEqualTo(20)
|
|
|
70
|
+ .build()
|
|
|
71
|
+ .stream()
|
|
|
72
|
+ .map(t -> t.calculateProduct())
|
|
|
73
|
+ .sorted((p1, p2) -> Double.compare(p1, p2))
|
|
|
74
|
+ .collect(Collectors.toList());
|
|
|
75
|
+ final List<Long> expected = Arrays.asList(3840l);
|
|
|
76
|
+ assertEquals(expected, actual);
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Test
|
|
|
80
|
+ @Ignore
|
|
|
81
|
+ public void shouldMakeTripletsAndFilterOnSum() {
|
|
|
82
|
+ final List<Long> actual
|
|
|
83
|
+ = PythagoreanTriplet
|
|
|
84
|
+ .makeTripletsList()
|
|
|
85
|
+ .withFactorsLessThanOrEqualTo(100)
|
|
|
86
|
+ .thatSumTo(180)
|
|
|
87
|
+ .build()
|
|
|
88
|
+ .stream()
|
|
|
89
|
+ .map(t -> t.calculateProduct())
|
|
|
90
|
+ .sorted((p1, p2) -> Double.compare(p1, p2))
|
|
|
91
|
+ .collect(Collectors.toList());
|
|
|
92
|
+ final List<Long> expected = Arrays.asList(118080l, 168480l, 202500l);
|
|
|
93
|
+ assertEquals(expected, actual);
|
|
|
94
|
+ }
|
|
|
95
|
+}
|