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