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