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 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
@author |
24 |
|
|
|
|
| 90.1% |
Uncovered Elements: 7 (71) |
Complexity: 12 |
Complexity Density: 0.21 |
|
25 |
|
public final class ThreeDynamicModel extends DynamicModel { |
26 |
|
|
27 |
|
|
28 |
|
public static final Entity ZERO = new Entity(0, "{}", "{} or empty set"); |
29 |
|
|
30 |
|
|
31 |
|
public static final Entity ONE = new Entity(1, "{{}}", "{{}} or 1"); |
32 |
|
|
33 |
|
|
34 |
|
public static final Entity TWO = new Entity(2, "{{}, {{}}}", "{{}, {{}}} or 2"); |
35 |
|
|
36 |
|
|
37 |
|
public static final Function FUNCTION_ZERO = Function.createConstant(ZERO); |
38 |
|
|
39 |
|
|
40 |
|
public static final Function FUNCTION_ONE = Function.createConstant(ONE); |
41 |
|
|
42 |
|
|
43 |
|
public static final Function FUNCTION_TWO = Function.createConstant(TWO); |
44 |
|
|
45 |
|
|
46 |
|
public static final Predicate IS_ZERO = Predicate.isEntity(ZERO); |
47 |
|
|
48 |
|
|
49 |
|
public static final Predicate IS_ONE = Predicate.isEntity(ONE); |
50 |
|
|
51 |
|
|
52 |
|
public static final Predicate IS_TWO = Predicate.isEntity(TWO); |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private final Function functionModulo3 = new Function(0, 99, "% 3", "modulo 3") { |
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
57 |
22
|
public Entity map(final Entity[] entities) {... |
58 |
22
|
int result = 0; |
59 |
44
|
for (int i = 0; i < entities.length; i++) { |
60 |
22
|
result += entities[i].getValue() % 3; |
61 |
|
} |
62 |
22
|
result = result % 3; |
63 |
22
|
return getEntity(result); |
64 |
|
} |
65 |
|
}; |
66 |
|
|
67 |
|
|
68 |
|
private final Function functionPlus1Modulo3 = new Function(0, 99, "+1 % 3", "plus 1 modulo 3") { |
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
69 |
18
|
public Entity map(final Entity[] entities) {... |
70 |
18
|
int result = 1; |
71 |
36
|
for (int i = 0; i < entities.length; i++) { |
72 |
18
|
result += entities[i].getValue() % 3; |
73 |
|
} |
74 |
18
|
result = result % 3; |
75 |
18
|
return getEntity(result); |
76 |
|
} |
77 |
|
}; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 1 |
Complexity Density: 0.03 |
|
83 |
48
|
public ThreeDynamicModel() {... |
84 |
48
|
super("three elements"); |
85 |
|
|
86 |
48
|
addEntity(ZERO); |
87 |
48
|
addEntity(ONE); |
88 |
48
|
addEntity(TWO); |
89 |
|
|
90 |
48
|
addFunction(0, FUNCTION_ZERO); |
91 |
48
|
addFunction(0, FUNCTION_ONE); |
92 |
48
|
addFunction(0, FUNCTION_TWO); |
93 |
|
|
94 |
48
|
addFunction(1, FUNCTION_ZERO); |
95 |
48
|
addFunction(1, FUNCTION_ONE); |
96 |
48
|
addFunction(1, functionModulo3); |
97 |
48
|
addFunction(1, functionPlus1Modulo3); |
98 |
|
|
99 |
48
|
addFunction(2, FUNCTION_ZERO); |
100 |
48
|
addFunction(2, FUNCTION_ONE); |
101 |
48
|
addFunction(2, functionModulo3); |
102 |
48
|
addFunction(2, functionPlus1Modulo3); |
103 |
|
|
104 |
48
|
addPredicate(0, FALSE); |
105 |
48
|
addPredicate(0, TRUE); |
106 |
|
|
107 |
48
|
addPredicate(1, FALSE); |
108 |
48
|
addPredicate(1, TRUE); |
109 |
48
|
addPredicate(1, EVEN); |
110 |
48
|
addPredicate(1, IS_ZERO); |
111 |
48
|
addPredicate(1, IS_ONE); |
112 |
48
|
addPredicate(1, IS_TWO); |
113 |
|
|
114 |
48
|
addPredicate(2, FALSE); |
115 |
48
|
addPredicate(2, TRUE); |
116 |
48
|
addPredicate(2, EVEN); |
117 |
48
|
addPredicate(2, LESS); |
118 |
48
|
addPredicate(2, EQUAL); |
119 |
48
|
addPredicate(2, IS_ZERO); |
120 |
48
|
addPredicate(2, IS_ONE); |
121 |
48
|
addPredicate(2, IS_TWO); |
122 |
|
|
123 |
48
|
addPredicateConstant(new ModelPredicateConstant("in", 2), LESS); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0
|
public String getDescription() {... |
127 |
0
|
return "This model has three entities: {}, {{}}, {{}, {{}}}."; |
128 |
|
} |
129 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
130 |
13
|
public Entity comprehension(final Entity[] array) {... |
131 |
13
|
Entity result = ZERO; |
132 |
26
|
for (int i = 0; i < array.length; i++) { |
133 |
13
|
switch (array[i].getValue()) { |
134 |
9
|
case 0: |
135 |
9
|
if (result.getValue() == 0) { |
136 |
9
|
result = ONE; |
137 |
|
} |
138 |
9
|
break; |
139 |
4
|
case 1: |
140 |
4
|
result = TWO; |
141 |
4
|
break; |
142 |
0
|
case 2: |
143 |
0
|
break; |
144 |
0
|
default: throw new RuntimeException("unknown value for entity " + array[i]); |
145 |
|
} |
146 |
|
} |
147 |
13
|
return result; |
148 |
|
} |
149 |
|
|
150 |
|
} |