EvaluationContext.java

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

Mutations

35

1.1
Location : evaluate
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED

39

1.1
Location : evaluate
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED

2.2
Location : lambda$evaluate$0
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::lambda$evaluate$0 → KILLED

43

1.1
Location : evaluate
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluationContext::evaluate → KILLED

49

1.1
Location : evaluate
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluationContext::leave → KILLED

50

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

51

1.1
Location : evaluate
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluationContext::updateEvaluableIo → KILLED

55

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

59

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

63

1.1
Location : isExpectationFlipped
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
replaced boolean return with false for com/github/valid8j/pcond/core/EvaluationContext::isExpectationFlipped → KILLED

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

67

1.1
Location : flipExpectation
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
negated conditional → KILLED

71

1.1
Location : updateEvaluableIo
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluableIo::output → KILLED

75

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.EnsuresTest.givenValidArgument_whenEnsure_thenValueReturned(com.github.valid8j.entrypoints.EnsuresTest)
negated conditional → KILLED

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

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

76

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.EnsuresTest.givenValidArgument_whenEnsure_thenValueReturned(com.github.valid8j.entrypoints.EnsuresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

77

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

78

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.RequiresTest.testRequireWithCustomStringTransformingPredicateAndSatisfyingValue(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

79

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

80

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

81

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
negated conditional → KILLED

82

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

83

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
negated conditional → KILLED

84

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.AssertionsTest$MessageTest.givenLambda$whenPreconditionExercised_thenTrueReturned(com.github.valid8j.entrypoints.AssertionsTest$MessageTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

85

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.RequiresTest.testRequireWithCustomStringTransformingPredicateAndSatisfyingValue(com.github.valid8j.entrypoints.RequiresTest)
negated conditional → KILLED

86

1.1
Location : resolveEvaluationEntryType
Killed by : com.github.valid8j.entrypoints.RequiresTest.testRequireWithCustomStringTransformingPredicateAndSatisfyingValue(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::resolveEvaluationEntryType → KILLED

94

1.1
Location : enter
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
Replaced integer subtraction with addition → KILLED

95

1.1
Location : enter
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::enter → KILLED

99

1.1
Location : leave
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
Replaced integer subtraction with addition → KILLED

100

1.1
Location : leave
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
removed call to com/github/valid8j/pcond/core/EvaluableIo::output → KILLED

101

1.1
Location : leave
Killed by : com.github.valid8j.entrypoints.EnsuresTest.testEnsureState(com.github.valid8j.entrypoints.EnsuresTest)
removed call to com/github/valid8j/pcond/core/EvaluationEntry$Impl::finalizeValues → KILLED

105

1.1
Location : createEvaluableIo
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::createEvaluableIo → KILLED

111

1.1
Location : createEvaluationEntry
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/EvaluationContext::createEvaluationEntry → KILLED

115

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

119

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

123

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

128

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

Active mutators

Tests examined


Report generated by PIT 1.7.3