PrintableFunction.java

1
package com.github.dakusui.pcond.core.printable;
2
3
import com.github.dakusui.pcond.core.Evaluable;
4
import com.github.dakusui.pcond.core.Evaluator;
5
import com.github.dakusui.pcond.experimentals.currying.CurriedFunction;
6
import com.github.dakusui.pcond.core.identifieable.Identifiable;
7
8
import java.util.List;
9
import java.util.Objects;
10
import java.util.Optional;
11
import java.util.function.Function;
12
import java.util.function.Supplier;
13
14
public class PrintableFunction<T, R> extends
15
    Identifiable.Base implements
16
    Evaluable.Func<T>,
17
    CurriedFunction<T, R>,
18
    Evaluator.Explainable,
19
    Cloneable {
20
  final         Function<? super T, ? extends R> function;
21
  private final Function<? super T, Object>           head;
22
  private final Evaluable<Object>                tail;
23
  private final Supplier<String>                 formatter;
24
  private final Function<?, R>                   tailAsFunction;
25
26
  boolean trivial = false;
27
28
  @SuppressWarnings("unchecked")
29
  protected PrintableFunction(Object creator, List<Object> args, Supplier<String> s, Function<? super T, ? extends R> function, Function<? super T, ?> head, Evaluable<?> tail) {
30
    super(creator, args);
31
    this.formatter = Objects.requireNonNull(s);
32
    this.function = requireNonPrintableFunction(unwrap(Objects.requireNonNull(function)));
33 1 1. <init> : negated conditional → KILLED
    this.head = head != null ? (Function<? super T, Object>) head : (Function<? super T, Object>) this;
34
    this.tail = (Evaluable<Object>) tail;
35
    this.tailAsFunction = (Function<?, R>) tail;
36
  }
37
38
  protected PrintableFunction(Object creator, List<Object> args, Supplier<String> s, Function<? super T, ? extends R> function) {
39
    this(creator, args, s, function, null, null);
40
  }
41
42
  @Override
43
  public String toString() {
44 1 1. toString : replaced return value with "" for com/github/dakusui/pcond/core/printable/PrintableFunction::toString → KILLED
    return this.formatter.get();
45
  }
46
47
  @Override
48
  public <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
49
    Objects.requireNonNull(before);
50 1 1. compose : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::compose → KILLED
    return PrintableFunctionFactory.<V, T, R>compose(before, this);
51
  }
52
53
  @SuppressWarnings("unchecked")
54
  @Override
55
  public <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
56
    Objects.requireNonNull(after);
57 1 1. andThen : negated conditional → KILLED
    @SuppressWarnings("rawtypes") Function f = this.tailAsFunction == null ? after : PrintableFunctionFactory.compose((Function) this.tailAsFunction, after);
58 1 1. andThen : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::andThen → KILLED
    return PrintableFunctionFactory.compose(this.head, f);
59
  }
60
61
  @Override
62
  public Function<? super T, Object> head() {
63 1 1. head : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::head → KILLED
    return this.head;
64
  }
65
66
  @Override
67
  public Optional<Evaluable<Object>> tail() {
68 1 1. tail : replaced return value with Optional.empty for com/github/dakusui/pcond/core/printable/PrintableFunction::tail → KILLED
    return Optional.ofNullable(this.tail);
69
  }
70
71
  @Override
72
  public R applyFunction(T value) {
73 1 1. applyFunction : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::applyFunction → KILLED
    return this.function.apply(value);
74
  }
75
76
  @SuppressWarnings("unchecked")
77
  @Override
78
  public Class<?> parameterType() {
79 2 1. parameterType : negated conditional → KILLED
2. parameterType : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::parameterType → KILLED
    return function instanceof CurriedFunction ?
80
        ((CurriedFunction<? super T, ? extends R>) function).parameterType() :
81
        Object.class;
82
  }
83
84
  @SuppressWarnings("unchecked")
85
  @Override
86
  public Class<? extends R> returnType() {
87 2 1. returnType : negated conditional → KILLED
2. returnType : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::returnType → KILLED
    return function instanceof CurriedFunction ?
88
        (Class<? extends R>) ((CurriedFunction<? super T, ? extends R>) function).returnType() :
89
        (Class<? extends R>) Object.class;
90
  }
91
92
  @Override
93
  public Object explainOutputExpectation() {
94 1 1. explainOutputExpectation : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainOutputExpectation → KILLED
    return this.head();
95
  }
96
97
  @Override
98
  public Object explainActual(Object actualValue) {
99 1 1. explainActual : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainActual → SURVIVED
    return actualValue;
100
  }
101
102
  @SuppressWarnings("unchecked")
103
  public static <T, R> Function<T, R> unwrap(Function<T, R> function) {
104
    Function<T, R> ret = function;
105 1 1. unwrap : negated conditional → KILLED
    if (function instanceof PrintableFunction) {
106
      ret = (Function<T, R>) ((PrintableFunction<T, R>) function).function;
107
      assert !(ret instanceof PrintableFunction);
108
    }
109 1 1. unwrap : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::unwrap → KILLED
    return ret;
110
  }
111
112
113
  @SuppressWarnings({ "CloneDoesntDeclareCloneNotSupportedException", "unchecked" })
114
  @Override
115
  protected PrintableFunction<T, R> clone() {
116
    try {
117 1 1. clone : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::clone → NO_COVERAGE
      return (PrintableFunction<T, R>) super.clone();
118
    } catch (CloneNotSupportedException e) {
119
      throw new AssertionError();
120
    }
121
  }
122
123
124
  public boolean isSquashable() {
125 2 1. isSquashable : replaced boolean return with false for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED
2. isSquashable : replaced boolean return with true for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED
    return this.trivial;
126
  }
127
128
  @Override
129
  public PrintableFunction<T, R> makeTrivial() {
130
    PrintableFunction<T, R> ret = this.clone();
131
    ret.trivial = true;
132 1 1. makeTrivial : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::makeTrivial → NO_COVERAGE
    return ret;
133
  }
134
135
  private static <T, R> Function<T, R> requireNonPrintableFunction(Function<T, R> function) {
136
    assert !(function instanceof PrintableFunction);
137 1 1. requireNonPrintableFunction : replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::requireNonPrintableFunction → KILLED
    return function;
138
  }
139
}

Mutations

33

1.1
Location : <init>
Killed by : com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest.givenFunctionReturnedByAndThen$whenToString$thenLooksGood(com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest)
negated conditional → KILLED

44

1.1
Location : toString
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$StreamTest.whenToString$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$StreamTest)
replaced return value with "" for com/github/dakusui/pcond/core/printable/PrintableFunction::toString → KILLED

50

1.1
Location : compose
Killed by : com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest.givenFunctionReturnedByCompose$whenToString$thenLooksGood(com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::compose → KILLED

57

1.1
Location : andThen
Killed by : com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest.givenFunctionReturnedByAndThen$whenToString$thenLooksGood(com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest)
negated conditional → KILLED

58

1.1
Location : andThen
Killed by : com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest.givenFunctionReturnedByAndThen$whenToString$thenLooksGood(com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::andThen → KILLED

63

1.1
Location : head
Killed by : com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest.givenFunctionReturnedByAndThen$whenToString$thenLooksGood(com.github.dakusui.pcond.ut.PrintablesTest$FunctionTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::head → KILLED

68

1.1
Location : tail
Killed by : com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.expectedExceptionThrown_testPassing(com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
replaced return value with Optional.empty for com/github/dakusui/pcond/core/printable/PrintableFunction::tail → KILLED

73

1.1
Location : applyFunction
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$SizeTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::applyFunction → KILLED

79

1.1
Location : parameterType
Killed by : com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest.testDummyFunction(com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest)
negated conditional → KILLED

2.2
Location : parameterType
Killed by : com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest.testDummyFunction(com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::parameterType → KILLED

87

1.1
Location : returnType
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$SizeTest)
negated conditional → KILLED

2.2
Location : returnType
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$SizeTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::returnType → KILLED

94

1.1
Location : explainOutputExpectation
Killed by : com.github.dakusui.pcond.propertybased.tests.StreamNoneMatchPredicateTest.exerciseTestCase[0: givenStreamPredicate$RequireConditionResultingInNPE$_whenUnexpectedValue_thenComparisonFailure2](com.github.dakusui.pcond.propertybased.tests.StreamNoneMatchPredicateTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainOutputExpectation → KILLED

99

1.1
Location : explainActual
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::explainActual → SURVIVED

105

1.1
Location : unwrap
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest.whenHashCode$thenSameIsSameAndDifferentIsDifferent(com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest)
negated conditional → KILLED

109

1.1
Location : unwrap
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::unwrap → KILLED

117

1.1
Location : clone
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::clone → NO_COVERAGE

125

1.1
Location : isSquashable
Killed by : none
replaced boolean return with false for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED

2.2
Location : isSquashable
Killed by : none
replaced boolean return with true for com/github/dakusui/pcond/core/printable/PrintableFunction::isSquashable → SURVIVED

132

1.1
Location : makeTrivial
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::makeTrivial → NO_COVERAGE

137

1.1
Location : requireNonPrintableFunction
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$ElementAtTest)
replaced return value with null for com/github/dakusui/pcond/core/printable/PrintableFunction::requireNonPrintableFunction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3