|
1 | 1 | package fj.test;
|
2 | 2 |
|
| 3 | +import fj.Equal; |
3 | 4 | import fj.data.List;
|
| 5 | +import fj.data.NonEmptyList; |
| 6 | +import fj.data.Option; |
4 | 7 | import fj.data.Stream;
|
| 8 | +import fj.data.Validation; |
5 | 9 | import fj.function.Effect1;
|
6 | 10 | import org.junit.Test;
|
7 | 11 |
|
8 | 12 | import static fj.Ord.charOrd;
|
9 | 13 | import static fj.data.List.list;
|
10 | 14 | import static fj.data.List.range;
|
| 15 | +import static fj.data.NonEmptyList.nel; |
| 16 | +import static fj.data.Option.somes; |
| 17 | +import static fj.data.Validation.fail; |
| 18 | +import static fj.data.Validation.success; |
11 | 19 | import static fj.test.Gen.combinationOf;
|
| 20 | +import static fj.test.Gen.listOf; |
12 | 21 | import static fj.test.Gen.permutationOf;
|
13 | 22 | import static fj.test.Gen.pickOne;
|
14 | 23 | import static fj.test.Gen.selectionOf;
|
| 24 | +import static fj.test.Gen.sequence; |
15 | 25 | import static fj.test.Gen.streamOf;
|
16 | 26 | import static fj.test.Gen.wordOf;
|
17 | 27 | import static fj.test.Rand.standard;
|
@@ -187,6 +197,15 @@ public void testStreamOf() {
|
187 | 197 | });
|
188 | 198 | }
|
189 | 199 |
|
| 200 | + @Test |
| 201 | + public void testSequenceValidation() { |
| 202 | + final Gen<List<Validation<NonEmptyList<Exception>, Character>>> success = listOf(sequence(success(pickOne(AS))), 4); |
| 203 | + testPick(100, success, list -> assertEquals(list.length(),somes(list.map(v -> Option.sequence(v.map(c -> AS.elementIndex(Equal.anyEqual(), c))))).length())); |
| 204 | + |
| 205 | + final Gen<List<Validation<NonEmptyList<Exception>, Gen<Character>>>> failure = listOf(sequence(fail(nel(new Exception()))), 4); |
| 206 | + testPick(100, failure, list -> assertTrue(list.forall(a -> a.isFail()))); |
| 207 | + } |
| 208 | + |
190 | 209 | private static <A> void testPick(int n, Gen<List<A>> instance, Effect1<List<A>> test) {
|
191 | 210 | range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test);
|
192 | 211 | }
|
|
0 commit comments