diff options
author | 2021-09-29 02:45:57 +0200 | |
---|---|---|
committer | 2021-09-29 03:16:01 +0200 | |
commit | a155f6ba02e08a75ce6e474a86900b8363f506e8 (patch) | |
tree | b78804c1c0f0968a9625f0656e08f5dadc16924c /store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java | |
parent | Simplify branding (diff) | |
download | refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.tar.gz refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.tar.zst refinery-a155f6ba02e08a75ce6e474a86900b8363f506e8.zip |
build: migration to Gradle 7
Diffstat (limited to 'store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java')
-rw-r--r-- | store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java b/store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java new file mode 100644 index 00000000..16368912 --- /dev/null +++ b/store/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java | |||
@@ -0,0 +1,77 @@ | |||
1 | package org.eclipse.viatra.solver.data.util; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Iterator; | ||
5 | import java.util.List; | ||
6 | import java.util.NoSuchElementException; | ||
7 | |||
8 | import org.junit.jupiter.api.Assertions; | ||
9 | import org.junit.jupiter.api.Test; | ||
10 | |||
11 | import static org.eclipse.viatra.solver.data.util.CollectionsUtil.*; | ||
12 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
13 | |||
14 | class CollectionsUtilTests { | ||
15 | List<Integer> list10 = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | ||
16 | List<String> listTen = List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); | ||
17 | |||
18 | private static <T> void compare(Iterable<T> a, Iterable<T> b) { | ||
19 | List<T> listA = toList(a); | ||
20 | List<T> listB = toList(b); | ||
21 | assertEquals(listA, listB); | ||
22 | } | ||
23 | |||
24 | private static <T> List<T> toList(Iterable<T> a) { | ||
25 | List<T> result = new ArrayList<T>(); | ||
26 | Iterator<T> iterator = a.iterator(); | ||
27 | while (iterator.hasNext()) { | ||
28 | result.add(iterator.next()); | ||
29 | } | ||
30 | return result; | ||
31 | } | ||
32 | |||
33 | @Test | ||
34 | void testFilterEven() { | ||
35 | compare(List.of(2, 4, 6, 8, 10), filter(list10, (x -> x % 2 == 0))); | ||
36 | } | ||
37 | |||
38 | @Test | ||
39 | void testFilterOdd() { | ||
40 | compare(List.of(1, 3, 5, 7, 9), filter(list10, (x -> x % 2 == 1))); | ||
41 | } | ||
42 | |||
43 | @Test | ||
44 | void testFilterFalse() { | ||
45 | compare(List.of(), filter(list10, (x -> false))); | ||
46 | } | ||
47 | |||
48 | @Test | ||
49 | void testFilterTrue() { | ||
50 | compare(list10, filter(list10, (x -> true))); | ||
51 | } | ||
52 | |||
53 | @Test | ||
54 | void testFilterEmpty() { | ||
55 | compare(List.of(), filter(List.of(), (x -> true))); | ||
56 | } | ||
57 | |||
58 | @Test() | ||
59 | void testNoSuchElement() { | ||
60 | Iterable<Integer> iterable = filter(list10, (x -> x % 2 == 0)); | ||
61 | Iterator<Integer> iterator = iterable.iterator(); | ||
62 | while (iterator.hasNext()) { | ||
63 | iterator.next(); | ||
64 | } | ||
65 | Assertions.assertThrows(NoSuchElementException.class, () -> iterator.next()); | ||
66 | } | ||
67 | |||
68 | @Test() | ||
69 | void mapTest() { | ||
70 | compare(listTen, map(list10, x -> x.toString())); | ||
71 | } | ||
72 | |||
73 | @Test() | ||
74 | void mapEmtyTest() { | ||
75 | compare(List.of(), map(List.of(), x -> x.toString())); | ||
76 | } | ||
77 | } | ||