]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/ModuleCoverage.java
Merge "Redirect document commandRelation and commandExecutorRelation terminals"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / coverage / ModuleCoverage.java
1 package org.simantics.scl.compiler.module.coverage;
2
3 import java.io.PrintStream;
4 import java.util.Arrays;
5
6 import gnu.trove.map.hash.THashMap;
7
8 public class ModuleCoverage extends AbstractCoverage {
9     
10     public final THashMap<String, FunctionCoverage> functionCoverages;
11     
12     public final int totalFunctionCount;
13     public final int coveredFunctionCount;
14     public final double functionCoverage;
15     
16     public ModuleCoverage(String moduleName, THashMap<String, FunctionCoverage> functionCoverages,
17             int totalCodeSize, int coveredCodeSize,
18             int totalFunctionCount, int coveredFunctionCount) {
19         
20         super(moduleName, totalCodeSize, coveredCodeSize);
21         this.functionCoverages = functionCoverages;
22         this.totalFunctionCount = totalFunctionCount;
23         this.coveredFunctionCount = coveredFunctionCount;
24         this.functionCoverage = CoverageUtils.safeDiv(coveredFunctionCount, totalFunctionCount);
25     }
26     
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 + ")");
38         }   
39     }
40
41 }