1 package org.simantics.scl.compiler.module.coverage;
\r
3 import java.io.PrintStream;
\r
4 import java.util.Arrays;
\r
6 import gnu.trove.map.hash.THashMap;
\r
8 public class ModuleCoverage extends AbstractCoverage {
\r
10 public final THashMap<String, FunctionCoverage> functionCoverages;
\r
12 public final int totalFunctionCount;
\r
13 public final int coveredFunctionCount;
\r
14 public final double functionCoverage;
\r
16 public ModuleCoverage(String moduleName, THashMap<String, FunctionCoverage> functionCoverages,
\r
17 int totalCodeSize, int coveredCodeSize,
\r
18 int totalFunctionCount, int coveredFunctionCount) {
\r
20 super(moduleName, totalCodeSize, coveredCodeSize);
\r
21 this.functionCoverages = functionCoverages;
\r
22 this.totalFunctionCount = totalFunctionCount;
\r
23 this.coveredFunctionCount = coveredFunctionCount;
\r
24 this.functionCoverage = CoverageUtils.safeDiv(coveredFunctionCount, totalFunctionCount);
\r
27 public void print(PrintStream s) {
\r
28 s.println("Code coverage: " + toPercent(getCoverage()) +
\r
29 " (" + getCoveredCodeSize() + " / " + getTotalCodeSize() + ")");
\r
30 s.println("Function coverage: " + toPercent(functionCoverage) +
\r
31 " (" + coveredFunctionCount + " / " + totalFunctionCount + ")");
\r
32 String[] functionNames = functionCoverages.keySet().toArray(new String[functionCoverages.size()]);
\r
33 Arrays.sort(functionNames);
\r
34 for(String functionName : functionNames) {
\r
35 FunctionCoverage fCov = functionCoverages.get(functionName);
\r
36 s.println(" " + functionName + ": " + toPercent(fCov.getCoverage()) +
\r
37 " (" + fCov.coveredCodeSize + " / " + fCov.totalCodeSize + ")");
\r