Checks.java

1
package com.github.dakusui.pcond.experimentals.currying;
2
3
import com.github.dakusui.pcond.internals.InternalChecks;
4
5
import java.util.function.Supplier;
6
7
import static com.github.dakusui.pcond.internals.InternalUtils.formatObject;
8
import static com.github.dakusui.pcond.internals.InternalUtils.wrapperClassOf;
9
import static java.lang.String.format;
10
11
/**
12
 * A utility class for checking values that the "currying" mechanism of the `pcond`
13
 * library processes.
14
 */
15
public enum Checks {
16
  ;
17
18
  static <T extends CurriedFunction<?, ?>> T requireLast(T value) {
19 1 1. requireLast : negated conditional → KILLED
    if (value.hasNext())
20
      throw new IllegalStateException();
21 1 1. requireLast : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/Checks::requireLast → KILLED
    return value;
22
  }
23
24
  /**
25
   * Validates if a given argument value is appropriate for a parameter type (`paramType`).
26
   *
27
   * @param arg              An argument value is to check with `paramType`.
28
   * @param paramType        An expected type for `arg`.
29
   * @param messageFormatter A message formatter which generates a message on a failure.
30
   * @param <T>              The type of the argument value.
31
   * @return The `arg` value itself.
32
   */
33
  static <T> T validateArgumentType(T arg, Class<?> paramType, Supplier<String> messageFormatter) {
34 1 1. validateArgumentType : removed call to com/github/dakusui/pcond/internals/InternalChecks::checkArgument → KILLED
    InternalChecks.checkArgument(isValidValueForType(arg, paramType), messageFormatter);
35 1 1. validateArgumentType : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/Checks::validateArgumentType → KILLED
    return arg;
36
  }
37
38
  static boolean isValidValueForType(Object arg, Class<?> paramType) {
39 1 1. isValidValueForType : negated conditional → KILLED
    if (paramType.isPrimitive()) {
40 1 1. isValidValueForType : negated conditional → KILLED
      if (arg == null)
41 2 1. isValidValueForType : replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → SURVIVED
2. isValidValueForType : replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
        return paramType.equals(void.class);
42 1 1. isValidValueForType : negated conditional → KILLED
      if (InternalChecks.isPrimitiveWrapperClassOrPrimitive(arg.getClass())) {
43
        Class<?> wrapperClassForParamType = wrapperClassOf(paramType);
44 1 1. isValidValueForType : negated conditional → KILLED
        if (wrapperClassForParamType.equals(arg.getClass()))
45 1 1. isValidValueForType : replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
          return true;
46 2 1. isValidValueForType : replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
2. isValidValueForType : replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
        return InternalChecks.isWiderThan(wrapperClassForParamType, arg.getClass());
47
      }
48 1 1. isValidValueForType : replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
      return false;
49
    } else {
50 1 1. isValidValueForType : negated conditional → KILLED
      if (arg == null)
51 1 1. isValidValueForType : replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
        return true;
52 2 1. isValidValueForType : replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
2. isValidValueForType : replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED
      return paramType.isAssignableFrom(arg.getClass());
53
    }
54
  }
55
56
  @SuppressWarnings("unchecked")
57
  static <T> T ensureReturnedValueType(Object value, Class<?> returnType) {
58 1 1. ensureReturnedValueType : negated conditional → KILLED
    if (isValidValueForType(value, returnType))
59 1 1. ensureReturnedValueType : replaced return value with null for com/github/dakusui/pcond/experimentals/currying/Checks::ensureReturnedValueType → KILLED
      return (T) value;
60
    else
61
      throw new IllegalStateException("Returned value:"
62 1 1. ensureReturnedValueType : negated conditional → KILLED
          + formatObject(value)
63
          + (value != null ? "(" + value.getClass().getName() + ")" : "")
64
          + " is neither null nor an instance of " + returnType.getName() + ". ");
65
  }
66
}

Mutations

19

1.1
Location : requireLast
Killed by : com.github.dakusui.pcond.ut.CurryingTest.givenCurriedFunction$whenApplyLastBeforeLast$thenIllegalStateIsThrown(com.github.dakusui.pcond.ut.CurryingTest)
negated conditional → KILLED

21

1.1
Location : requireLast
Killed by : com.github.dakusui.pcond.ut.CurryingTest.test3(com.github.dakusui.pcond.ut.CurryingTest)
replaced return value with null for com/github/dakusui/pcond/experimentals/currying/Checks::requireLast → KILLED

34

1.1
Location : validateArgumentType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.givenCurriedFunction$whenApplyWithInvalidArg$thenThrown(com.github.dakusui.pcond.ut.CurryingTest)
removed call to com/github/dakusui/pcond/internals/InternalChecks::checkArgument → KILLED

35

1.1
Location : validateArgumentType
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/experimentals/currying/Checks::validateArgumentType → KILLED

39

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

40

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.given_nullToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.dakusui.pcond.ut.CurryingTest)
negated conditional → KILLED

41

1.1
Location : isValidValueForType
Killed by : none
replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → SURVIVED

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

42

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.givenStringToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.dakusui.pcond.ut.CurryingTest)
negated conditional → KILLED

44

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.given_IntegerToCurriedFuncWithIntParam$whenIsValidArg$thenTrue(com.github.dakusui.pcond.ut.CurryingTest)
negated conditional → KILLED

45

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.given_IntegerToCurriedFuncWithIntParam$whenIsValidArg$thenTrue(com.github.dakusui.pcond.ut.CurryingTest)
replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

46

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.given_shortToCurriedFuncWithIntParam$whenIsValidArg$thenTrue(com.github.dakusui.pcond.ut.CurryingTest)
replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

2.2
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.given_longToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.dakusui.pcond.ut.CurryingTest)
replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

48

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingTest.givenStringToCurriedFuncWithIntParam$whenIsValidArg$thenFalse(com.github.dakusui.pcond.ut.CurryingTest)
replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

50

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

51

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest.testDummyFunction(com.github.dakusui.pcond.ut.InternalUtilsTest$DummyFormTest)
replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

52

1.1
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$SizeTest.whenApplied$thenLooksGood(com.github.dakusui.pcond.ut.FunctionsTest$SizeTest)
replaced boolean return with false for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

2.2
Location : isValidValueForType
Killed by : com.github.dakusui.pcond.ut.CurryingUtilsTest.returnedValueIsInvalid(com.github.dakusui.pcond.ut.CurryingUtilsTest)
replaced boolean return with true for com/github/dakusui/pcond/experimentals/currying/Checks::isValidValueForType → KILLED

58

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

59

1.1
Location : ensureReturnedValueType
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/experimentals/currying/Checks::ensureReturnedValueType → KILLED

62

1.1
Location : ensureReturnedValueType
Killed by : com.github.dakusui.pcond.ut.CurryingUtilsTest.returnedValueIsInvalid(com.github.dakusui.pcond.ut.CurryingUtilsTest)
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3