1 | package com.github.dakusui.pcond.core; | |
2 | ||
3 | import com.github.dakusui.pcond.experimentals.currying.context.CurriedContext; | |
4 | ||
5 | import java.util.function.Function; | |
6 | import java.util.function.Predicate; | |
7 | import java.util.stream.Stream; | |
8 | ||
9 | import static com.github.dakusui.pcond.core.EvaluationContext.formNameOf; | |
10 | import static com.github.dakusui.pcond.core.EvaluationContext.resolveEvaluationEntryType; | |
11 | import static com.github.dakusui.pcond.core.EvaluationEntry.Type.*; | |
12 | import static com.github.dakusui.pcond.core.EvaluationEntry.composeDetailOutputActualValueFromInputAndThrowable; | |
13 | import static com.github.dakusui.pcond.core.ValueHolder.CreatorFormType.FUNC_HEAD; | |
14 | import static com.github.dakusui.pcond.core.ValueHolder.CreatorFormType.FUNC_TAIL; | |
15 | import static com.github.dakusui.pcond.core.ValueHolder.State.*; | |
16 | import static com.github.dakusui.pcond.internals.InternalUtils.explainValue; | |
17 | import static com.github.dakusui.pcond.internals.InternalUtils.isDummyFunction; | |
18 | import static java.util.Objects.requireNonNull; | |
19 | ||
20 | /** | |
21 | * A visitor interface that defines a mechanism to "evaluate" printable predicates. | |
22 | */ | |
23 | public interface Evaluator { | |
24 | /** | |
25 | * Evaluates `value` with `conjunction` predicate ("and"). | |
26 | * | |
27 | * @param <T> The type of the `value`. | |
28 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
29 | * @param evaluationContext An evaluation context. | |
30 | * @see com.github.dakusui.pcond.core.Evaluable.Conjunction | |
31 | */ | |
32 | <T> void evaluateConjunction(EvaluableIo<T, Evaluable.Conjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
33 | ||
34 | /** | |
35 | * Evaluates `value` with a `disjunction` predicate ("or"). | |
36 | * | |
37 | * @param <T> The type of the `value`. | |
38 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
39 | * @param evaluationContext An evaluation context. | |
40 | * @see com.github.dakusui.pcond.core.Evaluable.Disjunction | |
41 | */ | |
42 | <T> void evaluateDisjunction(EvaluableIo<T, Evaluable.Disjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
43 | ||
44 | /** | |
45 | * Evaluates `value` with a `negation` predicate ("not"). | |
46 | * | |
47 | * @param <T> The type of the `value`. | |
48 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
49 | * @param evaluationContext An evaluation context. | |
50 | * @see com.github.dakusui.pcond.core.Evaluable.Negation | |
51 | */ | |
52 | <T> void evaluateNegation(EvaluableIo<T, Evaluable.Negation<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
53 | ||
54 | /** | |
55 | * Evaluates `value` with a leaf predicate. | |
56 | * | |
57 | * @param <T> The type of the `value`. | |
58 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
59 | * @param evaluationContext An evaluation context. | |
60 | * @see com.github.dakusui.pcond.core.Evaluable.LeafPred | |
61 | */ | |
62 | <T> void evaluateLeaf(EvaluableIo<T, Evaluable.LeafPred<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
63 | ||
64 | /** | |
65 | * Evaluates `value` with a "function" predicate. | |
66 | * | |
67 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
68 | * @param evaluationContext An evaluation context. | |
69 | * @see com.github.dakusui.pcond.core.Evaluable.Func | |
70 | */ | |
71 | <T, R> void evaluateFunction(EvaluableIo<T, Evaluable.Func<T>, R> evaluableIo, EvaluationContext<T> evaluationContext); | |
72 | ||
73 | /** | |
74 | * Evaluates `value` with a context predicate. | |
75 | * | |
76 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
77 | * @param evaluationContext An evaluation context. | |
78 | * @see Evaluable.CurriedContextPred | |
79 | */ | |
80 | void evaluateCurriedContextPredicate(EvaluableIo<CurriedContext, Evaluable.CurriedContextPred, Boolean> evaluableIo, EvaluationContext<CurriedContext> evaluationContext); | |
81 | ||
82 | /** | |
83 | * Evaluates `value` with a "transformation" predicate. | |
84 | * | |
85 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
86 | * @param evaluationContext An evaluation context. | |
87 | * @see com.github.dakusui.pcond.core.Evaluable.Transformation | |
88 | */ | |
89 | <T, R> void evaluateTransformation(EvaluableIo<T, Evaluable.Transformation<T, R>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext); | |
90 | ||
91 | /** | |
92 | * Evaluates `value` with a predicate for a stream. | |
93 | * | |
94 | * @param evaluableIo An object to hold an evaluable and its input and output. | |
95 | * @param evaluationContext An evaluation context. | |
96 | * @see com.github.dakusui.pcond.core.Evaluable.StreamPred | |
97 | */ | |
98 | <E> void evaluateStreamPredicate(EvaluableIo<Stream<E>, Evaluable.StreamPred<E>, Boolean> evaluableIo, EvaluationContext<Stream<E>> evaluationContext); | |
99 | ||
100 | /** | |
101 | * Returns a new instance of this interface. | |
102 | * | |
103 | * @return a new instance of this interface. | |
104 | */ | |
105 | static Evaluator create() { | |
106 |
1
1. create : replaced return value with null for com/github/dakusui/pcond/core/Evaluator::create → KILLED |
return new Impl(); |
107 | } | |
108 | ||
109 | class Impl implements Evaluator { | |
110 | public static final Object EVALUATION_SKIPPED = new Object() { | |
111 | @Override | |
112 | public String toString() { | |
113 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/core/Evaluator$Impl$1::toString → KILLED |
return "(not evaluated)"; |
114 | } | |
115 | }; | |
116 | ||
117 | private static final Object NULL_VALUE = new Object() { | |
118 | public String toString() { | |
119 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/core/Evaluator$Impl$2::toString → SURVIVED |
return "null"; |
120 | } | |
121 | }; | |
122 | ||
123 | public Impl() { | |
124 | } | |
125 | ||
126 | @Override | |
127 | public <T> void evaluateConjunction(EvaluableIo<T, Evaluable.Conjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
128 |
1
1. evaluateConjunction : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
129 | evaluableIo, | |
130 | (Evaluable.Conjunction<T> evaluable, ValueHolder<T> input) -> { | |
131 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
132 | boolean result = true; | |
133 | ValueHolder<Boolean> retSkipped = null; | |
134 | for (Evaluable<T> each : evaluable.children()) { | |
135 | EvaluableIo<T, Evaluable<T>, Boolean> child = createChildEvaluableIoOf(each, input); | |
136 |
1
1. lambda$evaluateConjunction$0 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
each.accept(child, evaluationContext, this); |
137 | ValueHolder<Boolean> outputFromEach = child.output(); | |
138 |
1
1. lambda$evaluateConjunction$0 : negated conditional → KILLED |
if (outputFromEach.isValueReturned()) { |
139 |
1
1. lambda$evaluateConjunction$0 : Replaced bitwise AND with OR → KILLED |
result &= outputFromEach.returnedValue(); |
140 | ret = ValueHolder.forValue(result); | |
141 |
1
1. lambda$evaluateConjunction$0 : negated conditional → SURVIVED |
} else if (child.output().isExceptionThrown()) { |
142 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
143 |
1
1. lambda$evaluateConjunction$0 : negated conditional → NO_COVERAGE |
retSkipped = retSkipped != null ? retSkipped : ret; |
144 |
1
1. lambda$evaluateConjunction$0 : negated conditional → KILLED |
} else if (child.output().isEvaluationSkipped()) { |
145 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
146 |
1
1. lambda$evaluateConjunction$0 : negated conditional → SURVIVED |
retSkipped = retSkipped != null ? retSkipped : ret; |
147 | } else | |
148 | assert false; | |
149 |
3
1. lambda$evaluateConjunction$0 : negated conditional → KILLED 2. lambda$evaluateConjunction$0 : negated conditional → KILLED 3. lambda$evaluateConjunction$0 : negated conditional → KILLED |
if (evaluable.shortcut() && (ret.isEvaluationSkipped() || !result)) |
150 | break; | |
151 | } | |
152 |
2
1. lambda$evaluateConjunction$0 : negated conditional → KILLED 2. lambda$evaluateConjunction$0 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateConjunction$0 → KILLED |
return retSkipped != null ? retSkipped : ret; |
153 | }); | |
154 | } | |
155 | ||
156 | @Override | |
157 | public <T> void evaluateDisjunction(EvaluableIo<T, Evaluable.Disjunction<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
158 |
1
1. evaluateDisjunction : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
159 | evaluableIo, | |
160 | (Evaluable.Disjunction<T> evaluable, ValueHolder<T> input) -> { | |
161 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
162 | boolean result = false; | |
163 | ValueHolder<Boolean> retSkipped = null; | |
164 | for (Evaluable<T> each : evaluable.children()) { | |
165 | EvaluableIo<T, Evaluable<T>, Boolean> child = createChildEvaluableIoOf(each, input); | |
166 |
1
1. lambda$evaluateDisjunction$1 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
each.accept(child, evaluationContext, this); |
167 | ValueHolder<Boolean> outputFromEach = child.output(); | |
168 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED |
if (outputFromEach.isValueReturned()) { |
169 |
1
1. lambda$evaluateDisjunction$1 : Replaced bitwise OR with AND → KILLED |
result |= outputFromEach.returnedValue(); |
170 | ret = ValueHolder.forValue(result); | |
171 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
} else if (outputFromEach.isExceptionThrown()) { |
172 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
173 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
retSkipped = retSkipped != null ? retSkipped : ret; |
174 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
} else if (outputFromEach.isEvaluationSkipped()) { |
175 | ret = ValueHolder.<Boolean>create().evaluationSkipped(); | |
176 |
1
1. lambda$evaluateDisjunction$1 : negated conditional → NO_COVERAGE |
retSkipped = retSkipped != null ? retSkipped : ret; |
177 | } else | |
178 | assert false; | |
179 |
3
1. lambda$evaluateDisjunction$1 : negated conditional → SURVIVED 2. lambda$evaluateDisjunction$1 : negated conditional → KILLED 3. lambda$evaluateDisjunction$1 : negated conditional → KILLED |
if (evaluable.shortcut() && (ret.isEvaluationSkipped() || result)) |
180 | break; | |
181 | } | |
182 |
2
1. lambda$evaluateDisjunction$1 : negated conditional → KILLED 2. lambda$evaluateDisjunction$1 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateDisjunction$1 → KILLED |
return retSkipped != null ? retSkipped : ret; |
183 | }); | |
184 | } | |
185 | ||
186 | @Override | |
187 | public <T> void evaluateNegation(EvaluableIo<T, Evaluable.Negation<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
188 |
1
1. evaluateNegation : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
189 | evaluableIo, | |
190 | (Evaluable.Negation<T> evaluable, ValueHolder<T> input) -> { | |
191 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/dakusui/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
192 | try { | |
193 | EvaluableIo<T, Evaluable<T>, Boolean> childIo = createChildEvaluableIoOf(evaluable.target(), input); | |
194 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
evaluable.target().accept(childIo, evaluationContext, this); |
195 |
2
1. lambda$evaluateNegation$2 : negated conditional → KILLED 2. lambda$evaluateNegation$2 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateNegation$2 → KILLED |
return childIo.output().isValueReturned() ? |
196 |
1
1. lambda$evaluateNegation$2 : Replaced XOR with AND → KILLED |
ValueHolder.forValue(evaluationContext.isExpectationFlipped() ^ childIo.output().returnedValue()) : |
197 | childIo.output(); | |
198 | } finally { | |
199 |
1
1. lambda$evaluateNegation$2 : removed call to com/github/dakusui/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
200 | } | |
201 | } | |
202 | ); | |
203 | } | |
204 | ||
205 | @Override | |
206 | public <T> void evaluateLeaf(EvaluableIo<T, Evaluable.LeafPred<T>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
207 |
1
1. evaluateLeaf : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
208 | LEAF, | |
209 | evaluableIo, | |
210 | (evaluable, input) -> { | |
211 | ValueHolder<Boolean> ret = ValueHolder.create(); | |
212 |
1
1. lambda$evaluateLeaf$3 : negated conditional → KILLED |
if (input.isValueReturned()) { |
213 | T value = input.returnedValue(); | |
214 | Predicate<? super T> predicate = requireNonNull(evaluable.predicate()); | |
215 | try { | |
216 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.valueReturned(predicate.test(value)); |
217 | } catch (Throwable t) { | |
218 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.exceptionThrown(t); |
219 | } | |
220 | } else | |
221 |
1
1. lambda$evaluateLeaf$3 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateLeaf$3 → KILLED |
return ret.evaluationSkipped(); |
222 | }); | |
223 | } | |
224 | ||
225 | @SuppressWarnings("unchecked") | |
226 | @Override | |
227 | public <T, R> void evaluateFunction(EvaluableIo<T, Evaluable.Func<T>, R> evaluableIo, EvaluationContext<T> evaluationContext) { | |
228 |
1
1. evaluateFunction : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( //#2 |
229 | FUNCTION, | |
230 | evaluableIo, | |
231 | (Evaluable.Func<T> evaluable, ValueHolder<T> input) -> { | |
232 | ValueHolder<R> ret; | |
233 | { | |
234 | EvaluableIo<T, Evaluable<T>, Object> ioForHead = createChildEvaluableIoOf(evaluable, input); | |
235 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
236 |
1
1. lambda$evaluateFunction$6 : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(FUNCTION, ioForHead, io -> { |
237 | ValueHolder<Object> tmp = ValueHolder.create(); | |
238 |
1
1. lambda$null$4 : negated conditional → KILLED |
if (io.input().isValueReturned()) |
239 | tmp = applyFunction(tmp, io.input().returnedValue(), ((Evaluable.Func<T>) io.evaluable()).head()); | |
240 | else | |
241 | tmp = tmp.evaluationSkipped(); | |
242 |
1
1. lambda$null$4 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$4 → KILLED |
return tmp.creatorFormType(FUNC_HEAD); |
243 | }); | |
244 |
1
1. lambda$evaluateFunction$6 : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 1); |
245 | ret = (ValueHolder<R>) ioForHead.output().creatorFormType(FUNC_TAIL); | |
246 | } | |
247 | ValueHolder<Object> finalRet = (ValueHolder<Object>) ret; | |
248 |
1
1. lambda$evaluateFunction$6 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateFunction$6 → KILLED |
return evaluable.tail().map((Evaluable<Object> e) -> { |
249 | EvaluableIo<Object, Evaluable<Object>, R> ioForTail = createChildEvaluableIoOf(e, finalRet); | |
250 |
1
1. lambda$null$5 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("FUNC_TAIL:BEFORE", ioForTail); |
251 |
1
1. lambda$null$5 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
e.accept(ioForTail, (EvaluationContext<Object>) evaluationContext, this); |
252 |
1
1. lambda$null$5 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("FUNC_TAIL:AFTER", ioForTail); |
253 |
1
1. lambda$null$5 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$5 → KILLED |
return ioForTail.output().creatorFormType(FUNC_TAIL); |
254 | }) | |
255 | .orElse(ret); | |
256 | }); | |
257 | } | |
258 | ||
259 | @SuppressWarnings("unchecked") | |
260 | private static <T, R> ValueHolder<R> applyFunction(ValueHolder<R> ret, T in, Function<? super T, Object> function) { | |
261 | try { | |
262 | R returnedValue; | |
263 | returnedValue = (R) function.apply(in); | |
264 |
1
1. applyFunction : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::applyFunction → KILLED |
return ret.valueReturned(returnedValue); |
265 | } catch (Throwable t) { | |
266 |
1
1. applyFunction : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::applyFunction → KILLED |
return ret.exceptionThrown(t); |
267 | } | |
268 | } | |
269 | ||
270 | @SuppressWarnings({ "unchecked", "rawtypes" }) | |
271 | @Override | |
272 | public <T, R> void evaluateTransformation(EvaluableIo<T, Evaluable.Transformation<T, R>, Boolean> evaluableIo, EvaluationContext<T> evaluationContext) { | |
273 |
1
1. evaluateTransformation : negated conditional → KILLED |
if (isDummyFunction((Function<?, ?>) evaluableIo.evaluable().mapper())) { |
274 |
1
1. evaluateTransformation : removed call to com/github/dakusui/pcond/core/Evaluable::accept → NO_COVERAGE |
evaluableIo.evaluable().checker().accept((EvaluableIo<R, Evaluable<R>, Boolean>) (Evaluable) evaluableIo, (EvaluationContext<R>) evaluationContext, this); |
275 | return; | |
276 | } | |
277 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
278 |
1
1. evaluateTransformation : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate( |
279 | evaluableIo, | |
280 | (Evaluable.Transformation<T, R> evaluable, ValueHolder<T> input) -> { | |
281 |
1
1. lambda$evaluateTransformation$7 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printInput → SURVIVED |
DebuggingUtils.printInput("TRANSFORMATION:BEFORE", evaluable, input); |
282 | EvaluableIo<T, Evaluable<T>, R> mapperIo = evaluateMapper(evaluable.mapperName().orElse("transform"), evaluable.mapper(), input, childContext); | |
283 | EvaluableIo<R, Evaluable<R>, Boolean> checkerIo = evaluateChecker(evaluable.checkerName().orElse("check"), evaluable.checker(), mapperIo.output(), childContext); | |
284 |
1
1. lambda$evaluateTransformation$7 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printInputAndOutput → SURVIVED |
DebuggingUtils.printInputAndOutput(evaluable, input, checkerIo.output()); |
285 |
1
1. lambda$evaluateTransformation$7 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateTransformation$7 → KILLED |
return checkerIo.output(); |
286 | } | |
287 | ); | |
288 |
1
1. evaluateTransformation : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 1); |
289 | } | |
290 | ||
291 | private <T, R> EvaluableIo<T, Evaluable<T>, R> evaluateMapper(String mapperName, Evaluable<T> mapper, ValueHolder<T> input, EvaluationContext<T> evaluationContext) { | |
292 | EvaluableIo<T, Evaluable<T>, R> ioForMapper = createChildEvaluableIoOf(mapper, input.creatorFormType(ValueHolder.CreatorFormType.TRANSFORM)); | |
293 | { | |
294 | EvaluationContext<T> childContext = new EvaluationContext<>(evaluationContext); | |
295 | ||
296 | // #1 | |
297 |
1
1. evaluateMapper : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(TRANSFORM, mapperName, ioForMapper, io -> { |
298 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("TRANSFORM:BEFORE", io); |
299 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
io.evaluable().accept(io, childContext, this); |
300 |
1
1. lambda$evaluateMapper$8 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("TRANSFORM:AFTER", io); |
301 |
1
1. lambda$evaluateMapper$8 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateMapper$8 → KILLED |
return io.output(); |
302 | }); | |
303 | ||
304 |
1
1. evaluateMapper : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 0); |
305 | } | |
306 |
1
1. evaluateMapper : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::evaluateMapper → KILLED |
return ioForMapper; |
307 | } | |
308 | ||
309 | private <T, R> EvaluableIo<R, Evaluable<R>, Boolean> evaluateChecker(String checkerName, Evaluable<R> checker, ValueHolder<R> input, EvaluationContext<T> evaluationContext) { | |
310 | EvaluableIo<R, Evaluable<R>, Boolean> ioForChecker = createChildEvaluableIoOf(checker, input); | |
311 | { | |
312 | EvaluationContext<R> childContext = new EvaluationContext<>(evaluationContext); | |
313 | ||
314 |
1
1. evaluateChecker : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
childContext.evaluate(CHECK, checkerName, ioForChecker, io -> { |
315 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("CHECK:BEFORE", io); |
316 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
io.evaluable().accept(io, childContext, this); |
317 |
1
1. lambda$evaluateChecker$9 : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printIo → SURVIVED |
DebuggingUtils.printIo("CHECK:AFTER", io); |
318 |
1
1. lambda$evaluateChecker$9 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateChecker$9 → KILLED |
return io.output(); |
319 | }); | |
320 | ||
321 |
1
1. evaluateChecker : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext, 0); |
322 | } | |
323 |
1
1. evaluateChecker : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::evaluateChecker → KILLED |
return ioForChecker; |
324 | } | |
325 | ||
326 | // ValueToCut ValueOnCut ValueForNone(=default) | |
327 | // NoneMatch true false true | |
328 | // AnyMatch true true false | |
329 | // AllMatch false false true | |
330 | ||
331 | @Override | |
332 | public <E> void evaluateStreamPredicate(EvaluableIo<Stream<E>, Evaluable.StreamPred<E>, Boolean> evaluableIo, EvaluationContext<Stream<E>> evaluationContext) { | |
333 |
1
1. evaluateStreamPredicate : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate( |
334 | evaluableIo, | |
335 | (Evaluable.StreamPred<E> evaluable, ValueHolder<Stream<E>> input) -> input.returnedValue() | |
336 | .map((E e) -> { | |
337 |
1
1. lambda$null$10 : negated conditional → KILLED |
if (evaluable.requestExpectationFlip()) |
338 |
1
1. lambda$null$10 : removed call to com/github/dakusui/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
339 | try { | |
340 | EvaluationContext<E> childContext = new EvaluationContext<>(evaluationContext); | |
341 | EvaluableIo<E, Evaluable<E>, Boolean> ioForCutPredicate = createChildEvaluableIoOf(evaluable.cut(), ValueHolder.forValue(e)); | |
342 |
1
1. lambda$null$10 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
evaluable.cut().accept(ioForCutPredicate, childContext, this); |
343 |
1
1. lambda$null$10 : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext); |
344 |
1
1. lambda$null$10 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$10 → KILLED |
return ioForCutPredicate.output(); |
345 | } finally { | |
346 |
1
1. lambda$null$10 : negated conditional → KILLED |
if (evaluable.requestExpectationFlip()) |
347 |
1
1. lambda$null$10 : removed call to com/github/dakusui/pcond/core/EvaluationContext::flipExpectation → KILLED |
evaluationContext.flipExpectation(); |
348 | } | |
349 | }) | |
350 | .filter(eachResult -> { | |
351 |
1
1. lambda$null$11 : negated conditional → KILLED |
if (!eachResult.isValueReturned()) |
352 |
1
1. lambda$null$11 : replaced boolean return with false for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$11 → KILLED |
return true; |
353 |
2
1. lambda$null$11 : negated conditional → KILLED 2. lambda$null$11 : replaced boolean return with true for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$11 → KILLED |
return eachResult.returnedValue() == evaluable.valueToCut(); |
354 | }) | |
355 |
2
1. lambda$null$12 : negated conditional → KILLED 2. lambda$null$12 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$12 → KILLED |
.map(eachResult -> eachResult.valueReturned(!evaluable.defaultValue())) // compute Value on cut |
356 | .findFirst() | |
357 |
2
1. lambda$evaluateStreamPredicate$14 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateStreamPredicate$14 → KILLED 2. lambda$null$13 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$null$13 → KILLED |
.orElseGet(() -> ValueHolder.forValue(evaluable.defaultValue()))); // compute Value for none |
358 | } | |
359 | ||
360 | @Override | |
361 | public void evaluateCurriedContextPredicate(EvaluableIo<CurriedContext, Evaluable.CurriedContextPred, Boolean> evaluableIo, EvaluationContext<CurriedContext> evaluationContext) { | |
362 |
1
1. evaluateCurriedContextPredicate : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED |
evaluationContext.evaluate(evaluableIo, (Evaluable.CurriedContextPred evaluable, ValueHolder<CurriedContext> input) -> { |
363 | EvaluableIo<Object, Evaluable<Object>, Boolean> io = createChildEvaluableIoOf(evaluable.enclosed(), ValueHolder.forValue(input.returnedValue().valueAt(evaluable.argIndex()))); | |
364 | EvaluationContext<Object> childContext = new EvaluationContext<>(evaluationContext); | |
365 |
1
1. lambda$evaluateCurriedContextPredicate$15 : removed call to com/github/dakusui/pcond/core/Evaluable::accept → KILLED |
evaluable.enclosed().accept(io, childContext, this); |
366 |
1
1. lambda$evaluateCurriedContextPredicate$15 : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED |
evaluationContext.importEntries(childContext); |
367 |
1
1. lambda$evaluateCurriedContextPredicate$15 : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::lambda$evaluateCurriedContextPredicate$15 → KILLED |
return io.output(); |
368 | }); | |
369 | } | |
370 | ||
371 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(E evaluable, ValueHolder<T> input) { | |
372 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return createChildEvaluableIoOf(resolveEvaluationEntryType(evaluable).formName(evaluable), evaluable, input); |
373 | } | |
374 | ||
375 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(String formName, E evaluable, ValueHolder<T> input) { | |
376 | EvaluationEntry.Type evaluableType = resolveEvaluationEntryType(evaluable); | |
377 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return createChildEvaluableIoOf(evaluableType, formName, evaluable, input); |
378 | } | |
379 | ||
380 | private static <T, E extends Evaluable<T>, O> EvaluableIo<T, Evaluable<T>, O> createChildEvaluableIoOf(EvaluationEntry.Type evaluableType, String formName, E evaluable, ValueHolder<T> input) { | |
381 |
1
1. createChildEvaluableIoOf : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Impl::createChildEvaluableIoOf → KILLED |
return new EvaluableIo<>(input, evaluableType, formName, evaluable); |
382 | } | |
383 | } | |
384 | ||
385 | /** | |
386 | * If an input or an output value object of a form implements this interface, | |
387 | * The value returned by `snapshot` method is stored in a {@link EvaluationEntry} | |
388 | * record, instead of the value itself. | |
389 | * | |
390 | * An implementation of this interface should override `toString()` method to return a string form of the original state of this object. | |
391 | */ | |
392 | interface Snapshottable { | |
393 | ||
394 | Object NULL = new Object() { | |
395 | @Override | |
396 | public String toString() { | |
397 |
1
1. toString : replaced return value with "" for com/github/dakusui/pcond/core/Evaluator$Snapshottable$1::toString → SURVIVED |
return "null"; |
398 | } | |
399 | }; | |
400 | ||
401 | Object snapshot(); | |
402 | ||
403 | static Object toSnapshotIfPossible(Object value) { | |
404 |
1
1. toSnapshotIfPossible : negated conditional → KILLED |
if (value instanceof Snapshottable) |
405 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → SURVIVED |
return ((Snapshottable) value).snapshot(); |
406 |
1
1. toSnapshotIfPossible : negated conditional → KILLED |
if (value == null) |
407 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → SURVIVED |
return NULL; |
408 | else | |
409 |
1
1. toSnapshotIfPossible : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Snapshottable::toSnapshotIfPossible → KILLED |
return value; |
410 | } | |
411 | } | |
412 | ||
413 | /** | |
414 | * An interface to define methods that make a predicate "explainable" to humans. | |
415 | */ | |
416 | interface Explainable { | |
417 | Object explainOutputExpectation(); | |
418 | ||
419 | Object explainActual(Object actualValue); | |
420 | ||
421 | static Object explainOutputExpectation(Object evaluable, EvaluableIo<?, ?, ?> evaluableIo) { | |
422 |
1
1. explainOutputExpectation : negated conditional → KILLED |
if (evaluable instanceof Explainable) |
423 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainOutputExpectation → KILLED |
return explainValue(((Explainable) evaluable).explainOutputExpectation()); |
424 |
1
1. explainOutputExpectation : negated conditional → SURVIVED |
if (evaluable instanceof Evaluable) |
425 |
1
1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainOutputExpectation → SURVIVED |
return formNameOf(evaluableIo); |
426 | return null; | |
427 | } | |
428 | ||
429 | static Object explainInputActualValue(Object evaluable, Object actualValue) { | |
430 |
1
1. explainInputActualValue : negated conditional → KILLED |
if (evaluable instanceof Explainable) |
431 |
1
1. explainInputActualValue : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainInputActualValue → SURVIVED |
return explainValue(((Explainable) evaluable).explainActual(actualValue)); |
432 | return null; | |
433 | } | |
434 | ||
435 | static <T, E extends Evaluable<T>> Object explainActual(EvaluableIo<T, E, ?> evaluableIo) { | |
436 |
1
1. explainActual : negated conditional → KILLED |
if (evaluableIo.output().state() == VALUE_RETURNED) { |
437 | T ret = evaluableIo.input().returnedValue(); | |
438 |
2
1. explainActual : negated conditional → KILLED 2. explainActual : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainActual → KILLED |
return ret != null ? ret : Impl.NULL_VALUE; |
439 |
1
1. explainActual : negated conditional → KILLED |
} else if (evaluableIo.output().state() == EXCEPTION_THROWN) |
440 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainActual → KILLED |
return composeDetailOutputActualValueFromInputAndThrowable(evaluableIo.input().value(), evaluableIo.output().thrownException()); |
441 |
1
1. explainActual : negated conditional → KILLED |
else if (evaluableIo.output().state() == EVALUATION_SKIPPED) { |
442 |
1
1. explainActual : replaced return value with null for com/github/dakusui/pcond/core/Evaluator$Explainable::explainActual → SURVIVED |
return EVALUATION_SKIPPED; |
443 | } else | |
444 | throw new AssertionError("evaluableIo:" + evaluableIo); | |
445 | } | |
446 | } | |
447 | } | |
Mutations | ||
106 |
1.1 |
|
113 |
1.1 |
|
119 |
1.1 |
|
128 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
146 |
1.1 |
|
149 |
1.1 2.2 3.3 |
|
152 |
1.1 2.2 |
|
158 |
1.1 |
|
166 |
1.1 |
|
168 |
1.1 |
|
169 |
1.1 |
|
171 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
176 |
1.1 |
|
179 |
1.1 2.2 3.3 |
|
182 |
1.1 2.2 |
|
188 |
1.1 |
|
191 |
1.1 |
|
194 |
1.1 |
|
195 |
1.1 2.2 |
|
196 |
1.1 |
|
199 |
1.1 |
|
207 |
1.1 |
|
212 |
1.1 |
|
216 |
1.1 |
|
218 |
1.1 |
|
221 |
1.1 |
|
228 |
1.1 |
|
236 |
1.1 |
|
238 |
1.1 |
|
242 |
1.1 |
|
244 |
1.1 |
|
248 |
1.1 |
|
250 |
1.1 |
|
251 |
1.1 |
|
252 |
1.1 |
|
253 |
1.1 |
|
264 |
1.1 |
|
266 |
1.1 |
|
273 |
1.1 |
|
274 |
1.1 |
|
278 |
1.1 |
|
281 |
1.1 |
|
284 |
1.1 |
|
285 |
1.1 |
|
288 |
1.1 |
|
297 |
1.1 |
|
298 |
1.1 |
|
299 |
1.1 |
|
300 |
1.1 |
|
301 |
1.1 |
|
304 |
1.1 |
|
306 |
1.1 |
|
314 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 |
|
318 |
1.1 |
|
321 |
1.1 |
|
323 |
1.1 |
|
333 |
1.1 |
|
337 |
1.1 |
|
338 |
1.1 |
|
342 |
1.1 |
|
343 |
1.1 |
|
344 |
1.1 |
|
346 |
1.1 |
|
347 |
1.1 |
|
351 |
1.1 |
|
352 |
1.1 |
|
353 |
1.1 2.2 |
|
355 |
1.1 2.2 |
|
357 |
1.1 2.2 |
|
362 |
1.1 |
|
365 |
1.1 |
|
366 |
1.1 |
|
367 |
1.1 |
|
372 |
1.1 |
|
377 |
1.1 |
|
381 |
1.1 |
|
397 |
1.1 |
|
404 |
1.1 |
|
405 |
1.1 |
|
406 |
1.1 |
|
407 |
1.1 |
|
409 |
1.1 |
|
422 |
1.1 |
|
423 |
1.1 |
|
424 |
1.1 |
|
425 |
1.1 |
|
430 |
1.1 |
|
431 |
1.1 |
|
436 |
1.1 |
|
438 |
1.1 2.2 |
|
439 |
1.1 |
|
440 |
1.1 |
|
441 |
1.1 |
|
442 |
1.1 |