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 CombinedCoverage extends AbstractCoverage {
9 public final THashMap<String, ModuleCoverage> moduleCoverages;
11 public final int totalFunctionCount;
12 public final int coveredFunctionCount;
13 public final double functionCoverage;
15 public CombinedCoverage(THashMap<String, ModuleCoverage> moduleCoverages,
16 int totalCodeSize, int coveredCodeSize,
17 int totalFunctionCount, int coveredFunctionCount) {
18 super("Total coverage of " + moduleCoverages.size() + " modules", totalCodeSize, coveredCodeSize);
19 this.moduleCoverages = moduleCoverages;
20 this.totalFunctionCount = totalFunctionCount;
21 this.coveredFunctionCount = coveredFunctionCount;
22 this.functionCoverage = CoverageUtils.safeDiv(coveredFunctionCount, totalFunctionCount);
25 public void print(PrintStream s) {
26 s.println("Code coverage: " + toPercent(getCoverage()) +
27 " (" + getCoveredCodeSize() + " / " + getTotalCodeSize() + ")");
28 s.println("Function coverage: " + toPercent(functionCoverage) +
29 " (" + coveredFunctionCount + " / " + totalFunctionCount + ")");
30 String[] moduleNames = moduleCoverages.keySet().toArray(new String[moduleCoverages.size()]);
31 Arrays.sort(moduleNames);
32 for(String functionName : moduleNames) {
33 ModuleCoverage mCov = moduleCoverages.get(functionName);
34 s.println(" " + functionName + ": " + toPercent(mCov.getCoverage()) +
35 " (" + mCov.getCoveredCodeSize() + " / " + mCov.getTotalCodeSize() + ")");