aboutsummaryrefslogtreecommitdiffstats
path: root/model-data/src
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <semerath@mit.bme.hu>2021-08-15 16:32:09 +0200
committerLibravatar OszkarSemerath <semerath@mit.bme.hu>2021-08-15 16:32:09 +0200
commit4ca66a207b7b7b7c17171aff2d6e7eb268419fdc (patch)
treef4b51b6af5a3be537a43c6c803243ce43f50b943 /model-data/src
parentTests for CollectionsUtil (diff)
downloadrefinery-4ca66a207b7b7b7c17171aff2d6e7eb268419fdc.tar.gz
refinery-4ca66a207b7b7b7c17171aff2d6e7eb268419fdc.tar.zst
refinery-4ca66a207b7b7b7c17171aff2d6e7eb268419fdc.zip
Tests for CollectionsUtil
Diffstat (limited to 'model-data/src')
-rw-r--r--model-data/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java46
1 files changed, 25 insertions, 21 deletions
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java
index ccc5cbeb..16368912 100644
--- a/model-data/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java
+++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/util/CollectionsUtilTests.java
@@ -12,62 +12,66 @@ import static org.eclipse.viatra.solver.data.util.CollectionsUtil.*;
12import static org.junit.jupiter.api.Assertions.assertEquals; 12import static org.junit.jupiter.api.Assertions.assertEquals;
13 13
14class CollectionsUtilTests { 14class CollectionsUtilTests {
15 List<Integer> list10 = List.of(1,2,3,4,5,6,7,8,9,10); 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"); 16 List<String> listTen = List.of("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
17 17
18 private static <T> void compare(Iterable<T> a, Iterable<T> b) { 18 private static <T> void compare(Iterable<T> a, Iterable<T> b) {
19 List<T> listA = toList(a); 19 List<T> listA = toList(a);
20 List<T> listB = toList(b); 20 List<T> listB = toList(b);
21 assertEquals(listA, listB); 21 assertEquals(listA, listB);
22 } 22 }
23
23 private static <T> List<T> toList(Iterable<T> a) { 24 private static <T> List<T> toList(Iterable<T> a) {
24 List<T> result = new ArrayList<T>(); 25 List<T> result = new ArrayList<T>();
25 Iterator<T> iterator = a.iterator(); 26 Iterator<T> iterator = a.iterator();
26 while(iterator.hasNext()) { 27 while (iterator.hasNext()) {
27 result.add(iterator.next()); 28 result.add(iterator.next());
28 } 29 }
29 return result; 30 return result;
30 } 31 }
31 32
32 @Test 33 @Test
33 void testFilterEven() { 34 void testFilterEven() {
34 compare(List.of(2,4,6,8,10), filter(list10, (x->x%2==0))); 35 compare(List.of(2, 4, 6, 8, 10), filter(list10, (x -> x % 2 == 0)));
35 } 36 }
36 37
37 @Test 38 @Test
38 void testFilterOdd() { 39 void testFilterOdd() {
39 compare(List.of(1,3,5,7,9), filter(list10, (x->x%2==1))); 40 compare(List.of(1, 3, 5, 7, 9), filter(list10, (x -> x % 2 == 1)));
40 } 41 }
41 42
42 @Test 43 @Test
43 void testFilterFalse() { 44 void testFilterFalse() {
44 compare(List.of(), filter(list10, (x->false))); 45 compare(List.of(), filter(list10, (x -> false)));
45 } 46 }
46 47
47 @Test 48 @Test
48 void testFilterTrue() { 49 void testFilterTrue() {
49 compare(list10, filter(list10, (x->true))); 50 compare(list10, filter(list10, (x -> true)));
50 } 51 }
51 52
52 @Test 53 @Test
53 void testFilterEmpty() { 54 void testFilterEmpty() {
54 compare(List.of(), filter(List.of(), (x->true))); 55 compare(List.of(), filter(List.of(), (x -> true)));
55 } 56 }
56 57
57 @Test() 58 @Test()
58 void testNoSuchElement() { 59 void testNoSuchElement() {
59 Iterable<Integer> iterable = filter(list10, (x->x%2==0)); 60 Iterable<Integer> iterable = filter(list10, (x -> x % 2 == 0));
60 Iterator<Integer> iterator = iterable.iterator(); 61 Iterator<Integer> iterator = iterable.iterator();
61 while(iterator.hasNext()) { 62 while (iterator.hasNext()) {
62 iterator.next(); 63 iterator.next();
63 } 64 }
64 Assertions.assertThrows(NoSuchElementException.class, ()->iterator.next()); 65 Assertions.assertThrows(NoSuchElementException.class, () -> iterator.next());
65 } 66 }
66 67
68 @Test()
67 void mapTest() { 69 void mapTest() {
68 compare(listTen,map(list10, x->x.toString())); 70 compare(listTen, map(list10, x -> x.toString()));
69 } 71 }
72
73 @Test()
70 void mapEmtyTest() { 74 void mapEmtyTest() {
71 compare(List.of(),map(List.of(), x->x.toString())); 75 compare(List.of(), map(List.of(), x -> x.toString()));
72 } 76 }
73} 77}