EvaluationContext.java

1
package com.github.dakusui.pcond.core;
2
3
import java.util.ArrayList;
4
import java.util.LinkedList;
5
import java.util.List;
6
import java.util.function.BiFunction;
7
import java.util.function.Function;
8
9
import static com.github.dakusui.pcond.core.EvaluationEntry.Type.*;
10
import static java.util.Objects.requireNonNull;
11
12
/**
13
 * The new design:
14
 *
15
 * Evaluator: Concentrates on "evaluate" an individual evaluable (form). No aware of how to compose evaluation entries.
16
 */
17
18
public class EvaluationContext<T> {
19
  final List<EvaluationEntry> evaluationEntries = new LinkedList<>();
20
  final List<EvaluationEntry> visitorLineage    = new LinkedList<>();
21
22
  boolean expectationFlipped = false;
23
24
  public EvaluationContext() {
25
  }
26
27
  public EvaluationContext(EvaluationContext<?> parent) {
28
    this.expectationFlipped = parent.isExpectationFlipped();
29
  }
30
31
  /**
32
   * @param evaluableIo       An object to hold a form and its I/O.
33
   * @param evaluatorCallback A callback that executes a logic specific to the {@code evaluable}.
34
   */
35
  public <E extends Evaluable<T>, O> void evaluate(EvaluableIo<T, E, O> evaluableIo, BiFunction<E, ValueHolder<T>, ValueHolder<O>> evaluatorCallback) {
36 1 1. evaluate : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED
    evaluate(resolveEvaluationEntryType(evaluableIo.evaluable()), evaluableIo, evaluatorCallback);
37
  }
38
39
  public <E extends Evaluable<T>, O> void evaluate(EvaluationEntry.Type type, EvaluableIo<T, E, O> evaluableIo, BiFunction<E, ValueHolder<T>, ValueHolder<O>> evaluatorCallback) {
40 2 1. evaluate : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED
2. lambda$evaluate$0 : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::lambda$evaluate$0 → KILLED
    evaluate(type, evaluableIo, io -> evaluatorCallback.apply(io.evaluable(), io.input()));
41
  }
42
43
  public <E extends Evaluable<T>, O> void evaluate(EvaluationEntry.Type type, EvaluableIo<T, E, O> evaluableIo, Function<EvaluableIo<T, E, O>, ValueHolder<O>> function) {
44 1 1. evaluate : removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED
    evaluate(type, formNameOf(evaluableIo), evaluableIo, function);
45
  }
46
47
  public <E extends Evaluable<T>, O> void evaluate(EvaluationEntry.Type type, String formName, EvaluableIo<T, E, O> evaluableIo, Function<EvaluableIo<T, E, O>, ValueHolder<O>> function) {
48
    requireNonNull(evaluableIo);
49
    EvaluableIo<T, E, O> evaluableIoWork = this.enter(evaluableIo.input(), type, formName, evaluableIo.evaluable());
50 1 1. evaluate : removed call to com/github/dakusui/pcond/core/EvaluationContext::leave → KILLED
    this.leave(evaluableIoWork, function.apply(evaluableIoWork));
51 1 1. evaluate : removed call to com/github/dakusui/pcond/core/DebuggingUtils::printTo → SURVIVED
    DebuggingUtils.printTo(this, System.err, 1);
52 1 1. evaluate : removed call to com/github/dakusui/pcond/core/EvaluationContext::updateEvaluableIo → KILLED
    updateEvaluableIo(evaluableIo, evaluableIoWork);
53
  }
54
55
  public static String formNameOf(EvaluableIo<?, ?, ?> evaluableIo) {
56 1 1. formNameOf : replaced return value with "" for com/github/dakusui/pcond/core/EvaluationContext::formNameOf → KILLED
    return formNameOf(evaluableIo.evaluableType(), evaluableIo.evaluable());
57
  }
58
59
  public static String formNameOf(EvaluationEntry.Type type, Evaluable<?> e) {
60 1 1. formNameOf : replaced return value with "" for com/github/dakusui/pcond/core/EvaluationContext::formNameOf → KILLED
    return type.formName(e);
61
  }
62
63
  public boolean isExpectationFlipped() {
64 2 1. isExpectationFlipped : replaced boolean return with false for com/github/dakusui/pcond/core/EvaluationContext::isExpectationFlipped → KILLED
2. isExpectationFlipped : replaced boolean return with true for com/github/dakusui/pcond/core/EvaluationContext::isExpectationFlipped → KILLED
    return this.expectationFlipped;
65
  }
66
67
  public void flipExpectation() {
68 1 1. flipExpectation : negated conditional → KILLED
    this.expectationFlipped = !expectationFlipped;
69
  }
70
71
  private static <T, E extends Evaluable<T>, O> void updateEvaluableIo(EvaluableIo<T, E, O> evaluableIo, EvaluableIo<T, E, O> evaluableIoWork) {
72 1 1. updateEvaluableIo : removed call to com/github/dakusui/pcond/core/EvaluableIo::output → KILLED
    evaluableIo.output(evaluableIoWork.output());
73
  }
74
75
  public static <T> EvaluationEntry.Type resolveEvaluationEntryType(Evaluable<T> evaluable) {
76 3 1. resolveEvaluationEntryType : negated conditional → KILLED
2. resolveEvaluationEntryType : negated conditional → KILLED
3. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.LeafPred || evaluable instanceof Evaluable.CurriedContextPred || evaluable instanceof Evaluable.StreamPred)
77 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return LEAF;
78 1 1. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.Func)
79 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return FUNCTION;
80 1 1. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.Conjunction)
81 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return AND;
82 1 1. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.Disjunction)
83 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return OR;
84 1 1. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.Negation)
85 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return NOT;
86 1 1. resolveEvaluationEntryType : negated conditional → KILLED
    if (evaluable instanceof Evaluable.Transformation)
87 1 1. resolveEvaluationEntryType : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED
      return TRANSFORM_AND_CHECK;
88
    throw new IllegalArgumentException();
89
  }
90
91
  @SuppressWarnings("unchecked")
92
  private <E extends Evaluable<T>, O> EvaluableIo<T, E, O> enter(ValueHolder<T> input, EvaluationEntry.Type type, String formName, E evaluable) {
93
    EvaluableIo<T, Evaluable<T>, O> ret = createEvaluableIo(input, type, formName, evaluable);
94
    this.evaluationEntries.add(createEvaluationEntry(this, ret));
95 1 1. enter : Replaced integer subtraction with addition → KILLED
    this.visitorLineage.add(evaluationEntries.get(evaluationEntries.size() - 1));
96 1 1. enter : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::enter → KILLED
    return (EvaluableIo<T, E, O>) ret;
97
  }
98
99
  private <E extends Evaluable<T>, O> void leave(EvaluableIo<T, E, O> evaluableIo, ValueHolder<O> output) {
100 1 1. leave : Replaced integer subtraction with addition → KILLED
    EvaluationEntry.Impl currentEvaluationEntry = (EvaluationEntry.Impl) this.visitorLineage.remove(this.visitorLineage.size() - 1);
101 1 1. leave : removed call to com/github/dakusui/pcond/core/EvaluableIo::output → KILLED
    evaluableIo.output(output);
102 1 1. leave : removed call to com/github/dakusui/pcond/core/EvaluationEntry$Impl::finalizeValues → KILLED
    currentEvaluationEntry.finalizeValues();
103
  }
104
105
  private static <T, O> EvaluableIo<T, Evaluable<T>, O> createEvaluableIo(ValueHolder<T> input, EvaluationEntry.Type type, String formName, Evaluable<T> evaluable) {
106 1 1. createEvaluableIo : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::createEvaluableIo → KILLED
    return new EvaluableIo<>(input, type, formName, evaluable);
107
  }
108
109
  private static <T, E extends Evaluable<T>> EvaluationEntry createEvaluationEntry(
110
      EvaluationContext<T> evaluationContext,
111
      EvaluableIo<T, E, ?> evaluableIo) {
112 1 1. createEvaluationEntry : replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::createEvaluationEntry → KILLED
    return new EvaluationEntry.Impl(evaluationContext, evaluableIo);
113
  }
114
115
  public List<EvaluationEntry> resultEntries() {
116 1 1. resultEntries : replaced return value with Collections.emptyList for com/github/dakusui/pcond/core/EvaluationContext::resultEntries → KILLED
    return new ArrayList<>(this.evaluationEntries);
117
  }
118
119
  public <R> void importEntries(EvaluationContext<R> childContext) {
120 1 1. importEntries : removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED
    importEntries(childContext, currentIndentLevel());
121
  }
122
123
  public <R> void importEntries(EvaluationContext<R> childContext, int indentLevelGap) {
124 2 1. importEntries : removed call to java/util/List::forEach → SURVIVED
2. lambda$importEntries$1 : Replaced integer addition with subtraction → SURVIVED
    childContext.evaluationEntries.forEach(each -> each.level += indentLevelGap);
125
    this.evaluationEntries.addAll(childContext.resultEntries());
126
  }
127
128
  public int currentIndentLevel() {
129 1 1. currentIndentLevel : replaced int return with 0 for com/github/dakusui/pcond/core/EvaluationContext::currentIndentLevel → SURVIVED
    return this.visitorLineage.size();
130
  }
131
}

Mutations

36

1.1
Location : evaluate
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED

40

1.1
Location : evaluate
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED

2.2
Location : lambda$evaluate$0
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::lambda$evaluate$0 → KILLED

44

1.1
Location : evaluate
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::evaluate → KILLED

50

1.1
Location : evaluate
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::leave → KILLED

51

1.1
Location : evaluate
Killed by : none
removed call to com/github/dakusui/pcond/core/DebuggingUtils::printTo → SURVIVED

52

1.1
Location : evaluate
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::updateEvaluableIo → KILLED

56

1.1
Location : formNameOf
Killed by : com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest.test(com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest)
replaced return value with "" for com/github/dakusui/pcond/core/EvaluationContext::formNameOf → KILLED

60

1.1
Location : formNameOf
Killed by : com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest.test(com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest)
replaced return value with "" for com/github/dakusui/pcond/core/EvaluationContext::formNameOf → KILLED

64

1.1
Location : isExpectationFlipped
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced boolean return with false for com/github/dakusui/pcond/core/EvaluationContext::isExpectationFlipped → KILLED

2.2
Location : isExpectationFlipped
Killed by : com.github.dakusui.ut.thincrest.ut.ReportDetailTest.givenLongString_whenCheckEqualnessUsingCustomPredicateWithSlightlyDifferentString_thenFailWithDetailsArePrinted(com.github.dakusui.ut.thincrest.ut.ReportDetailTest)
replaced boolean return with true for com/github/dakusui/pcond/core/EvaluationContext::isExpectationFlipped → KILLED

68

1.1
Location : flipExpectation
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
negated conditional → KILLED

72

1.1
Location : updateEvaluableIo
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluableIo::output → KILLED

76

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withEvaluator_nativePredicate(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
negated conditional → KILLED

2.2
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.givenStreamOfSingleString$hello$_whenRequireNonNullIsFound_thenPassing(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
negated conditional → KILLED

3.3
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStreamTest.test_allMatch(com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStreamTest)
negated conditional → KILLED

77

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withEvaluator_nativePredicate(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

78

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withoutEvaluator_conj_thenPass(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
negated conditional → KILLED

79

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.hello_b3(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

80

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withoutEvaluator_conj_thenPass(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
negated conditional → KILLED

81

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withoutEvaluator_conj_thenPass(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

82

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
negated conditional → KILLED

83

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest.whenIsInstanceOfUsedInComposite_thenNoExplicitTypeParameterIsNeeded(com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

84

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
negated conditional → KILLED

85

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.testValidateMethod$passing(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

86

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.hello_b3(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
negated conditional → KILLED

87

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.hello_b3(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

95

1.1
Location : enter
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
Replaced integer subtraction with addition → KILLED

96

1.1
Location : enter
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::enter → KILLED

100

1.1
Location : leave
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
Replaced integer subtraction with addition → KILLED

101

1.1
Location : leave
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
removed call to com/github/dakusui/pcond/core/EvaluableIo::output → KILLED

102

1.1
Location : leave
Killed by : com.github.dakusui.ut.valid8j.compatibility.BooleanTest.testIsTrue(com.github.dakusui.ut.valid8j.compatibility.BooleanTest)
removed call to com/github/dakusui/pcond/core/EvaluationEntry$Impl::finalizeValues → KILLED

106

1.1
Location : createEvaluableIo
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::createEvaluableIo → KILLED

112

1.1
Location : createEvaluationEntry
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/EvaluationContext::createEvaluationEntry → KILLED

116

1.1
Location : resultEntries
Killed by : com.github.dakusui.ut.thincrest.ut.ReportDetailTest.givenLongString_whenCheckEqualnessUsingCustomPredicateWithSlightlyDifferentString_thenFailWithDetailsArePrinted(com.github.dakusui.ut.thincrest.ut.ReportDetailTest)
replaced return value with Collections.emptyList for com/github/dakusui/pcond/core/EvaluationContext::resultEntries → KILLED

120

1.1
Location : importEntries
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.givenString$hello$_whenTransformToContextAndCheckContextValueIsNull_thenPreconditionViolationWithCorrectMessageThrown(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
removed call to com/github/dakusui/pcond/core/EvaluationContext::importEntries → KILLED

124

1.1
Location : importEntries
Killed by : none
removed call to java/util/List::forEach → SURVIVED

2.2
Location : lambda$importEntries$1
Killed by : none
Replaced integer addition with subtraction → SURVIVED

129

1.1
Location : currentIndentLevel
Killed by : none
replaced int return with 0 for com/github/dakusui/pcond/core/EvaluationContext::currentIndentLevel → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.7.3