|
7 | 7 | import static fj.Ord.charOrd; |
8 | 8 | import static fj.data.List.list; |
9 | 9 | import static fj.data.List.range; |
10 | | -import static fj.test.Gen.pickCombinationWithReplacement; |
11 | | -import static fj.test.Gen.pickCombinationWithoutReplacement; |
12 | | -import static fj.test.Gen.pickPermutationWithReplacement; |
13 | | -import static fj.test.Gen.pickPermutationWithoutReplacement; |
| 10 | +import static fj.test.Gen.selectionOf; |
| 11 | +import static fj.test.Gen.combinationOf; |
| 12 | +import static fj.test.Gen.wordOf; |
| 13 | +import static fj.test.Gen.permutationOf; |
14 | 14 | import static fj.test.Rand.standard; |
15 | 15 | import static org.junit.Assert.assertEquals; |
16 | 16 | import static org.junit.Assert.assertTrue; |
17 | 17 |
|
18 | | -public final class TestGen { |
| 18 | +public final class GenTest { |
19 | 19 |
|
20 | 20 | private static final List<Character> AS = list('A', 'B', 'C'); |
21 | 21 |
|
22 | 22 | @Test |
23 | | - public void testPickCombinationWithoutReplacement_none() { |
24 | | - Gen<List<Character>> instance = pickCombinationWithoutReplacement(0, AS); |
| 23 | + public void testCombinationOf_none() { |
| 24 | + Gen<List<Character>> instance = combinationOf(0, AS); |
25 | 25 | testPick(100, instance, actual -> { |
26 | 26 | assertTrue(actual.isEmpty()); |
27 | 27 | }); |
28 | 28 | } |
29 | 29 |
|
30 | 30 | @Test |
31 | | - public void testPickCombinationWithoutReplacement_one() { |
32 | | - Gen<List<Character>> instance = pickCombinationWithoutReplacement(1, AS); |
| 31 | + public void testCombinationOf_one() { |
| 32 | + Gen<List<Character>> instance = combinationOf(1, AS); |
33 | 33 | testPick(100, instance, actual -> { |
34 | 34 | assertEquals(1, actual.length()); |
35 | 35 | assertTrue(AS.exists(a -> a.equals(actual.head()))); |
36 | 36 | }); |
37 | 37 | } |
38 | 38 |
|
39 | 39 | @Test |
40 | | - public void testPickCombinationWithoutReplacement_two() { |
41 | | - Gen<List<Character>> instance = pickCombinationWithoutReplacement(2, AS); |
| 40 | + public void testCombinationOf_two() { |
| 41 | + Gen<List<Character>> instance = combinationOf(2, AS); |
42 | 42 | testPick(100, instance, actual -> { |
43 | 43 | assertEquals(2, actual.length()); |
44 | 44 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -47,8 +47,8 @@ public void testPickCombinationWithoutReplacement_two() { |
47 | 47 | } |
48 | 48 |
|
49 | 49 | @Test |
50 | | - public void testPickCombinationWithoutReplacement_three() { |
51 | | - Gen<List<Character>> instance = pickCombinationWithoutReplacement(3, AS); |
| 50 | + public void testCombinationOf_three() { |
| 51 | + Gen<List<Character>> instance = combinationOf(3, AS); |
52 | 52 | testPick(100, instance, actual -> { |
53 | 53 | assertEquals(3, actual.length()); |
54 | 54 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -57,25 +57,25 @@ public void testPickCombinationWithoutReplacement_three() { |
57 | 57 | } |
58 | 58 |
|
59 | 59 | @Test |
60 | | - public void testPickCombinationWithReplacement_none() { |
61 | | - Gen<List<Character>> instance = pickCombinationWithReplacement(0, AS); |
| 60 | + public void testSelectionOf_none() { |
| 61 | + Gen<List<Character>> instance = selectionOf(0, AS); |
62 | 62 | testPick(100, instance, actual -> { |
63 | 63 | assertTrue(actual.isEmpty()); |
64 | 64 | }); |
65 | 65 | } |
66 | 66 |
|
67 | 67 | @Test |
68 | | - public void testPickCombinationWithReplacement_one() { |
69 | | - Gen<List<Character>> instance = pickCombinationWithReplacement(1, AS); |
| 68 | + public void testSelectionOf_one() { |
| 69 | + Gen<List<Character>> instance = selectionOf(1, AS); |
70 | 70 | testPick(100, instance, actual -> { |
71 | 71 | assertEquals(1, actual.length()); |
72 | 72 | assertTrue(AS.exists(a -> a.equals(actual.head()))); |
73 | 73 | }); |
74 | 74 | } |
75 | 75 |
|
76 | 76 | @Test |
77 | | - public void testPickCombinationWithReplacement_two() { |
78 | | - Gen<List<Character>> instance = pickCombinationWithReplacement(2, AS); |
| 77 | + public void testSelectionOf_two() { |
| 78 | + Gen<List<Character>> instance = selectionOf(2, AS); |
79 | 79 | testPick(100, instance, actual -> { |
80 | 80 | assertEquals(2, actual.length()); |
81 | 81 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -84,8 +84,8 @@ public void testPickCombinationWithReplacement_two() { |
84 | 84 | } |
85 | 85 |
|
86 | 86 | @Test |
87 | | - public void testPickCombinationWithReplacement_three() { |
88 | | - Gen<List<Character>> instance = pickCombinationWithReplacement(3, AS); |
| 87 | + public void testSelectionOf_three() { |
| 88 | + Gen<List<Character>> instance = selectionOf(3, AS); |
89 | 89 | testPick(100, instance, actual -> { |
90 | 90 | assertEquals(3, actual.length()); |
91 | 91 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -94,8 +94,8 @@ public void testPickCombinationWithReplacement_three() { |
94 | 94 | } |
95 | 95 |
|
96 | 96 | @Test |
97 | | - public void testPickCombinationWithReplacement_four() { |
98 | | - Gen<List<Character>> instance = pickCombinationWithReplacement(4, AS); |
| 97 | + public void testSelectionOf_four() { |
| 98 | + Gen<List<Character>> instance = selectionOf(4, AS); |
99 | 99 | testPick(100, instance, actual -> { |
100 | 100 | assertEquals(4, actual.length()); |
101 | 101 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -104,34 +104,34 @@ public void testPickCombinationWithReplacement_four() { |
104 | 104 | } |
105 | 105 |
|
106 | 106 | @Test |
107 | | - public void testPickPermutationWithoutReplacement_none() { |
108 | | - Gen<List<Character>> instance = pickPermutationWithoutReplacement(0, AS); |
| 107 | + public void testPermutationOf_none() { |
| 108 | + Gen<List<Character>> instance = permutationOf(0, AS); |
109 | 109 | testPick(100, instance, actual -> { |
110 | 110 | assertTrue(actual.isEmpty()); |
111 | 111 | }); |
112 | 112 | } |
113 | 113 |
|
114 | 114 | @Test |
115 | | - public void testPickPermutationWithoutReplacement_one() { |
116 | | - Gen<List<Character>> instance = pickPermutationWithoutReplacement(1, AS); |
| 115 | + public void testPermutationOf_one() { |
| 116 | + Gen<List<Character>> instance = permutationOf(1, AS); |
117 | 117 | testPick(100, instance, actual -> { |
118 | 118 | assertEquals(1, actual.length()); |
119 | 119 | assertTrue(AS.exists(a -> a.equals(actual.head()))); |
120 | 120 | }); |
121 | 121 | } |
122 | 122 |
|
123 | 123 | @Test |
124 | | - public void testPickPermutationWithoutReplacement_two() { |
125 | | - Gen<List<Character>> instance = pickCombinationWithoutReplacement(2, AS); |
| 124 | + public void testPermutationOf_two() { |
| 125 | + Gen<List<Character>> instance = combinationOf(2, AS); |
126 | 126 | testPick(100, instance, actual -> { |
127 | 127 | assertEquals(2, actual.length()); |
128 | 128 | assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !a.equals(l.head())))); |
129 | 129 | }); |
130 | 130 | } |
131 | 131 |
|
132 | 132 | @Test |
133 | | - public void testPickPermutationWithoutReplacement_three() { |
134 | | - Gen<List<Character>> instance = pickPermutationWithoutReplacement(3, AS); |
| 133 | + public void testPermutationOf_three() { |
| 134 | + Gen<List<Character>> instance = permutationOf(3, AS); |
135 | 135 | testPick(100, instance, actual -> { |
136 | 136 | assertEquals(3, actual.length()); |
137 | 137 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
@@ -140,51 +140,51 @@ public void testPickPermutationWithoutReplacement_three() { |
140 | 140 | } |
141 | 141 |
|
142 | 142 | @Test |
143 | | - public void testPickPermutationWithReplacement_none() { |
144 | | - Gen<List<Character>> instance = pickPermutationWithReplacement(0, AS); |
| 143 | + public void testWordOf_none() { |
| 144 | + Gen<List<Character>> instance = wordOf(0, AS); |
145 | 145 | testPick(100, instance, actual -> { |
146 | 146 | assertTrue(actual.isEmpty()); |
147 | 147 | }); |
148 | 148 | } |
149 | 149 |
|
150 | 150 | @Test |
151 | | - public void testPickPermutationWithReplacement_one() { |
152 | | - Gen<List<Character>> instance = pickPermutationWithReplacement(1, AS); |
| 151 | + public void testWordOf_one() { |
| 152 | + Gen<List<Character>> instance = wordOf(1, AS); |
153 | 153 | testPick(100, instance, actual -> { |
154 | 154 | assertEquals(1, actual.length()); |
155 | 155 | assertTrue(AS.exists(a -> a.equals(actual.head()))); |
156 | 156 | }); |
157 | 157 | } |
158 | 158 |
|
159 | 159 | @Test |
160 | | - public void testPickPermutationWithReplacement_two() { |
161 | | - Gen<List<Character>> instance = pickPermutationWithReplacement(2, AS); |
| 160 | + public void testWordOf_two() { |
| 161 | + Gen<List<Character>> instance = wordOf(2, AS); |
162 | 162 | testPick(100, instance, actual -> { |
163 | 163 | assertEquals(2, actual.length()); |
164 | 164 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
165 | 165 | }); |
166 | 166 | } |
167 | 167 |
|
168 | 168 | @Test |
169 | | - public void testPickPermutationWithReplacement_three() { |
170 | | - Gen<List<Character>> instance = pickPermutationWithReplacement(3, AS); |
| 169 | + public void testWordOf_three() { |
| 170 | + Gen<List<Character>> instance = wordOf(3, AS); |
171 | 171 | testPick(100, instance, actual -> { |
172 | 172 | assertEquals(3, actual.length()); |
173 | 173 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
174 | 174 | }); |
175 | 175 | } |
176 | 176 |
|
177 | 177 | @Test |
178 | | - public void testPickPermutationWithReplacement_four() { |
179 | | - Gen<List<Character>> instance = pickPermutationWithReplacement(4, AS); |
| 178 | + public void testWordOf_four() { |
| 179 | + Gen<List<Character>> instance = wordOf(4, AS); |
180 | 180 | testPick(100, instance, actual -> { |
181 | 181 | assertEquals(4, actual.length()); |
182 | 182 | assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); |
183 | 183 | }); |
184 | 184 | } |
185 | 185 |
|
186 | 186 | private static <A> void testPick(int n, Gen<List<A>> instance, Effect1<List<A>> test) { |
187 | | - range(0, n).map(i -> instance.gen(0, standard)).foreachDoEffect(test::f); |
| 187 | + range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test::f); |
188 | 188 | } |
189 | 189 |
|
190 | 190 | } |