diff options
Diffstat (limited to 'subprojects/store/src/test/java/tools')
2 files changed, 187 insertions, 0 deletions
diff --git a/subprojects/store/src/test/java/tools/refinery/store/statecoding/ExperimentalSetupTest.java b/subprojects/store/src/test/java/tools/refinery/store/statecoding/ExperimentalSetupTest.java new file mode 100644 index 00000000..87b1623c --- /dev/null +++ b/subprojects/store/src/test/java/tools/refinery/store/statecoding/ExperimentalSetupTest.java | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.statecoding; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | import tools.refinery.store.map.Version; | ||
10 | import tools.refinery.store.model.ModelStore; | ||
11 | import tools.refinery.store.representation.Symbol; | ||
12 | import tools.refinery.store.tuple.Tuple; | ||
13 | |||
14 | import java.util.*; | ||
15 | |||
16 | class ExperimentalSetupTest { | ||
17 | public static void generate(int size) { | ||
18 | Symbol<Boolean> person = new Symbol<>("Person", 1, Boolean.class, false); | ||
19 | Symbol<Boolean> friend = new Symbol<>("friend", 2, Boolean.class, false); | ||
20 | |||
21 | var store = ModelStore.builder() | ||
22 | .symbols(person, friend) | ||
23 | .with(StateCoderAdapter | ||
24 | .builder()) | ||
25 | .build(); | ||
26 | |||
27 | Set<Version> versions = new HashSet<>(); | ||
28 | Map<Integer, List<Version>> codes = new HashMap<>(); | ||
29 | |||
30 | var empty = store.createEmptyModel(); | ||
31 | var pI = empty.getInterpretation(person); | ||
32 | |||
33 | for (int i = 0; i < size; i++) { | ||
34 | pI.put(Tuple.of(i), true); | ||
35 | } | ||
36 | |||
37 | var emptyVersion = empty.commit(); | ||
38 | versions.add(emptyVersion); | ||
39 | var emptyCode = empty.getAdapter(StateCoderAdapter.class).calculateModelCode(); | ||
40 | List<Version> emptyList = new ArrayList<>(); | ||
41 | emptyList.add(emptyVersion); | ||
42 | codes.put(emptyCode, emptyList); | ||
43 | |||
44 | var storeAdapter = store.getAdapter(StateCoderStoreAdapter.class); | ||
45 | |||
46 | int dif = 0; | ||
47 | int iso = 0; | ||
48 | int unk = 0; | ||
49 | |||
50 | //int step = 0 | ||
51 | |||
52 | for (int i = 0; i < size; i++) { | ||
53 | for (int j = 0; j < size; j++) { | ||
54 | var previousVersions = new HashSet<>(versions); | ||
55 | for (var version : previousVersions) { | ||
56 | |||
57 | var model = store.createModelForState(version); | ||
58 | model.getInterpretation(friend).put(Tuple.of(i, j), true); | ||
59 | |||
60 | Version version1 = model.commit(); | ||
61 | var stateCode = model.getAdapter(StateCoderAdapter.class).calculateStateCode(); | ||
62 | int code = stateCode.modelCode(); | ||
63 | //System.out.println(step+++" ->" +code); | ||
64 | if (codes.containsKey(code)) { | ||
65 | Version similar = codes.get(code).get(0); | ||
66 | |||
67 | var outcome = storeAdapter.checkEquivalence(version1, similar); | ||
68 | if (outcome == StateEquivalenceChecker.EquivalenceResult.DIFFERENT) { | ||
69 | System.out.println(); | ||
70 | var c = model.getInterpretation(friend).getAll(); | ||
71 | while (c.move()) { | ||
72 | System.out.println(c.getKey().toString()); | ||
73 | } | ||
74 | System.out.println("vs"); | ||
75 | var c2 = store.createModelForState(similar).getInterpretation(friend).getAll(); | ||
76 | while (c2.move()) { | ||
77 | System.out.println(c2.getKey().toString()); | ||
78 | } | ||
79 | |||
80 | dif++; | ||
81 | } else if (outcome == StateEquivalenceChecker.EquivalenceResult.UNKNOWN) { | ||
82 | unk++; | ||
83 | } else { | ||
84 | iso++; | ||
85 | } | ||
86 | } else { | ||
87 | versions.add(version1); | ||
88 | |||
89 | List<Version> newList = new ArrayList<>(); | ||
90 | newList.add(version1); | ||
91 | codes.put(code, newList); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | System.out.printf("v=%d i=%d d=%d u=%d\n", versions.size(), iso, dif, unk); | ||
98 | } | ||
99 | |||
100 | @Test | ||
101 | void runTests() { | ||
102 | for (int i = 0; i < 5; i++) { | ||
103 | System.out.println("size = " + i); | ||
104 | generate(i); | ||
105 | } | ||
106 | } | ||
107 | } | ||
diff --git a/subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java b/subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java new file mode 100644 index 00000000..b0b80af7 --- /dev/null +++ b/subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.statecoding; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | import tools.refinery.store.model.Interpretation; | ||
10 | import tools.refinery.store.model.ModelStore; | ||
11 | import tools.refinery.store.representation.Symbol; | ||
12 | import tools.refinery.store.tuple.Tuple; | ||
13 | |||
14 | import static org.junit.jupiter.api.Assertions.*; | ||
15 | |||
16 | class StateCoderBuildTest { | ||
17 | Symbol<Boolean> person = new Symbol<>("Person", 1, Boolean.class, false); | ||
18 | Symbol<Integer> age = new Symbol<>("age", 1, Integer.class, null); | ||
19 | Symbol<Boolean> friend = new Symbol<>("friend", 2, Boolean.class, false); | ||
20 | |||
21 | @Test | ||
22 | void simpleStateCoderTest() { | ||
23 | var store = ModelStore.builder() | ||
24 | .symbols(person, age, friend) | ||
25 | .with(StateCoderAdapter | ||
26 | .builder()) | ||
27 | .build(); | ||
28 | |||
29 | var model = store.createEmptyModel(); | ||
30 | var stateCoder = model.getAdapter(StateCoderAdapter.class); | ||
31 | assertNotNull(stateCoder); | ||
32 | |||
33 | var personI = model.getInterpretation(person); | ||
34 | var friendI = model.getInterpretation(friend); | ||
35 | var ageI = model.getInterpretation(age); | ||
36 | fill(personI, friendI, ageI); | ||
37 | |||
38 | stateCoder.calculateStateCode(); | ||
39 | } | ||
40 | |||
41 | @Test | ||
42 | void excludeTest() { | ||
43 | var store = ModelStore.builder() | ||
44 | .symbols(person, age, friend) | ||
45 | .with(StateCoderAdapter.builder() | ||
46 | .exclude(person) | ||
47 | .exclude(age)) | ||
48 | .build(); | ||
49 | |||
50 | var model = store.createEmptyModel(); | ||
51 | var stateCoder = model.getAdapter(StateCoderAdapter.class); | ||
52 | assertNotNull(stateCoder); | ||
53 | |||
54 | var personI = model.getInterpretation(person); | ||
55 | var friendI = model.getInterpretation(friend); | ||
56 | var ageI = model.getInterpretation(age); | ||
57 | fill(personI, friendI, ageI); | ||
58 | |||
59 | int code = stateCoder.calculateStateCode().modelCode(); | ||
60 | |||
61 | ageI.put(Tuple.of(1),3); | ||
62 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | ||
63 | |||
64 | ageI.put(Tuple.of(1),null); | ||
65 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | ||
66 | |||
67 | personI.put(Tuple.of(2),false); | ||
68 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | ||
69 | } | ||
70 | |||
71 | private static void fill(Interpretation<Boolean> personI, Interpretation<Boolean> friendI, Interpretation<Integer> ageI) { | ||
72 | personI.put(Tuple.of(1), true); | ||
73 | personI.put(Tuple.of(2), true); | ||
74 | |||
75 | ageI.put(Tuple.of(1), 5); | ||
76 | ageI.put(Tuple.of(2), 4); | ||
77 | |||
78 | friendI.put(Tuple.of(1, 2), true); | ||
79 | } | ||
80 | } | ||