CurriedFunction.java

1
package com.github.valid8j.pcond.experimentals.currying;
2
3
import com.github.valid8j.pcond.experimentals.currying.multi.MultiFunction;
4
import com.github.valid8j.pcond.internals.InternalUtils;
5
6
import java.util.List;
7
import java.util.NoSuchElementException;
8
import java.util.function.Function;
9
10
public interface CurriedFunction<T, R> extends Function<T, R> {
11
  R applyFunction(T value);
12
13
  default R apply(T value) {
14 1 1. apply : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::apply → KILLED
    return Checks.ensureReturnedValueType(this.applyFunction(validateArg(value)), returnType());
15
  }
16
17
  @SuppressWarnings("unchecked")
18
  default <V> V applyLast(T value) {
19 1 1. applyLast : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyLast → KILLED
    return (V) Checks.requireLast(this).apply(value);
20
  }
21
22
  @SuppressWarnings("unchecked")
23
  default <V extends CurriedFunction<T, R>> V applyNext(T value) {
24 1 1. applyNext : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyNext → KILLED
    return (V) requireHasNext(this).apply(value);
25
  }
26
27
  static <V extends CurriedFunction<T, R>, T, R> V requireHasNext(V value) {
28 1 1. requireHasNext : negated conditional → KILLED
    if (!value.hasNext())
29
      throw new NoSuchElementException();
30 1 1. requireHasNext : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::requireHasNext → KILLED
    return value;
31
  }
32
33
  Class<?> parameterType();
34
35
  Class<?> returnType();
36
37
  default boolean hasNext() {
38 2 1. hasNext : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED
2. hasNext : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED
    return CurriedFunction.class.isAssignableFrom(returnType());
39
  }
40
41
  default boolean isValidArg(Object arg) {
42 2 1. isValidArg : replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED
2. isValidArg : replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED
    return Checks.isValidValueForType(arg, this.parameterType());
43
  }
44
45
  default <V> V validateArg(V arg) {
46 1 1. validateArg : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::validateArg → KILLED
    return Checks.validateArgumentType(arg, parameterType(), CurryingUtils.messageInvalidTypeArgument(arg, parameterType()));
47
  }
48
49
  class Impl implements CurriedFunction<Object, Object> {
50
    private final MultiFunction<Object> function;
51
    private final List<? super Object>  ongoingContext;
52
53
    public Impl(MultiFunction<Object> function, List<? super Object> ongoingContext) {
54
      this.function = function;
55
      this.ongoingContext = ongoingContext;
56
    }
57
58
    @Override
59
    public Class<?> parameterType() {
60 1 1. parameterType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::parameterType → KILLED
      return function.parameterType(ongoingContext.size());
61
    }
62
63
    @Override
64
    public Class<?> returnType() {
65 2 1. returnType : Replaced integer subtraction with addition → KILLED
2. returnType : negated conditional → KILLED
      if (ongoingContext.size() == function.arity() - 1)
66 1 1. returnType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED
        return function.returnType();
67
      else
68 1 1. returnType : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED
        return CurriedFunction.class;
69
    }
70
71
    @Override
72
    public Object applyFunction(Object p) {
73 2 1. applyFunction : Replaced integer subtraction with addition → KILLED
2. applyFunction : negated conditional → KILLED
      if (ongoingContext.size() == function.arity() - 1)
74 1 1. applyFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED
        return function.apply(InternalUtils.append(ongoingContext, p));
75 1 1. applyFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED
      return CurryingUtils.curry(function, InternalUtils.append(ongoingContext, p));
76
    }
77
  }
78
}

Mutations

14

1.1
Location : apply
Killed by : com.github.valid8j.ut.internal.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.valid8j.ut.internal.FunctionsTest$SizeTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::apply → KILLED

19

1.1
Location : applyLast
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyExpectedTimes$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyLast → KILLED

24

1.1
Location : applyNext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::applyNext → KILLED

28

1.1
Location : requireHasNext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyWithInvalidArg$thenThrown(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

30

1.1
Location : requireHasNext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::requireHasNext → KILLED

38

1.1
Location : hasNext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED

2.2
Location : hasNext
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::hasNext → KILLED

42

1.1
Location : isValidArg
Killed by : com.github.valid8j.ut.currying.CurryingTest.given_nullToCurriedFuncWithStringParam$whenIsValidArg$thenTrue(com.github.valid8j.ut.currying.CurryingTest)
replaced boolean return with false for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED

2.2
Location : isValidArg
Killed by : com.github.valid8j.ut.currying.CurryingTest.given_nullToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.valid8j.ut.currying.CurryingTest)
replaced boolean return with true for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::isValidArg → KILLED

46

1.1
Location : validateArg
Killed by : com.github.valid8j.ut.internal.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.valid8j.ut.internal.FunctionsTest$SizeTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction::validateArg → KILLED

60

1.1
Location : parameterType
Killed by : com.github.valid8j.ut.currying.CurryingTest.given_nullToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::parameterType → KILLED

65

1.1
Location : returnType
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
Replaced integer subtraction with addition → KILLED

2.2
Location : returnType
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

66

1.1
Location : returnType
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED

68

1.1
Location : returnType
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::returnType → KILLED

73

1.1
Location : applyFunction
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyExpectedTimes$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
Replaced integer subtraction with addition → KILLED

2.2
Location : applyFunction
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
negated conditional → KILLED

74

1.1
Location : applyFunction
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyExpectedTimes$thenExpectedResultReturned(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED

75

1.1
Location : applyFunction
Killed by : com.github.valid8j.ut.currying.CurryingTest.givenCurriedFunction$whenApplyNextMoreThanExpected$thenNoSuchElementIsThrown(com.github.valid8j.ut.currying.CurryingTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunction$Impl::applyFunction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3