Skip to content
Permalink
Browse files

Step 5: Expected Coverage

  • Loading branch information...
tlinkowski committed Jan 31, 2019
1 parent 0a8c6fd commit 6240a59eb541f1476d8d5216635f7af3e8109fc2
Showing with 38 additions and 0 deletions.
  1. +4 −0 Issue.java
  2. +30 −0 IssueCoverage.java
  3. +4 −0 Usage.java
@@ -4,4 +4,8 @@
int endOffset(); // e.g. 9 (end of "migth")

IssueType type(); // e.g. SPELLING

default int length() {
return endOffset() - startOffset();
} // e.g. 5
}
@@ -0,0 +1,30 @@
import java.util.stream.Collector;

class IssueCoverage {
static Collector<IssueWiseText, ?, Double> collector() {
return Collector.of(
Accumulator::new, Accumulator::accumulate, Accumulator::combine, Accumulator::finish,
Collector.Characteristics.UNORDERED
);
}

private static class Accumulator {
int totalIssueLength = 0;
int totalTextLength = 0;

void accumulate(IssueWiseText issueWiseText) {
totalIssueLength += issueWiseText.issues().stream().mapToInt(Issue::length).sum();
totalTextLength += issueWiseText.text().length();
}

Accumulator combine(Accumulator other) {
totalIssueLength += other.totalIssueLength;
totalTextLength += other.totalTextLength;
return this;
}

double finish() {
return (double) totalIssueLength / totalTextLength;
}
}
}
@@ -1,6 +1,10 @@
import java.util.stream.Stream;

class Usage {
static double issueCoverage(Stream<? extends IssueWiseText> textStream) {
return textStream.collect(IssueCoverage.collector());
}

static Stream<IssueWiseText> testCaseStream() {
return Stream.of();
}

0 comments on commit 6240a59

Please sign in to comment.
You can’t perform that action at this time.