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 |
|
|
|
|
| 51.8% |
Uncovered Elements: 55 (114) |
Complexity: 27 |
Complexity Density: 0.31 |
|
25 |
|
public final class SixDynamicModel extends DynamicModel { |
26 |
|
|
27 |
|
|
28 |
|
public static final Entity EMPTY = new Entity(0, "{}", "{} or empty set"); |
29 |
|
|
30 |
|
|
31 |
|
public static final Entity ZERO_ONE = new Entity(1, "1", "1"); |
32 |
|
|
33 |
|
|
34 |
|
public static final Entity ZERO_TWO = new Entity(2, "2", "2"); |
35 |
|
|
36 |
|
|
37 |
|
public static final Entity ONE_ONE = new Entity(3, "{1}", "{1}"); |
38 |
|
|
39 |
|
|
40 |
|
public static final Entity ONE_TWO = new Entity(4, "{2}", "{2}"); |
41 |
|
|
42 |
|
|
43 |
|
public static final Entity TWO_ONE_TWO = new Entity(5, "{1, 2}", "{1, 2}"); |
44 |
|
|
45 |
|
|
46 |
|
public static final Function FUNCTION_EMPTY = Function.createConstant(EMPTY); |
47 |
|
|
48 |
|
|
49 |
|
public static final Function FUNCTION_ZERO_ONE = Function.createConstant(ZERO_ONE); |
50 |
|
|
51 |
|
|
52 |
|
public static final Function FUNCTION_ZERO_TWO = Function.createConstant(ZERO_TWO); |
53 |
|
|
54 |
|
|
55 |
|
public static final Function FUNCTION_ONE_ONE = Function.createConstant(ONE_ONE); |
56 |
|
|
57 |
|
|
58 |
|
public static final Function FUNCTION_ONE_TWO = Function.createConstant(ONE_TWO); |
59 |
|
|
60 |
|
|
61 |
|
public static final Function FUNCTION_TWO_ONE_TWO = Function.createConstant(TWO_ONE_TWO); |
62 |
|
|
63 |
|
|
64 |
|
public static final Predicate IS_EMPTY = Predicate.isEntity(EMPTY); |
65 |
|
|
66 |
|
|
67 |
|
public static final Predicate IS_ZERO_ONE = Predicate.isEntity(ZERO_ONE); |
68 |
|
|
69 |
|
|
70 |
|
public static final Predicate IS_ZERO_TWO = Predicate.isEntity(ZERO_TWO); |
71 |
|
|
72 |
|
|
73 |
|
public static final Predicate IS_ONE_ONE = Predicate.isEntity(ONE_ONE); |
74 |
|
|
75 |
|
|
76 |
|
public static final Predicate IS_ONE_TWO = Predicate.isEntity(ONE_TWO); |
77 |
|
|
78 |
|
|
79 |
|
public static final Predicate IS_TWO_ONE_TWO = Predicate.isEntity(TWO_ONE_TWO); |
80 |
|
|
81 |
|
|
82 |
|
public static final Predicate NOT_IS_ONE_TWO = Predicate.not(IS_ONE_TWO); |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
private final Function functionModulo3 = new Function(0, 99, "% 3", "modulo 3") { |
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
87 |
40
|
public Entity map(final Entity[] entities) {... |
88 |
40
|
int result = 0; |
89 |
80
|
for (int i = 0; i < entities.length; i++) { |
90 |
40
|
result += entities[i].getValue() % 3; |
91 |
|
} |
92 |
40
|
result = result % 3; |
93 |
40
|
return getEntity(result); |
94 |
|
} |
95 |
|
}; |
96 |
|
|
97 |
|
|
98 |
|
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 |
|
99 |
36
|
public Entity map(final Entity[] entities) {... |
100 |
36
|
int result = 1; |
101 |
72
|
for (int i = 0; i < entities.length; i++) { |
102 |
36
|
result += entities[i].getValue() % 3; |
103 |
|
} |
104 |
36
|
result = result % 3; |
105 |
36
|
return getEntity(result); |
106 |
|
} |
107 |
|
}; |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 1 |
Complexity Density: 0.02 |
|
113 |
46
|
public SixDynamicModel() {... |
114 |
46
|
super("six elements"); |
115 |
|
|
116 |
46
|
addEntity(EMPTY); |
117 |
46
|
addEntity(ZERO_ONE); |
118 |
46
|
addEntity(ZERO_TWO); |
119 |
46
|
addEntity(ONE_ONE); |
120 |
46
|
addEntity(ONE_TWO); |
121 |
46
|
addEntity(TWO_ONE_TWO); |
122 |
|
|
123 |
46
|
addFunction(0, FUNCTION_EMPTY); |
124 |
46
|
addFunction(0, FUNCTION_ZERO_ONE); |
125 |
46
|
addFunction(0, FUNCTION_ZERO_TWO); |
126 |
46
|
addFunction(0, FUNCTION_ONE_ONE); |
127 |
46
|
addFunction(0, FUNCTION_ONE_TWO); |
128 |
46
|
addFunction(0, FUNCTION_TWO_ONE_TWO); |
129 |
|
|
130 |
46
|
addFunction(1, FUNCTION_EMPTY); |
131 |
46
|
addFunction(1, FUNCTION_ZERO_ONE); |
132 |
46
|
addFunction(1, functionModulo3); |
133 |
46
|
addFunction(1, functionPlus1Modulo3); |
134 |
|
|
135 |
46
|
addFunction(2, FUNCTION_EMPTY); |
136 |
46
|
addFunction(2, FUNCTION_ZERO_ONE); |
137 |
46
|
addFunction(2, functionModulo3); |
138 |
46
|
addFunction(2, functionPlus1Modulo3); |
139 |
|
|
140 |
46
|
addPredicate(0, FALSE); |
141 |
46
|
addPredicate(0, TRUE); |
142 |
|
|
143 |
46
|
addPredicate(1, FALSE); |
144 |
46
|
addPredicate(1, TRUE); |
145 |
46
|
addPredicate(1, EVEN); |
146 |
46
|
addPredicate(1, IS_EMPTY); |
147 |
46
|
addPredicate(1, IS_ZERO_ONE); |
148 |
46
|
addPredicate(1, IS_ZERO_TWO); |
149 |
46
|
addPredicate(1, IS_ONE_ONE); |
150 |
46
|
addPredicate(1, IS_TWO_ONE_TWO); |
151 |
|
|
152 |
46
|
addPredicate(2, FALSE); |
153 |
46
|
addPredicate(2, TRUE); |
154 |
46
|
addPredicate(2, EVEN); |
155 |
46
|
addPredicate(2, LESS); |
156 |
46
|
addPredicate(2, EQUAL); |
157 |
46
|
addPredicate(2, IS_EMPTY); |
158 |
46
|
addPredicate(2, IS_ZERO_ONE); |
159 |
46
|
addPredicate(2, IS_ZERO_TWO); |
160 |
46
|
addPredicate(2, IS_ONE_ONE); |
161 |
46
|
addPredicate(2, IS_ONE_TWO); |
162 |
|
|
163 |
46
|
addPredicateConstant(new ModelPredicateConstant("in", 2), new Predicate(2, 2, "in", "isSet") { |
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 7 |
Complexity Density: 0.88 |
|
164 |
0
|
public boolean calculate(final Entity[] entities) {... |
165 |
0
|
boolean result = false; |
166 |
0
|
final int a = entities[0].getValue(); |
167 |
0
|
final int b = entities[1].getValue(); |
168 |
0
|
if (a == 1 && (b == 3 || b == 5)) { |
169 |
0
|
result = true; |
170 |
|
} |
171 |
0
|
if (a == 2 && (b == 4 || b == 5)) { |
172 |
0
|
result = true; |
173 |
|
} |
174 |
0
|
return result; |
175 |
|
} |
176 |
|
}); |
177 |
|
} |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
0
|
public String getDescription() {... |
180 |
0
|
return "This model has six entities: {}, {1}, {2}, {{1}}, {{2}} and {1, 2}."; |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 14 |
Complexity Density: 0.56 |
|
183 |
0
|
public Entity comprehension(final Entity[] array) {... |
184 |
0
|
Entity result = EMPTY; |
185 |
0
|
for (int i = 0; i < array.length; i++) { |
186 |
0
|
switch (array[i].getValue()) { |
187 |
0
|
case 0: |
188 |
0
|
case 3: |
189 |
0
|
case 4: |
190 |
0
|
case 5: break; |
191 |
0
|
case 1: if (result.getValue() != 5) { |
192 |
0
|
if (result.getValue() == 0) { |
193 |
0
|
result = ONE_ONE; |
194 |
0
|
} else if (result.getValue() == 4) { |
195 |
0
|
result = TWO_ONE_TWO; |
196 |
|
} |
197 |
|
} |
198 |
0
|
break; |
199 |
0
|
case 2: if (result.getValue() != 5) { |
200 |
0
|
if (result.getValue() == 0) { |
201 |
0
|
result = ONE_TWO; |
202 |
0
|
} else if (result.getValue() == 4) { |
203 |
0
|
result = TWO_ONE_TWO; |
204 |
|
} |
205 |
|
} |
206 |
0
|
break; |
207 |
0
|
default: throw new RuntimeException("unknown value for entity " + array[i]); |
208 |
|
} |
209 |
|
} |
210 |
0
|
return result; |
211 |
|
} |
212 |
|
|
213 |
|
} |