InternalChecks.java

1
package com.github.dakusui.pcond.internals;
2
3
import com.github.dakusui.pcond.core.refl.ReflUtils;
4
5
import java.lang.reflect.Method;
6
import java.lang.reflect.Modifier;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Set;
10
import java.util.function.Function;
11
import java.util.function.Predicate;
12
import java.util.function.Supplier;
13
14
import static java.lang.String.format;
15
import static java.util.Collections.emptySet;
16
import static java.util.Collections.unmodifiableList;
17
import static java.util.stream.Collectors.toList;
18
19
public enum InternalChecks {
20
  ;
21
22
  private static final Set<Class<?>> PRIMITIVE_WRAPPERS = new HashSet<Class<?>>() {{
23
    add(Integer.class);
24
    add(Long.class);
25
    add(Boolean.class);
26
    add(Byte.class);
27
    add(Character.class);
28
    add(Float.class);
29
    add(Double.class);
30
    add(Short.class);
31
    add(Void.class);
32
  }};
33
34
  public static void checkArgument(boolean b, Supplier<String> messageFormatter) {
35 1 1. checkArgument : negated conditional → KILLED
    if (!b)
36
      throw new IllegalArgumentException(messageFormatter.get());
37
  }
38
39
  public static <V> V requireArgument(V arg, Predicate<? super V> predicate, Supplier<String> messageFormatter) {
40 1 1. requireArgument : negated conditional → KILLED
    if (!predicate.test(arg))
41
      throw new IllegalArgumentException(messageFormatter.get());
42 1 1. requireArgument : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireArgument → KILLED
    return arg;
43
  }
44
45
  public static <V> V ensureValue(V value, Predicate<? super V> predicate, Function<V, String> messageFormatter) {
46 1 1. ensureValue : negated conditional → KILLED
    if (!predicate.test(value))
47
      throw new IllegalStateException(messageFormatter.apply(value));
48 1 1. ensureValue : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::ensureValue → KILLED
    return value;
49
  }
50
51
  public static <V> V requireState(V arg, Predicate<? super V> predicate, Function<V, String> messageFormatter) {
52 1 1. requireState : negated conditional → KILLED
    if (!predicate.test(arg))
53
      throw new IllegalStateException(messageFormatter.apply(arg));
54 1 1. requireState : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireState → KILLED
    return arg;
55
  }
56
57
  public static Method requireStaticMethod(Method method) {
58 1 1. requireStaticMethod : negated conditional → KILLED
    if (!Modifier.isStatic(method.getModifiers()))
59
      throw new IllegalArgumentException(String.format("The specified method '%s' is not static", method));
60 1 1. requireStaticMethod : replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireStaticMethod → SURVIVED
    return method;
61
  }
62
63
  public static List<Object> requireArgumentListSize(List<Object> args, int requiredSize) {
64 1 1. requireArgumentListSize : negated conditional → KILLED
    if (requiredSize != args.size())
65
      throw new IllegalArgumentException(String.format("Wrong number of arguments are given: required: %s, actual: %s", requiredSize, args.size()));
66 1 1. requireArgumentListSize : replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::requireArgumentListSize → KILLED
    return args;
67
  }
68
69
  public static boolean isWiderThanOrEqualTo(Class<?> classA, Class<?> classB) {
70 1 1. lambda$isWiderThanOrEqualTo$0 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$0 → SURVIVED
    requireArgument(classA, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classA));
71 1 1. lambda$isWiderThanOrEqualTo$1 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$1 → SURVIVED
    requireArgument(classB, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classB));
72 3 1. isWiderThanOrEqualTo : negated conditional → KILLED
2. isWiderThanOrEqualTo : negated conditional → KILLED
3. isWiderThanOrEqualTo : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThanOrEqualTo → KILLED
    return classA.equals(classB) || isWiderThan(classA, classB);
73
  }
74
75
  public static boolean isPrimitiveWrapperClass(Class<?> aClass) {
76 2 1. isPrimitiveWrapperClass : replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED
2. isPrimitiveWrapperClass : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED
    return PRIMITIVE_WRAPPERS.contains(aClass);
77
  }
78
79
  public static boolean isPrimitiveWrapperClassOrPrimitive(Class<?> aClass) {
80 3 1. isPrimitiveWrapperClassOrPrimitive : negated conditional → KILLED
2. isPrimitiveWrapperClassOrPrimitive : negated conditional → KILLED
3. isPrimitiveWrapperClassOrPrimitive : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClassOrPrimitive → KILLED
    return aClass.isPrimitive() || isPrimitiveWrapperClass(aClass);
81
  }
82
83
  /**
84
   * @param classA A non-primitive type class.
85
   * @param classB Another non-primitive type class.
86
   * @return {@code true} iff {@code classA} is a "wider" wrapper class than {@code classB}.
87
   */
88
  public static boolean isWiderThan(Class<?> classA, Class<?> classB) {
89 1 1. lambda$isWiderThan$2 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$2 → SURVIVED
    requireArgument(classA, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classA));
90 1 1. lambda$isWiderThan$3 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$3 → SURVIVED
    requireArgument(classB, InternalChecks::isPrimitiveWrapperClass, () -> format("'%s' is not a primitive wrapper class", classB));
91
    Set<Class<?>> widerBoxedClassesForClassA = widerTypesThan(classB);
92 2 1. isWiderThan : replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED
2. isWiderThan : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED
    return widerBoxedClassesForClassA.contains(classA);
93
  }
94
95
  private static Set<Class<?>> widerTypesThan(Class<?> classB) {
96 1 1. widerTypesThan : replaced return value with Collections.emptySet for com/github/dakusui/pcond/internals/InternalChecks::widerTypesThan → KILLED
    return ReflUtils.WIDER_TYPES.getOrDefault(classB, emptySet());
97
  }
98
99
  public static List<Integer> validateParamOrderList(List<Integer> order, int numParameters) {
100
    final List<Integer> paramOrder = unmodifiableList(order.stream().distinct().collect(toList()));
101 3 1. lambda$validateParamOrderList$4 : negated conditional → KILLED
2. lambda$validateParamOrderList$4 : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$4 → KILLED
3. lambda$validateParamOrderList$5 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$5 → KILLED
    requireArgument(order, o -> o.size() == paramOrder.size(), () -> "Duplicated elements are found in the 'order' argument:" + order.toString() + " " + paramOrder);
102 3 1. lambda$validateParamOrderList$6 : negated conditional → KILLED
2. lambda$validateParamOrderList$6 : replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$6 → KILLED
3. lambda$validateParamOrderList$7 : replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$7 → KILLED
    requireArgument(order, o -> o.size() == numParameters, () -> "Inconsistent number of parameters are supplied by 'order'. Expected:" + numParameters + ", Actual: " + order.size());
103 1 1. validateParamOrderList : replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::validateParamOrderList → KILLED
    return paramOrder;
104
  }
105
}

Mutations

35

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

40

1.1
Location : requireArgument
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenEqual$whenIsWiderThanOrEqualToThenTrue(com.github.dakusui.pcond.ut.currying.ChecksTest)
negated conditional → KILLED

42

1.1
Location : requireArgument
Killed by : com.github.dakusui.pcond.ut.InternalChecksTest.testRequireArgument(com.github.dakusui.pcond.ut.InternalChecksTest)
replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireArgument → KILLED

46

1.1
Location : ensureValue
Killed by : com.github.dakusui.pcond.CallTest.narrowerMethodIsChosen(com.github.dakusui.pcond.CallTest)
negated conditional → KILLED

48

1.1
Location : ensureValue
Killed by : com.github.dakusui.pcond.CallTest.narrowerMethodIsChosen(com.github.dakusui.pcond.CallTest)
replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::ensureValue → KILLED

52

1.1
Location : requireState
Killed by : com.github.dakusui.pcond.ut.InternalChecksTest.testRequireState$fails(com.github.dakusui.pcond.ut.InternalChecksTest)
negated conditional → KILLED

54

1.1
Location : requireState
Killed by : com.github.dakusui.pcond.ut.InternalChecksTest.testRequireState(com.github.dakusui.pcond.ut.InternalChecksTest)
replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireState → KILLED

58

1.1
Location : requireStaticMethod
Killed by : com.github.dakusui.pcond.ut.CurryingTest.nonStaticMethod(com.github.dakusui.pcond.ut.CurryingTest)
negated conditional → KILLED

60

1.1
Location : requireStaticMethod
Killed by : none
replaced return value with null for com/github/dakusui/pcond/internals/InternalChecks::requireStaticMethod → SURVIVED

64

1.1
Location : requireArgumentListSize
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.runMultiParameterFunction$thenExpectedValueReturned(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
negated conditional → KILLED

66

1.1
Location : requireArgumentListSize
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.runMultiParameterFunction$thenExpectedValueReturned(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::requireArgumentListSize → KILLED

70

1.1
Location : lambda$isWiderThanOrEqualTo$0
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$0 → SURVIVED

71

1.1
Location : lambda$isWiderThanOrEqualTo$1
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThanOrEqualTo$1 → SURVIVED

72

1.1
Location : isWiderThanOrEqualTo
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenEqual$whenIsWiderThanOrEqualToThenTrue(com.github.dakusui.pcond.ut.currying.ChecksTest)
negated conditional → KILLED

2.2
Location : isWiderThanOrEqualTo
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenNarrower$whenIsWiderThanOrEqualToThenTrue(com.github.dakusui.pcond.ut.currying.ChecksTest)
negated conditional → KILLED

3.3
Location : isWiderThanOrEqualTo
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenNarrower$whenIsWiderThanOrEqualToThenTrue(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThanOrEqualTo → KILLED

76

1.1
Location : isPrimitiveWrapperClass
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenEqual$whenIsWiderThanOrEqualToThenTrue(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED

2.2
Location : isPrimitiveWrapperClass
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenNonWrapperForFirstArgument$whenIsWiderThanOrEqualTo$thenIllegalArgument(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isPrimitiveWrapperClass → KILLED

80

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

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

3.3
Location : isPrimitiveWrapperClassOrPrimitive
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/internals/InternalChecks::isPrimitiveWrapperClassOrPrimitive → KILLED

89

1.1
Location : lambda$isWiderThan$2
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$2 → SURVIVED

90

1.1
Location : lambda$isWiderThan$3
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$isWiderThan$3 → SURVIVED

92

1.1
Location : isWiderThan
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenWider$whenIsWiderThan(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced boolean return with false for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED

2.2
Location : isWiderThan
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenNarrower$whenIsWiderThanTest2(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::isWiderThan → KILLED

96

1.1
Location : widerTypesThan
Killed by : com.github.dakusui.pcond.ut.currying.ChecksTest.givenWider$whenIsWiderThan(com.github.dakusui.pcond.ut.currying.ChecksTest)
replaced return value with Collections.emptySet for com/github/dakusui/pcond/internals/InternalChecks::widerTypesThan → KILLED

101

1.1
Location : lambda$validateParamOrderList$4
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_duplicatedOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
negated conditional → KILLED

2.2
Location : lambda$validateParamOrderList$4
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_duplicatedOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$4 → KILLED

3.3
Location : lambda$validateParamOrderList$5
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_duplicatedOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$5 → KILLED

102

1.1
Location : lambda$validateParamOrderList$6
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_insufficientNumberOfParamOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
negated conditional → KILLED

2.2
Location : lambda$validateParamOrderList$6
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_insufficientNumberOfParamOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced boolean return with true for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$6 → KILLED

3.3
Location : lambda$validateParamOrderList$7
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.lookUpWithInvalidArgument_insufficientNumberOfParamOrder(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced return value with "" for com/github/dakusui/pcond/internals/InternalChecks::lambda$validateParamOrderList$7 → KILLED

103

1.1
Location : validateParamOrderList
Killed by : com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest.testEqualsWithDifferentObjects(com.github.dakusui.pcond.ut.FunctionsTest$MultiFunctionTest)
replaced return value with Collections.emptyList for com/github/dakusui/pcond/internals/InternalChecks::validateParamOrderList → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3