diff options
author | 2021-08-16 02:17:38 +0200 | |
---|---|---|
committer | 2021-08-16 02:17:38 +0200 | |
commit | d2e4318d1ed4c88e65f96bbf591638d1de3293fa (patch) | |
tree | 3e48ef2ab8ad607e467e9db2581c3de619d2667b /model-data | |
parent | Basic Model building tests (diff) | |
download | refinery-d2e4318d1ed4c88e65f96bbf591638d1de3293fa.tar.gz refinery-d2e4318d1ed4c88e65f96bbf591638d1de3293fa.tar.zst refinery-d2e4318d1ed4c88e65f96bbf591638d1de3293fa.zip |
:lipstick:
Diffstat (limited to 'model-data')
-rw-r--r-- | model-data/src/test/java/org/eclipse/viatra/solver/data/model/tests/ModelTest.java | 114 |
1 files changed, 56 insertions, 58 deletions
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/model/tests/ModelTest.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/model/tests/ModelTest.java index dacea35d..c9bf3da9 100644 --- a/model-data/src/test/java/org/eclipse/viatra/solver/data/model/tests/ModelTest.java +++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/model/tests/ModelTest.java | |||
@@ -15,135 +15,133 @@ import org.junit.jupiter.api.Assertions; | |||
15 | import org.junit.jupiter.api.Test; | 15 | import org.junit.jupiter.api.Test; |
16 | 16 | ||
17 | class ModelTest { | 17 | class ModelTest { |
18 | 18 | ||
19 | @Test | 19 | @Test |
20 | void modelConstructionTest() { | 20 | void modelConstructionTest() { |
21 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 21 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
22 | Relation<Boolean> friend = new Relation<>("friend", 2, false); | 22 | Relation<Boolean> friend = new Relation<>("friend", 2, false); |
23 | 23 | ||
24 | ModelStore store = new ModelStoreImpl(Set.of(person,friend)); | 24 | ModelStore store = new ModelStoreImpl(Set.of(person, friend)); |
25 | Model model = store.createModel(); | 25 | Model model = store.createModel(); |
26 | 26 | ||
27 | assertTrue(store.getDataRepresentations().contains(person)); | 27 | assertTrue(store.getDataRepresentations().contains(person)); |
28 | assertTrue(store.getDataRepresentations().contains(friend)); | 28 | assertTrue(store.getDataRepresentations().contains(friend)); |
29 | assertTrue(model.getDataRepresentations().contains(person)); | 29 | assertTrue(model.getDataRepresentations().contains(person)); |
30 | assertTrue(model.getDataRepresentations().contains(friend)); | 30 | assertTrue(model.getDataRepresentations().contains(friend)); |
31 | 31 | ||
32 | Relation<Integer> other = new Relation<Integer>("other", 2, null); | 32 | Relation<Integer> other = new Relation<Integer>("other", 2, null); |
33 | assertFalse(model.getDataRepresentations().contains(other)); | 33 | assertFalse(model.getDataRepresentations().contains(other)); |
34 | } | 34 | } |
35 | 35 | ||
36 | @Test | 36 | @Test |
37 | void modelBuildingTest() { | 37 | void modelBuildingTest() { |
38 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 38 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
39 | Relation<Integer> age = new Relation<Integer>("age", 1, null); | 39 | Relation<Integer> age = new Relation<Integer>("age", 1, null); |
40 | Relation<Boolean> friend = new Relation<>("friend", 2, false); | 40 | Relation<Boolean> friend = new Relation<>("friend", 2, false); |
41 | 41 | ||
42 | ModelStore store = new ModelStoreImpl(Set.of(person,age,friend)); | 42 | ModelStore store = new ModelStoreImpl(Set.of(person, age, friend)); |
43 | Model model = store.createModel(); | 43 | Model model = store.createModel(); |
44 | 44 | ||
45 | model.put(person, Tuple.of(0), true); | 45 | model.put(person, Tuple.of(0), true); |
46 | model.put(person, Tuple.of(1), true); | 46 | model.put(person, Tuple.of(1), true); |
47 | model.put(age, Tuple.of(0), 3); | 47 | model.put(age, Tuple.of(0), 3); |
48 | model.put(age, Tuple.of(1), 1); | 48 | model.put(age, Tuple.of(1), 1); |
49 | model.put(friend, Tuple.of(0,1), true); | 49 | model.put(friend, Tuple.of(0, 1), true); |
50 | model.put(friend, Tuple.of(1,0), true); | 50 | model.put(friend, Tuple.of(1, 0), true); |
51 | 51 | ||
52 | assertTrue(model.get(person, Tuple.of(0))); | 52 | assertTrue(model.get(person, Tuple.of(0))); |
53 | assertTrue(model.get(person, Tuple.of(1))); | 53 | assertTrue(model.get(person, Tuple.of(1))); |
54 | assertFalse(model.get(person, Tuple.of(2))); | 54 | assertFalse(model.get(person, Tuple.of(2))); |
55 | 55 | ||
56 | assertEquals(3, model.get(age, Tuple.of(0))); | 56 | assertEquals(3, model.get(age, Tuple.of(0))); |
57 | assertEquals(1, model.get(age, Tuple.of(1))); | 57 | assertEquals(1, model.get(age, Tuple.of(1))); |
58 | assertEquals(null, model.get(age, Tuple.of(2))); | 58 | assertEquals(null, model.get(age, Tuple.of(2))); |
59 | 59 | ||
60 | assertTrue(model.get(friend, Tuple.of(0,1))); | 60 | assertTrue(model.get(friend, Tuple.of(0, 1))); |
61 | assertFalse(model.get(friend, Tuple.of(0,5))); | 61 | assertFalse(model.get(friend, Tuple.of(0, 5))); |
62 | } | 62 | } |
63 | 63 | ||
64 | @Test | 64 | @Test |
65 | void modelBuildingArityFailTest() { | 65 | void modelBuildingArityFailTest() { |
66 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 66 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
67 | ModelStore store = new ModelStoreImpl(Set.of(person)); | 67 | ModelStore store = new ModelStoreImpl(Set.of(person)); |
68 | Model model = store.createModel(); | 68 | Model model = store.createModel(); |
69 | 69 | ||
70 | final Tuple tuple3 = Tuple.of(1,1,1); | 70 | final Tuple tuple3 = Tuple.of(1, 1, 1); |
71 | Assertions.assertThrows(IllegalArgumentException.class, ()-> model.put(person, tuple3, true)); | 71 | Assertions.assertThrows(IllegalArgumentException.class, () -> model.put(person, tuple3, true)); |
72 | Assertions.assertThrows(IllegalArgumentException.class, ()-> model.get(person, tuple3)); | 72 | Assertions.assertThrows(IllegalArgumentException.class, () -> model.get(person, tuple3)); |
73 | } | 73 | } |
74 | 74 | ||
75 | @Test | 75 | @Test |
76 | void modelBuildingNullFailTest() { | 76 | void modelBuildingNullFailTest() { |
77 | Relation<Integer> age = new Relation<Integer>("age", 1, null); | 77 | Relation<Integer> age = new Relation<Integer>("age", 1, null); |
78 | ModelStore store = new ModelStoreImpl(Set.of(age)); | 78 | ModelStore store = new ModelStoreImpl(Set.of(age)); |
79 | Model model = store.createModel(); | 79 | Model model = store.createModel(); |
80 | 80 | ||
81 | //final Tuple tuple3 = Tuple.of(1,1,1); | ||
82 | |||
83 | model.put(age, Tuple.of(1), null); // valid | 81 | model.put(age, Tuple.of(1), null); // valid |
84 | Assertions.assertThrows(IllegalArgumentException.class, ()-> model.put(age, null, 1)); | 82 | Assertions.assertThrows(IllegalArgumentException.class, () -> model.put(age, null, 1)); |
85 | Assertions.assertThrows(IllegalArgumentException.class, ()-> model.get(age, null)); | 83 | Assertions.assertThrows(IllegalArgumentException.class, () -> model.get(age, null)); |
86 | 84 | ||
87 | } | 85 | } |
88 | 86 | ||
89 | @Test | 87 | @Test |
90 | void modelUpdateTest() { | 88 | void modelUpdateTest() { |
91 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 89 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
92 | Relation<Integer> age = new Relation<Integer>("age", 1, null); | 90 | Relation<Integer> age = new Relation<Integer>("age", 1, null); |
93 | Relation<Boolean> friend = new Relation<>("friend", 2, false); | 91 | Relation<Boolean> friend = new Relation<>("friend", 2, false); |
94 | 92 | ||
95 | ModelStore store = new ModelStoreImpl(Set.of(person,age,friend)); | 93 | ModelStore store = new ModelStoreImpl(Set.of(person, age, friend)); |
96 | Model model = store.createModel(); | 94 | Model model = store.createModel(); |
97 | 95 | ||
98 | model.put(person, Tuple.of(0), true); | 96 | model.put(person, Tuple.of(0), true); |
99 | model.put(person, Tuple.of(1), true); | 97 | model.put(person, Tuple.of(1), true); |
100 | model.put(age, Tuple.of(0), 3); | 98 | model.put(age, Tuple.of(0), 3); |
101 | model.put(age, Tuple.of(1), 1); | 99 | model.put(age, Tuple.of(1), 1); |
102 | model.put(friend, Tuple.of(0,1), true); | 100 | model.put(friend, Tuple.of(0, 1), true); |
103 | model.put(friend, Tuple.of(1,0), true); | 101 | model.put(friend, Tuple.of(1, 0), true); |
104 | 102 | ||
105 | assertEquals(3, model.get(age, Tuple.of(0))); | 103 | assertEquals(3, model.get(age, Tuple.of(0))); |
106 | assertTrue(model.get(friend, Tuple.of(0,1))); | 104 | assertTrue(model.get(friend, Tuple.of(0, 1))); |
107 | 105 | ||
108 | model.put(age, Tuple.of(0), 4); | 106 | model.put(age, Tuple.of(0), 4); |
109 | model.put(friend, Tuple.of(0,1), false); | 107 | model.put(friend, Tuple.of(0, 1), false); |
110 | 108 | ||
111 | assertEquals(4, model.get(age, Tuple.of(0))); | 109 | assertEquals(4, model.get(age, Tuple.of(0))); |
112 | assertFalse(model.get(friend, Tuple.of(0,1))); | 110 | assertFalse(model.get(friend, Tuple.of(0, 1))); |
113 | } | 111 | } |
114 | 112 | ||
115 | @Test | 113 | @Test |
116 | void restoreTest() { | 114 | void restoreTest() { |
117 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 115 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); |
118 | Relation<Boolean> friend = new Relation<Boolean>("friend", 2, false); | 116 | Relation<Boolean> friend = new Relation<Boolean>("friend", 2, false); |
119 | 117 | ||
120 | ModelStore store = new ModelStoreImpl(Set.of(person,friend)); | 118 | ModelStore store = new ModelStoreImpl(Set.of(person, friend)); |
121 | Model model = store.createModel(); | 119 | Model model = store.createModel(); |
122 | 120 | ||
123 | model.put(person, Tuple.of(0), true); | 121 | model.put(person, Tuple.of(0), true); |
124 | model.put(person, Tuple.of(1), true); | 122 | model.put(person, Tuple.of(1), true); |
125 | model.put(friend, Tuple.of(0,1), true); | 123 | model.put(friend, Tuple.of(0, 1), true); |
126 | model.put(friend, Tuple.of(1,0), true); | 124 | model.put(friend, Tuple.of(1, 0), true); |
127 | long state1 = model.commit(); | 125 | long state1 = model.commit(); |
128 | 126 | ||
129 | assertFalse(model.get(person, Tuple.of(2))); | 127 | assertFalse(model.get(person, Tuple.of(2))); |
130 | assertFalse(model.get(friend, Tuple.of(0,2))); | 128 | assertFalse(model.get(friend, Tuple.of(0, 2))); |
131 | 129 | ||
132 | model.put(person, Tuple.of(2), true); | 130 | model.put(person, Tuple.of(2), true); |
133 | model.put(friend, Tuple.of(0,2), true); | 131 | model.put(friend, Tuple.of(0, 2), true); |
134 | long state2 = model.commit(); | 132 | long state2 = model.commit(); |
135 | 133 | ||
136 | assertTrue(model.get(person, Tuple.of(2))); | 134 | assertTrue(model.get(person, Tuple.of(2))); |
137 | assertTrue(model.get(friend, Tuple.of(0,2))); | 135 | assertTrue(model.get(friend, Tuple.of(0, 2))); |
138 | 136 | ||
139 | model.restore(state1); | 137 | model.restore(state1); |
140 | 138 | ||
141 | assertFalse(model.get(person, Tuple.of(2))); | 139 | assertFalse(model.get(person, Tuple.of(2))); |
142 | assertFalse(model.get(friend, Tuple.of(0,2))); | 140 | assertFalse(model.get(friend, Tuple.of(0, 2))); |
143 | 141 | ||
144 | model.restore(state2); | 142 | model.restore(state2); |
145 | 143 | ||
146 | assertTrue(model.get(person, Tuple.of(2))); | 144 | assertTrue(model.get(person, Tuple.of(2))); |
147 | assertTrue(model.get(friend, Tuple.of(0,2))); | 145 | assertTrue(model.get(friend, Tuple.of(0, 2))); |
148 | } | 146 | } |
149 | } | 147 | } |