| 1 | package com.github.dakusui.pcond.validator; | |
| 2 | ||
| 3 | import java.util.LinkedList; | |
| 4 | import java.util.List; | |
| 5 | import java.util.Objects; | |
| 6 | import java.util.stream.IntStream; | |
| 7 | ||
| 8 | import static com.github.dakusui.pcond.internals.InternalUtils.newLine; | |
| 9 | import static com.github.dakusui.pcond.validator.ReportComposer.Utils.composeReport; | |
| 10 | import static java.lang.String.format; | |
| 11 | import static java.util.Objects.requireNonNull; | |
| 12 | import static java.util.stream.Collectors.joining; | |
| 13 | ||
| 14 | public class Explanation { | |
| 15 | private final String message; | |
| 16 | private final ReportComposer.Report expected; | |
| 17 | private final ReportComposer.Report actual; | |
| 18 | ||
| 19 | public Explanation(String message) { | |
| 20 | this(message, composeReport("", null), composeReport("", null)); | |
| 21 | } | |
| 22 | ||
| 23 | public Explanation(String message, ReportComposer.Report expected, ReportComposer.Report actual) { | |
| 24 | this.message = message; | |
| 25 | this.expected = requireNonNull(expected); | |
| 26 | this.actual = requireNonNull(actual); | |
| 27 | } | |
| 28 | ||
| 29 | public String message() { | |
| 30 |
1
1. message : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::message → KILLED |
return this.message; |
| 31 | } | |
| 32 | ||
| 33 | public ReportComposer.Report expected() { | |
| 34 |
1
1. expected : replaced return value with null for com/github/dakusui/pcond/validator/Explanation::expected → KILLED |
return this.expected; |
| 35 | } | |
| 36 | ||
| 37 | public ReportComposer.Report actual() { | |
| 38 |
1
1. actual : replaced return value with null for com/github/dakusui/pcond/validator/Explanation::actual → KILLED |
return this.actual; |
| 39 | } | |
| 40 | ||
| 41 | public String toString() { | |
| 42 |
2
1. toString : negated conditional → KILLED 2. toString : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::toString → KILLED |
return actual != null ? |
| 43 | format("%s%n%s", message, composeDiff(expected, actual)) : | |
| 44 | message; | |
| 45 | } | |
| 46 | ||
| 47 | private static String composeDiff(ReportComposer.Report expected, ReportComposer.Report actual) { | |
| 48 | String[] e = splitAndTrim(expected.summary()); | |
| 49 | String[] a = splitAndTrim(actual.summary()); | |
| 50 | List<String> b = new LinkedList<>(); | |
| 51 |
3
1. composeDiff : changed conditional boundary → SURVIVED 2. composeDiff : negated conditional → TIMED_OUT 3. composeDiff : Changed increment from 1 to -1 → KILLED |
for (int i = 0; i < Math.max(a.length, e.length); i++) { |
| 52 |
3
1. composeDiff : changed conditional boundary → SURVIVED 2. composeDiff : negated conditional → KILLED 3. composeDiff : negated conditional → KILLED |
if (i < Math.min(e.length, a.length) && Objects.equals(e[i], a[i])) { |
| 53 | b.add(format(" %s", a[i])); | |
| 54 | } else { | |
| 55 |
2
1. composeDiff : changed conditional boundary → SURVIVED 2. composeDiff : negated conditional → KILLED |
b.add(format("Mismatch<:%s", i < e.length ? e[i] : "")); |
| 56 |
2
1. composeDiff : changed conditional boundary → SURVIVED 2. composeDiff : negated conditional → KILLED |
b.add(format("Mismatch>:%s", i < a.length ? a[i] : "")); |
| 57 | } | |
| 58 | } | |
| 59 | b.add(newLine()); | |
| 60 | assert expected.details().size() == actual.details().size(); | |
| 61 |
1
1. composeDiff : negated conditional → KILLED |
return !expected.details().isEmpty() ? |
| 62 | b.stream().collect(joining(newLine())) | |
| 63 | + IntStream.range(0, expected.details().size()) | |
| 64 |
1
1. lambda$composeDiff$0 : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::lambda$composeDiff$0 → KILLED |
.mapToObj(i -> formatDetailItemPair(i, expected.details().get(i), actual.details().get(i))) |
| 65 | .collect(joining(newLine())) : | |
| 66 | ""; | |
| 67 | } | |
| 68 | ||
| 69 | private static String formatDetailItemPair(int i, String detailItemForExpectation, String detailItemForActual) { | |
| 70 |
1
1. formatDetailItemPair : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::formatDetailItemPair → KILLED |
return format(".Detail of failure [%s] (expectation)%n", i) |
| 71 | + format("----%n") | |
| 72 | + detailItemForExpectation | |
| 73 | + newLine() | |
| 74 | + format("----%n") | |
| 75 | + newLine() | |
| 76 | + format(".Detail of failure [%s] (actual value)%n", i) | |
| 77 | + format("----%n") | |
| 78 | + detailItemForActual | |
| 79 | + newLine() | |
| 80 | + "----"; | |
| 81 | } | |
| 82 | ||
| 83 | public static String reportToString(ReportComposer.Report report) { | |
| 84 | String ret = report.summary(); | |
| 85 | ret += newLine(); | |
| 86 | ret += newLine(); | |
| 87 | ret += IntStream.range(0, report.details().size()) | |
| 88 |
1
1. lambda$reportToString$1 : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::lambda$reportToString$1 → KILLED |
.mapToObj(i -> formatDetailItem(i, report.details().get(i))) |
| 89 | .collect(joining(newLine())); | |
| 90 |
1
1. reportToString : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::reportToString → KILLED |
return ret; |
| 91 | } | |
| 92 | ||
| 93 | private static String formatDetailItem(int i, String detailItem) { | |
| 94 |
1
1. formatDetailItem : replaced return value with "" for com/github/dakusui/pcond/validator/Explanation::formatDetailItem → KILLED |
return format(".Detail of failure [%s]%n", i) |
| 95 | + format("----%n") | |
| 96 | + detailItem | |
| 97 | + newLine() | |
| 98 | + format("----%n"); | |
| 99 | } | |
| 100 | ||
| 101 | public static Explanation fromMessage(String msg) { | |
| 102 |
1
1. fromMessage : replaced return value with null for com/github/dakusui/pcond/validator/Explanation::fromMessage → KILLED |
return new Explanation(msg); |
| 103 | } | |
| 104 | ||
| 105 | private static String[] splitAndTrim(String expected) { | |
| 106 | String[] in = expected.split(newLine()); | |
| 107 | List<String> out = new LinkedList<>(); | |
| 108 | boolean nonEmptyFound = false; | |
| 109 |
4
1. splitAndTrim : changed conditional boundary → KILLED 2. splitAndTrim : Changed increment from -1 to 1 → KILLED 3. splitAndTrim : Replaced integer subtraction with addition → KILLED 4. splitAndTrim : negated conditional → KILLED |
for (int i = in.length - 1; i >= 0; i--) { |
| 110 |
1
1. splitAndTrim : negated conditional → KILLED |
if (!"".equals(in[i])) |
| 111 | nonEmptyFound = true; | |
| 112 |
1
1. splitAndTrim : negated conditional → KILLED |
if (nonEmptyFound) |
| 113 |
1
1. splitAndTrim : removed call to java/util/List::add → KILLED |
out.add(0, in[i]); |
| 114 | } | |
| 115 |
1
1. splitAndTrim : replaced return value with null for com/github/dakusui/pcond/validator/Explanation::splitAndTrim → KILLED |
return out.toArray(new String[0]); |
| 116 | } | |
| 117 | } | |
Mutations | ||
| 30 |
1.1 |
|
| 34 |
1.1 |
|
| 38 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 51 |
1.1 2.2 3.3 |
|
| 52 |
1.1 2.2 3.3 |
|
| 55 |
1.1 2.2 |
|
| 56 |
1.1 2.2 |
|
| 61 |
1.1 |
|
| 64 |
1.1 |
|
| 70 |
1.1 |
|
| 88 |
1.1 |
|
| 90 |
1.1 |
|
| 94 |
1.1 |
|
| 102 |
1.1 |
|
| 109 |
1.1 2.2 3.3 4.4 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |
|
| 113 |
1.1 |
|
| 115 |
1.1 |