diff options
-rw-r--r-- | subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java | 74 |
1 files changed, 60 insertions, 14 deletions
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 index a4e953ea..0b738005 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/statecoding/StateCoderBuildTest.java | |||
@@ -58,14 +58,14 @@ class StateCoderBuildTest { | |||
58 | 58 | ||
59 | int code = stateCoder.calculateStateCode().modelCode(); | 59 | int code = stateCoder.calculateStateCode().modelCode(); |
60 | 60 | ||
61 | ageI.put(Tuple.of(1),3); | 61 | ageI.put(Tuple.of(1), 3); |
62 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | 62 | assertEquals(code, stateCoder.calculateStateCode().modelCode()); |
63 | 63 | ||
64 | ageI.put(Tuple.of(1),null); | 64 | ageI.put(Tuple.of(1), null); |
65 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | 65 | assertEquals(code, stateCoder.calculateStateCode().modelCode()); |
66 | 66 | ||
67 | personI.put(Tuple.of(2),false); | 67 | personI.put(Tuple.of(2), false); |
68 | assertEquals(code,stateCoder.calculateStateCode().modelCode()); | 68 | assertEquals(code, stateCoder.calculateStateCode().modelCode()); |
69 | } | 69 | } |
70 | 70 | ||
71 | @Test | 71 | @Test |
@@ -80,14 +80,14 @@ class StateCoderBuildTest { | |||
80 | 80 | ||
81 | var friendI = model.getInterpretation(friend); | 81 | var friendI = model.getInterpretation(friend); |
82 | 82 | ||
83 | friendI.put(Tuple.of(1,2),true); | 83 | friendI.put(Tuple.of(1, 2), true); |
84 | int code1 = stateCoder.calculateModelCode(); | 84 | int code1 = stateCoder.calculateModelCode(); |
85 | 85 | ||
86 | friendI.put(Tuple.of(1,2),false); | 86 | friendI.put(Tuple.of(1, 2), false); |
87 | friendI.put(Tuple.of(2,1),true); | 87 | friendI.put(Tuple.of(2, 1), true); |
88 | int code2 = stateCoder.calculateModelCode(); | 88 | int code2 = stateCoder.calculateModelCode(); |
89 | 89 | ||
90 | assertEquals(code1,code2); | 90 | assertEquals(code1, code2); |
91 | } | 91 | } |
92 | 92 | ||
93 | @Test | 93 | @Test |
@@ -103,16 +103,62 @@ class StateCoderBuildTest { | |||
103 | 103 | ||
104 | var friendI = model.getInterpretation(friend); | 104 | var friendI = model.getInterpretation(friend); |
105 | 105 | ||
106 | friendI.put(Tuple.of(1,2),true); | 106 | friendI.put(Tuple.of(1, 2), true); |
107 | int code1 = stateCoder.calculateModelCode(); | 107 | int code1 = stateCoder.calculateModelCode(); |
108 | 108 | ||
109 | friendI.put(Tuple.of(1,2),false); | 109 | friendI.put(Tuple.of(1, 2), false); |
110 | friendI.put(Tuple.of(2,1),true); | 110 | friendI.put(Tuple.of(2, 1), true); |
111 | int code2 = stateCoder.calculateModelCode(); | 111 | int code2 = stateCoder.calculateModelCode(); |
112 | 112 | ||
113 | assertNotEquals(code1,code2); | 113 | assertNotEquals(code1, code2); |
114 | } | 114 | } |
115 | 115 | ||
116 | @Test | ||
117 | void customStateCoderTest() { | ||
118 | final boolean[] called = new boolean[]{false}; | ||
119 | StateCodeCalculator mock = () -> { | ||
120 | called[0] = true; | ||
121 | return null; | ||
122 | }; | ||
123 | |||
124 | var store = ModelStore.builder() | ||
125 | .symbols(friend) | ||
126 | .with(StateCoderAdapter.builder() | ||
127 | .stateCodeCalculatorFactory((interpretations, individuals) -> mock)) | ||
128 | .build(); | ||
129 | |||
130 | var model = store.createEmptyModel(); | ||
131 | var stateCoder = model.getAdapter(StateCoderAdapter.class); | ||
132 | |||
133 | stateCoder.calculateStateCode(); | ||
134 | |||
135 | assertTrue(called[0]); | ||
136 | } | ||
137 | |||
138 | @Test | ||
139 | void customEquivalenceCheckerTest() { | ||
140 | final boolean[] called = new boolean[]{false}; | ||
141 | StateEquivalenceChecker mock = (p1, p2, p3, p4, p5) -> { | ||
142 | called[0] = true; | ||
143 | return StateEquivalenceChecker.EquivalenceResult.UNKNOWN; | ||
144 | }; | ||
145 | |||
146 | var store = ModelStore.builder() | ||
147 | .symbols(friend) | ||
148 | .with(StateCoderAdapter.builder() | ||
149 | .stateEquivalenceChecker(mock)) | ||
150 | .build(); | ||
151 | |||
152 | var model = store.createEmptyModel(); | ||
153 | var v1 = model.commit(); | ||
154 | var v2 = model.commit(); | ||
155 | |||
156 | store.getAdapter(StateCoderStoreAdapter.class).checkEquivalence(v1, v2); | ||
157 | |||
158 | assertTrue(called[0]); | ||
159 | } | ||
160 | |||
161 | |||
116 | private static void fill(Interpretation<Boolean> personI, Interpretation<Boolean> friendI, Interpretation<Integer> ageI) { | 162 | private static void fill(Interpretation<Boolean> personI, Interpretation<Boolean> friendI, Interpretation<Integer> ageI) { |
117 | personI.put(Tuple.of(1), true); | 163 | personI.put(Tuple.of(1), true); |
118 | personI.put(Tuple.of(2), true); | 164 | personI.put(Tuple.of(2), true); |