| 1 | package com.github.valid8j.pcond.core; | |
| 2 | ||
| 3 | import com.github.valid8j.pcond.experimentals.currying.context.CurriedContext; | |
| 4 | ||
| 5 | import java.util.List; | |
| 6 | import java.util.Optional; | |
| 7 | import java.util.function.Function; | |
| 8 | import java.util.function.Predicate; | |
| 9 | import java.util.stream.Stream; | |
| 10 | ||
| 11 | /** | |
| 12 | * // @formatter:off | |
| 13 | * An interface that models "forms". | |
| 14 | * A form is a general idea that covers predicates, functions, and "special-forms". | |
| 15 | * | |
| 16 | * A simple form (such as one returned by {@link Predicate#isEqual(Object)}) is | |
| 17 | * modeled as and held by {@link LeafPred}. | |
| 18 | * The framework just delegates the evaluation to the object. | |
| 19 | * | |
| 20 | * However, for a form which has an internal structure, such as one returned by | |
| 21 | * {@link Predicate#and(Predicate)}, this approach doesn't work. | |
| 22 | * Because, in order to make the evaluation process visible and readable for human, | |
| 23 | * we need intermediate evaluation results. | |
| 24 | * | |
| 25 | * That is, when we evaluate a form `v != null && v.startsWith("hello")`, we want | |
| 26 | * information about which predicate was violated. | |
| 27 | * Just showing the actual value of `v` is not sufficient, because the `v` and the | |
| 28 | * predicates in the evaluation might have internal structures or logics that make | |
| 29 | * it difficult/impossible to infer which predicate is violated. | |
| 30 | * // @formatter:on | |
| 31 | * | |
| 32 | * @param <T> The type of the value evaluated by this object. | |
| 33 | */ | |
| 34 | public interface Evaluable<T> { | |
| 35 | /** | |
| 36 | * Performs an evaluation of the `evaluationContext` with a given `evaluator`. | |
| 37 | * | |
| 38 | * @param evaluableIo An execution occurrence of an evaluable. | |
| 39 | * @param evaluationContext An evaluation context. | |
| 40 | * @param evaluator An evaluator with which the `evaluationContext` is evaluated. | |
| 41 | */ | |
| 42 | <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator); | |
| 43 | ||
| 44 | /** | |
| 45 | * Returns if this object can be folded in a test failure report. | |
| 46 | * | |
| 47 | * @return true - squashable / false - otherwise. | |
| 48 | */ | |
| 49 | default boolean isSquashable() { | |
| 50 |
1
1. isSquashable : replaced boolean return with true for com/github/valid8j/pcond/core/Evaluable::isSquashable → NO_COVERAGE |
return false; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * Returns if this object can be skipped in a test failure report. | |
| 55 | * | |
| 56 | * @return true - can be skipped / false - otherwise. | |
| 57 | */ | |
| 58 | default boolean isTrivial() { | |
| 59 |
1
1. isTrivial : replaced boolean return with true for com/github/valid8j/pcond/core/Evaluable::isTrivial → NO_COVERAGE |
return false; |
| 60 | } | |
| 61 | ||
| 62 | ||
| 63 | /** | |
| 64 | * Marks this object squashable so that an entry in a failure report can be folded where possible. | |
| 65 | * This method is overridden by an implementation that allows the behavior described above. | |
| 66 | * | |
| 67 | * @return A cloned object marked squashable. | |
| 68 | */ | |
| 69 | default Evaluable<T> markSquashable() { | |
| 70 | throw new UnsupportedOperationException(); | |
| 71 | } | |
| 72 | ||
| 73 | ||
| 74 | /** | |
| 75 | * Marks this object trivial so that an entry in a failure report can be skipped. | |
| 76 | * This method is overridden by an implementation that allows the behavior described above. | |
| 77 | * | |
| 78 | * @return A cloned object marked ignored. | |
| 79 | */ | |
| 80 | default Evaluable<T> markTrivial() { | |
| 81 | throw new UnsupportedOperationException(); | |
| 82 | } | |
| 83 | ||
| 84 | ||
| 85 | /** | |
| 86 | * A base interface to model all the predicates in the model of the evaluation | |
| 87 | * framework. | |
| 88 | * | |
| 89 | * @param <T> The type of the value to be tested. | |
| 90 | */ | |
| 91 | interface Pred<T> extends Evaluable<T> { | |
| 92 | } | |
| 93 | ||
| 94 | /** | |
| 95 | * A base interface for conjunction (and) and disjunction (or) of predicates. | |
| 96 | * | |
| 97 | * @param <T> The type of the value to be evaluated. | |
| 98 | */ | |
| 99 | interface Composite<T> extends Pred<T> { | |
| 100 | /** | |
| 101 | * Returns the predicates with which the target value is evaluated. | |
| 102 | * | |
| 103 | * @return The list of the child predicates. | |
| 104 | */ | |
| 105 | List<Evaluable<T>> children(); | |
| 106 | ||
| 107 | /** | |
| 108 | * // @formatter:on | |
| 109 | * | |
| 110 | * Returns `true` if the "shortcut" evaluation is enabled. | |
| 111 | * | |
| 112 | * Suppose you have a following predicate. | |
| 113 | * | |
| 114 | * ---- | |
| 115 | * a && b && c | |
| 116 | * ---- | |
| 117 | * | |
| 118 | * If the `a` results in `false`, the `b` and `c` doesn't need to be evaluated. | |
| 119 | * The optimization, where the evaluations for the `b` and `c` are skipped, | |
| 120 | * is called "shortcut". | |
| 121 | * | |
| 122 | * However, in the context of testing, sometimes we want to know the evaluation | |
| 123 | * results for the `b` and `c`. | |
| 124 | * Otherwise, we cannot avoid getting into a fail->fix->run->fail... loop, | |
| 125 | * sometimes. | |
| 126 | * | |
| 127 | * // @formatter:off | |
| 128 | * @return `true` if the "shortcut" evaluation is enabled. | |
| 129 | */ | |
| 130 | boolean shortcut(); | |
| 131 | ||
| 132 | @Override | |
| 133 | default boolean isSquashable() { | |
| 134 |
3
1. isSquashable : changed conditional boundary → NO_COVERAGE 2. isSquashable : negated conditional → NO_COVERAGE 3. isSquashable : replaced boolean return with true for com/github/valid8j/pcond/core/Evaluable$Composite::isSquashable → NO_COVERAGE |
return children().size() <= 1; |
| 135 | } | |
| 136 | } | |
| 137 | ||
| 138 | /** | |
| 139 | * An interface to model a conjunction (`and`, `&&`) predicate. | |
| 140 | * | |
| 141 | * @param <T> The type of the value to be evaluated. | |
| 142 | */ | |
| 143 | interface Conjunction<T> extends Composite<T> { | |
| 144 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 145 | @Override | |
| 146 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 147 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateConjunction → KILLED |
evaluator.evaluateConjunction((EvaluableIo<T, Conjunction<T>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * An interface to model a disjunction (`or`, `||`) predicate. | |
| 153 | * | |
| 154 | * @param <T> The type of the value to be evaluated. | |
| 155 | */ | |
| 156 | interface Disjunction<T> extends Composite<T> { | |
| 157 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 158 | @Override | |
| 159 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 160 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateDisjunction → KILLED |
evaluator.evaluateDisjunction((EvaluableIo<T, Disjunction<T>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 161 | } | |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 165 | * An interface to model a negation (`not`, `negate`, `!`) of a predicate. | |
| 166 | * | |
| 167 | * @param <T> The type of the value to be evaluated. | |
| 168 | */ | |
| 169 | interface Negation<T> extends Pred<T> { | |
| 170 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 171 | @Override | |
| 172 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 173 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateNegation → KILLED |
evaluator.evaluateNegation((EvaluableIo<T, Negation<T>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * The predicate the negation is applied. | |
| 178 | * | |
| 179 | * @return A target predicate. | |
| 180 | */ | |
| 181 | Evaluable<T> target(); | |
| 182 | ||
| 183 | @Override | |
| 184 | default boolean isSquashable() { | |
| 185 |
1
1. isSquashable : replaced boolean return with false for com/github/valid8j/pcond/core/Evaluable$Negation::isSquashable → NO_COVERAGE |
return true; |
| 186 | } | |
| 187 | } | |
| 188 | ||
| 189 | /** | |
| 190 | * An interface to model a simple predicate in the evaluation framework. | |
| 191 | * | |
| 192 | * @param <T> The type of the value to be evaluated. | |
| 193 | */ | |
| 194 | interface LeafPred<T> extends Pred<T> { | |
| 195 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 196 | @Override | |
| 197 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 198 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateLeaf → KILLED |
evaluator.evaluateLeaf((EvaluableIo<T, LeafPred<T>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 199 | } | |
| 200 | ||
| 201 | /** | |
| 202 | * Returns an actual predicate modeled by this interface. | |
| 203 | * | |
| 204 | * @return The predicate modeled by this interface. | |
| 205 | */ | |
| 206 | Predicate<? super T> predicate(); | |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * An interface to model a predicate for {@link CurriedContext}. | |
| 211 | * | |
| 212 | * @see CurriedContext | |
| 213 | */ | |
| 214 | interface CurriedContextPred extends Pred<CurriedContext> { | |
| 215 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 216 | @Override | |
| 217 | default <O> void accept(EvaluableIo<CurriedContext, Evaluable<CurriedContext>, O> evaluableIo, EvaluationContext<CurriedContext> evaluationContext, Evaluator evaluator) { | |
| 218 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateCurriedContextPredicate → KILLED |
evaluator.evaluateCurriedContextPredicate((EvaluableIo<CurriedContext, CurriedContextPred, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 219 | } | |
| 220 | ||
| 221 | <T> Evaluable<T> enclosed(); | |
| 222 | ||
| 223 | int argIndex(); | |
| 224 | } | |
| 225 | ||
| 226 | /** | |
| 227 | * An interface to model a predicate for {@link Stream}. | |
| 228 | * | |
| 229 | * @param <E> The type of elements in the stream to be evaluated. | |
| 230 | */ | |
| 231 | interface StreamPred<E> extends Pred<Stream<E>> { | |
| 232 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 233 | @Override | |
| 234 | default <O> void accept(EvaluableIo<Stream<E>, Evaluable<Stream<E>>, O> evaluableIo, EvaluationContext<Stream<E>> evaluationContext, Evaluator evaluator) { | |
| 235 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateStreamPredicate → KILLED |
evaluator.evaluateStreamPredicate((EvaluableIo<Stream<E>, StreamPred<E>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 236 | } | |
| 237 | ||
| 238 | /** | |
| 239 | * Returns a default value returned as the entire result of this predicate. | |
| 240 | * The `value` is used when a "cut" happens. | |
| 241 | * | |
| 242 | * @return a default value to fallback of this object. | |
| 243 | */ | |
| 244 | boolean defaultValue(); | |
| 245 | ||
| 246 | /** | |
| 247 | * Returns an evaluable object which makes "cut" happen. | |
| 248 | * If the result of the evaluation of the returned object becomes equal to the | |
| 249 | * returned value of the {@link StreamPred#valueToCut()}, a "cut" will actually happen. | |
| 250 | * | |
| 251 | * @return An evaluable which triggers a "cut". | |
| 252 | */ | |
| 253 | Evaluable<E> cut(); | |
| 254 | ||
| 255 | /** | |
| 256 | * // @formatter:off | |
| 257 | * Returns a value to make a "cut" happen. | |
| 258 | * | |
| 259 | * A "cut" is a situation, where an evaluation process for the elements in the | |
| 260 | * stream is ended without reaching the last one. | |
| 261 | * This is necessary to model a functionalities of `Stream`, such as | |
| 262 | * `allMatch`, `noneMatch`, and `anyMatch`. | |
| 263 | * // @formatter:on | |
| 264 | * | |
| 265 | * @return value ( `true` / `false` ) to make a "cut" happen. | |
| 266 | */ | |
| 267 | boolean valueToCut(); | |
| 268 | ||
| 269 | /** | |
| 270 | * // @formatter:off | |
| 271 | * In order to generate an informative report, the framework needs information | |
| 272 | * about the expected value for each predicate. | |
| 273 | * | |
| 274 | * The "expected" value of a predicate can be different inside the tree of the `Evaluables`, | |
| 275 | * when a negation is used. | |
| 276 | * | |
| 277 | * If this `Evaluable` node requests to flip the expectation value under the node, | |
| 278 | * this method should return `true`. | |
| 279 | * // @formatter:on | |
| 280 | * | |
| 281 | * @return `true`, if the expectation flip is requested. | |
| 282 | */ | |
| 283 | default boolean requestExpectationFlip() { | |
| 284 |
1
1. requestExpectationFlip : replaced boolean return with true for com/github/valid8j/pcond/core/Evaluable$StreamPred::requestExpectationFlip → KILLED |
return false; |
| 285 | } | |
| 286 | } | |
| 287 | ||
| 288 | /** | |
| 289 | * An interface to model a "transforming predicate", which models the "transform and check" style of value validation. | |
| 290 | * The idea of the style is to first transform a value into a type, which is easy to read for human and to check for machine, such as list, integer, string, etc., in order to validate a value. | |
| 291 | * | |
| 292 | * @param <T> The type of the value to be evaluated. | |
| 293 | * @param <R> The type to which the value (`T`) is transformed and then tested. | |
| 294 | */ | |
| 295 | interface Transformation<T, R> extends Pred<T> { | |
| 296 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 297 | @Override | |
| 298 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 299 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateTransformation → KILLED |
evaluator.evaluateTransformation((EvaluableIo<T, Transformation<T, R>, Boolean>) (EvaluableIo) evaluableIo, evaluationContext); |
| 300 | } | |
| 301 | ||
| 302 | /** | |
| 303 | * Returns a transformer of this object. | |
| 304 | * | |
| 305 | * @return A transformer function. | |
| 306 | */ | |
| 307 | Evaluable<T> mapper(); | |
| 308 | ||
| 309 | Evaluable<R> checker(); | |
| 310 | ||
| 311 | /** | |
| 312 | * Returns a name of a transformer, if any. | |
| 313 | * | |
| 314 | * @return An optional to store a name of the transformer. | |
| 315 | */ | |
| 316 | Optional<String> mapperName(); | |
| 317 | ||
| 318 | /** | |
| 319 | * Returns a name of a checker, if any. | |
| 320 | * | |
| 321 | * @return An optional to store a name of the checker. | |
| 322 | */ | |
| 323 | Optional<String> checkerName(); | |
| 324 | } | |
| 325 | ||
| 326 | /** | |
| 327 | * An interface to model a function ({@link Function}) in the evaluation framework | |
| 328 | * of the `pcond`. | |
| 329 | * | |
| 330 | * @param <T> The type of the value to be evaluated. | |
| 331 | */ | |
| 332 | interface Func<T> extends Evaluable<T> { | |
| 333 | @SuppressWarnings({"unchecked", "rawtypes"}) | |
| 334 | @Override | |
| 335 | default <O> void accept(EvaluableIo<T, Evaluable<T>, O> evaluableIo, EvaluationContext<T> evaluationContext, Evaluator evaluator) { | |
| 336 |
1
1. accept : removed call to com/github/valid8j/pcond/core/Evaluator::evaluateFunction → KILLED |
evaluator.evaluateFunction((EvaluableIo<T, Func<T>, O>) (EvaluableIo) evaluableIo, evaluationContext); |
| 337 | } | |
| 338 | ||
| 339 | Function<? super T, Object> head(); | |
| 340 | ||
| 341 | Optional<Evaluable<Object>> tail(); | |
| 342 | } | |
| 343 | } | |
Mutations | ||
| 50 |
1.1 |
|
| 59 |
1.1 |
|
| 134 |
1.1 2.2 3.3 |
|
| 147 |
1.1 |
|
| 160 |
1.1 |
|
| 173 |
1.1 |
|
| 185 |
1.1 |
|
| 198 |
1.1 |
|
| 218 |
1.1 |
|
| 235 |
1.1 |
|
| 284 |
1.1 |
|
| 299 |
1.1 |
|
| 336 |
1.1 |