1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.logic.model; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.HashMap; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
@author |
28 |
|
|
|
|
| 90.7% |
Uncovered Elements: 25 (269) |
Complexity: 68 |
Complexity Density: 0.33 |
|
29 |
|
public final class ThreeModel implements Model { |
30 |
|
|
31 |
|
|
32 |
|
public static final Entity ZERO = new Entity(0, "0", "{} or empty set"); |
33 |
|
|
34 |
|
|
35 |
|
public static final Entity ONE = new Entity(1, "1", "{{}} or {0}"); |
36 |
|
|
37 |
|
|
38 |
|
public static final Entity TWO = new Entity(2, "2", "{{}, {{}}} or {0, 1}"); |
39 |
|
|
40 |
|
|
41 |
|
public static final Function FUNCTION_ZERO = new Function(0, 99, "->0", "always 0") { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
243
|
public Entity map(final Entity[] entities) {... |
43 |
243
|
return ZERO; |
44 |
|
} |
45 |
|
}; |
46 |
|
|
47 |
|
|
48 |
|
public static final Function FUNCTION_ONE = new Function(0, 99, "->1", "always 1") { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
48
|
public Entity map(final Entity[] entities) {... |
50 |
48
|
return ONE; |
51 |
|
} |
52 |
|
}; |
53 |
|
|
54 |
|
|
55 |
|
public static final Function FUNCTION_TWO = new Function(0, 99, "->2", "always 2") { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
181
|
public Entity map(final Entity[] entities) {... |
57 |
181
|
return TWO; |
58 |
|
} |
59 |
|
}; |
60 |
|
|
61 |
|
|
62 |
|
public static final Function FUNCTION_MOD = new Function(0, 99, "% 3", "modulo 3") { |
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 5 |
Complexity Density: 0.38 |
|
63 |
40
|
public Entity map(final Entity[] entities) {... |
64 |
40
|
int result = 0; |
65 |
80
|
for (int i = 0; i < entities.length; i++) { |
66 |
40
|
result += entities[i].getValue() % 3; |
67 |
|
} |
68 |
40
|
result = result % 3; |
69 |
40
|
switch (result) { |
70 |
15
|
case 0: return ZERO; |
71 |
13
|
case 1: return ONE; |
72 |
12
|
case 2: return TWO; |
73 |
0
|
default: return null; |
74 |
|
} |
75 |
|
} |
76 |
|
}; |
77 |
|
|
78 |
|
|
79 |
|
public static final Function FUNCTION_PLUS = new Function(0, 99, "+1 % 3", "plus 1 modulo 3") { |
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 5 |
Complexity Density: 0.38 |
|
80 |
36
|
public Entity map(final Entity[] entities) {... |
81 |
36
|
int result = 1; |
82 |
72
|
for (int i = 0; i < entities.length; i++) { |
83 |
36
|
result += entities[i].getValue() % 3; |
84 |
|
} |
85 |
36
|
result = result % 3; |
86 |
36
|
switch (result) { |
87 |
12
|
case 0: return ZERO; |
88 |
12
|
case 1: return ONE; |
89 |
12
|
case 2: return TWO; |
90 |
0
|
default: return null; |
91 |
|
} |
92 |
|
} |
93 |
|
}; |
94 |
|
|
95 |
|
|
96 |
|
public static final Function FUNCTION_MIN = new Function(0, 99, "min", "minimum") { |
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 6 |
Complexity Density: 0.46 |
|
97 |
375
|
public Entity map(final Entity[] entities) {... |
98 |
375
|
int result = 2; |
99 |
1125
|
for (int i = 0; i < entities.length; i++) { |
100 |
750
|
if (result > entities[i].getValue()) { |
101 |
384
|
result = entities[i].getValue(); |
102 |
|
} |
103 |
|
} |
104 |
375
|
switch (result) { |
105 |
285
|
case 0: return ZERO; |
106 |
64
|
case 1: return ONE; |
107 |
26
|
case 2: return TWO; |
108 |
0
|
default: return null; |
109 |
|
} |
110 |
|
} |
111 |
|
}; |
112 |
|
|
113 |
|
|
114 |
|
public static final Function FUNCTION_MAX = new Function(0, 99, "max", "maximum") { |
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 6 |
Complexity Density: 0.46 |
|
115 |
355
|
public Entity map(final Entity[] entities) {... |
116 |
355
|
int result = 0; |
117 |
1065
|
for (int i = 0; i < entities.length; i++) { |
118 |
710
|
if (result < entities[i].getValue()) { |
119 |
302
|
result = entities[i].getValue(); |
120 |
|
} |
121 |
|
} |
122 |
355
|
switch (result) { |
123 |
75
|
case 0: return ZERO; |
124 |
92
|
case 1: return ONE; |
125 |
188
|
case 2: return TWO; |
126 |
0
|
default: return null; |
127 |
|
} |
128 |
|
} |
129 |
|
}; |
130 |
|
|
131 |
|
|
132 |
|
private final Function functionClassList = new Function(0, 99, "{..}", "classList") { |
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 6 |
Complexity Density: 0.38 |
|
133 |
143
|
public Entity map(final Entity[] entities) {... |
134 |
143
|
Entity result = ZERO; |
135 |
385
|
for (int i = 0; i < entities.length; i++) { |
136 |
242
|
switch (entities[i].getValue()) { |
137 |
106
|
case 0: |
138 |
106
|
if (result.getValue() == 0) { |
139 |
66
|
result = ONE; |
140 |
|
} |
141 |
106
|
break; |
142 |
76
|
case 1: |
143 |
76
|
result = TWO; |
144 |
76
|
break; |
145 |
60
|
case 2: |
146 |
60
|
result = TWO; |
147 |
60
|
break; |
148 |
0
|
default: throw new RuntimeException("unknown value for entity " + entities[i]); |
149 |
|
} |
150 |
|
} |
151 |
143
|
return result; |
152 |
|
} |
153 |
|
}; |
154 |
|
|
155 |
|
|
156 |
|
public static final Predicate FALSE = new Predicate(0, 99, "F", "always false") { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
33903
|
public boolean calculate(final Entity[] entities) {... |
158 |
33903
|
return false; |
159 |
|
} |
160 |
|
}; |
161 |
|
|
162 |
|
|
163 |
|
public static final Predicate TRUE = new Predicate(0, 99, "T", "always true") { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
38421
|
public boolean calculate(final Entity[] entities) {... |
165 |
38421
|
return true; |
166 |
|
} |
167 |
|
}; |
168 |
|
|
169 |
|
|
170 |
|
public static final Predicate EVEN = new Predicate(0, 99, "| 2", "is even") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
171 |
16666
|
public boolean calculate(final Entity[] entities) {... |
172 |
16666
|
boolean result = true; |
173 |
34290
|
for (int i = 0; i < entities.length; i++) { |
174 |
17624
|
result &= entities[i].getValue() % 2 == 0; |
175 |
|
} |
176 |
16666
|
return result; |
177 |
|
} |
178 |
|
}; |
179 |
|
|
180 |
|
|
181 |
|
public static final Predicate LESS = new Predicate(0, 99, "<", "less") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
182 |
4028
|
public boolean calculate(final Entity[] entities) {... |
183 |
4028
|
boolean result = true; |
184 |
8056
|
for (int i = 0; i < entities.length - 1; i++) { |
185 |
4028
|
result &= entities[i].getValue() < entities[i + 1].getValue(); |
186 |
|
} |
187 |
4028
|
return result; |
188 |
|
} |
189 |
|
}; |
190 |
|
|
191 |
|
|
192 |
|
public static final Predicate NOT_LESS = Predicate.not(LESS); |
193 |
|
|
194 |
|
|
195 |
|
public static final Predicate EQUAL = new Predicate(0, 99, "=", "equal") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
196 |
3990
|
public boolean calculate(final Entity[] entities) {... |
197 |
3990
|
boolean result = true; |
198 |
7980
|
for (int i = 0; i < entities.length - 1; i++) { |
199 |
3990
|
result &= entities[i].getValue() == entities[i + 1].getValue(); |
200 |
|
} |
201 |
3990
|
return result; |
202 |
|
} |
203 |
|
}; |
204 |
|
|
205 |
|
|
206 |
|
public static final Predicate NOT_EQUAL = Predicate.not(EQUAL); |
207 |
|
|
208 |
|
|
209 |
|
public static final Predicate IS_ZERO = new Predicate(0, 99, "=0", "is_zero") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
210 |
16599
|
public boolean calculate(final Entity[] entities) {... |
211 |
16599
|
boolean result = true; |
212 |
34116
|
for (int i = 0; i < entities.length; i++) { |
213 |
17517
|
result &= entities[i].getValue() == ZERO.getValue(); |
214 |
|
} |
215 |
16599
|
return result; |
216 |
|
} |
217 |
|
}; |
218 |
|
|
219 |
|
|
220 |
|
public static final Predicate IS_ONE = new Predicate(0, 99, "=1", "is_one") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
221 |
14830
|
public boolean calculate(final Entity[] entities) {... |
222 |
14830
|
boolean result = true; |
223 |
31442
|
for (int i = 0; i < entities.length; i++) { |
224 |
16612
|
result &= entities[i].getValue() == ONE.getValue(); |
225 |
|
} |
226 |
14830
|
return result; |
227 |
|
} |
228 |
|
}; |
229 |
|
|
230 |
|
|
231 |
|
public static final Predicate IS_TWO = new Predicate(0, 99, "= 2", "is_two") { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
232 |
21297
|
public boolean calculate(final Entity[] entities) {... |
233 |
21297
|
boolean result = true; |
234 |
45528
|
for (int i = 0; i < entities.length; i++) { |
235 |
24231
|
result &= entities[i].getValue() == TWO.getValue(); |
236 |
|
} |
237 |
21297
|
return result; |
238 |
|
} |
239 |
|
}; |
240 |
|
|
241 |
|
|
242 |
|
public static final Predicate NOT_IS_TWO = Predicate.not(IS_TWO); |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
private final List entities; |
248 |
|
|
249 |
|
|
250 |
|
private final List functionPool; |
251 |
|
|
252 |
|
|
253 |
|
private final List predicatePool; |
254 |
|
|
255 |
|
|
256 |
|
private final Map predicateConstants; |
257 |
|
|
258 |
|
|
259 |
|
private final Map functionConstants; |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (65) |
Complexity: 1 |
Complexity Density: 0.02 |
|
264 |
51
|
public ThreeModel() {... |
265 |
51
|
entities = new ArrayList(); |
266 |
51
|
entities.add(ZERO); |
267 |
51
|
entities.add(ONE); |
268 |
51
|
entities.add(TWO); |
269 |
|
|
270 |
51
|
functionPool = new ArrayList(); |
271 |
|
|
272 |
51
|
final List function0 = new ArrayList(); |
273 |
51
|
functionPool.add(function0); |
274 |
51
|
function0.add(FUNCTION_ZERO); |
275 |
51
|
function0.add(FUNCTION_ONE); |
276 |
|
|
277 |
51
|
final List function1 = new ArrayList(); |
278 |
51
|
functionPool.add(function1); |
279 |
51
|
function1.add(FUNCTION_ZERO); |
280 |
51
|
function1.add(FUNCTION_ONE); |
281 |
51
|
function1.add(FUNCTION_MOD); |
282 |
51
|
function1.add(FUNCTION_PLUS); |
283 |
|
|
284 |
51
|
final List function2 = new ArrayList(); |
285 |
51
|
functionPool.add(function2); |
286 |
51
|
function2.add(FUNCTION_ZERO); |
287 |
51
|
function2.add(FUNCTION_ONE); |
288 |
51
|
function2.add(FUNCTION_MOD); |
289 |
51
|
function2.add(FUNCTION_PLUS); |
290 |
|
|
291 |
51
|
predicatePool = new ArrayList(); |
292 |
|
|
293 |
51
|
final List predicate0 = new ArrayList(); |
294 |
51
|
predicatePool.add(predicate0); |
295 |
51
|
predicate0.add(FALSE); |
296 |
51
|
predicate0.add(TRUE); |
297 |
|
|
298 |
51
|
final List predicate1 = new ArrayList(); |
299 |
51
|
predicatePool.add(predicate1); |
300 |
51
|
predicate1.add(FALSE); |
301 |
51
|
predicate1.add(TRUE); |
302 |
51
|
predicate1.add(EVEN); |
303 |
51
|
predicate1.add(IS_ZERO); |
304 |
51
|
predicate1.add(IS_ONE); |
305 |
51
|
predicate1.add(IS_TWO); |
306 |
|
|
307 |
51
|
final List predicate2 = new ArrayList(); |
308 |
51
|
predicatePool.add(predicate2); |
309 |
51
|
predicate2.add(FALSE); |
310 |
51
|
predicate2.add(TRUE); |
311 |
51
|
predicate2.add(EVEN); |
312 |
51
|
predicate2.add(LESS); |
313 |
51
|
predicate2.add(EQUAL); |
314 |
51
|
predicate2.add(IS_ZERO); |
315 |
51
|
predicate2.add(IS_ONE); |
316 |
51
|
predicate2.add(IS_TWO); |
317 |
|
|
318 |
51
|
predicateConstants = new HashMap(); |
319 |
51
|
predicateConstants.put(new ModelPredicateConstant("TRUE", 0), TRUE); |
320 |
51
|
predicateConstants.put(new ModelPredicateConstant("FALSE", 0), FALSE); |
321 |
51
|
predicateConstants.put(new ModelPredicateConstant("equal", 2), EQUAL); |
322 |
51
|
predicateConstants.put(new ModelPredicateConstant("notEqual", 2), NOT_EQUAL); |
323 |
51
|
predicateConstants.put(new ModelPredicateConstant("in", 2), LESS); |
324 |
51
|
predicateConstants.put(new ModelPredicateConstant("notIn", 2), NOT_LESS); |
325 |
51
|
predicateConstants.put(new ModelPredicateConstant("isSet", 1), Predicate.not(IS_TWO)); |
326 |
51
|
predicateConstants.put(new ModelPredicateConstant("subclass", 2), Predicate.or(LESS, EQUAL)); |
327 |
|
|
328 |
51
|
functionConstants = new HashMap(); |
329 |
51
|
functionConstants.put(new ModelFunctionConstant("emptySet", 0), FUNCTION_ZERO); |
330 |
51
|
functionConstants.put(new ModelFunctionConstant("RussellClass", 0), FUNCTION_TWO); |
331 |
51
|
functionConstants.put(new ModelFunctionConstant("intersection", 2), FUNCTION_MIN); |
332 |
51
|
functionConstants.put(new ModelFunctionConstant("union", 2), FUNCTION_MAX); |
333 |
51
|
functionConstants.put(new ModelFunctionConstant("universalClass", 0), FUNCTION_TWO); |
334 |
51
|
functionConstants.put(new ModelFunctionConstant("complement", 1), new Function(1, 1, "compement", |
335 |
|
"complement") { |
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 5 |
Complexity Density: 0.45 |
|
336 |
212
|
public Entity map(final Entity[] entities) {... |
337 |
212
|
if (entities.length != 1) { |
338 |
0
|
return ZERO; |
339 |
|
} |
340 |
212
|
switch (entities[0].getValue()) { |
341 |
125
|
case 0: return TWO; |
342 |
39
|
case 1: return TWO; |
343 |
48
|
case 2: return ZERO; |
344 |
0
|
default: throw new IllegalArgumentException("unknown entity value"); |
345 |
|
} |
346 |
|
} |
347 |
|
}); |
348 |
51
|
functionConstants.put(new ModelFunctionConstant("classList", 0), functionClassList); |
349 |
51
|
functionConstants.put(new ModelFunctionConstant("classList", 1), functionClassList); |
350 |
51
|
functionConstants.put(new ModelFunctionConstant("classList", 2), functionClassList); |
351 |
51
|
functionConstants.put(new ModelFunctionConstant("classList", 3), functionClassList); |
352 |
51
|
functionConstants.put(new ModelFunctionConstant("classList", 4), functionClassList); |
353 |
|
|
354 |
|
} |
355 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
356 |
0
|
public String getDescription() {... |
357 |
0
|
return "This model has three entities. The first is element of the second, " |
358 |
|
+ "the second element of the third."; |
359 |
|
} |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
361 |
114241
|
public int getEntitiesSize() {... |
362 |
114241
|
return entities.size(); |
363 |
|
} |
364 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
365 |
138334
|
public Entity getEntity(final int number) {... |
366 |
138334
|
return (Entity) entities.get(number); |
367 |
|
} |
368 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
369 |
4289
|
public int getPredicateSize(final int size) {... |
370 |
4289
|
if (predicatePool.size() <= size) { |
371 |
0
|
return 0; |
372 |
|
} |
373 |
4289
|
return ((List) predicatePool.get(size)).size(); |
374 |
|
} |
375 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
376 |
139793
|
public Predicate getPredicate(final int size, final int number) {... |
377 |
139793
|
final List predicateForSize = (List) predicatePool.get(size); |
378 |
139793
|
return (Predicate) predicateForSize.get(number); |
379 |
|
} |
380 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
381 |
8360
|
public Predicate getPredicateConstant(final ModelPredicateConstant con) {... |
382 |
8360
|
return (Predicate) predicateConstants.get(con); |
383 |
|
} |
384 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
385 |
14
|
public int getFunctionSize(final int size) {... |
386 |
14
|
if (functionPool.size() <= size) { |
387 |
0
|
return 0; |
388 |
|
} |
389 |
14
|
return ((List) functionPool.get(size)).size(); |
390 |
|
} |
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
392 |
172
|
public Function getFunction(final int size, final int number) {... |
393 |
172
|
final List functionForSize = (List) functionPool.get(size); |
394 |
172
|
return (Function) functionForSize.get(number); |
395 |
|
} |
396 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
397 |
1497
|
public Function getFunctionConstant(final ModelFunctionConstant con) {... |
398 |
1497
|
return (Function) functionConstants.get(con); |
399 |
|
} |
400 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
401 |
2232
|
public Entity comprehension(final Entity[] array) {... |
402 |
2232
|
Entity result = ZERO; |
403 |
4479
|
for (int i = 0; i < array.length; i++) { |
404 |
2247
|
switch (array[i].getValue()) { |
405 |
1496
|
case 0: |
406 |
1496
|
if (result.getValue() == 0) { |
407 |
1496
|
result = ONE; |
408 |
|
} |
409 |
1496
|
break; |
410 |
751
|
case 1: |
411 |
751
|
result = TWO; |
412 |
751
|
break; |
413 |
0
|
case 2: |
414 |
0
|
break; |
415 |
0
|
default: throw new RuntimeException("unknown value for entity " + array[i]); |
416 |
|
} |
417 |
|
} |
418 |
2232
|
return result; |
419 |
|
} |
420 |
|
|
421 |
|
} |