]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/CombinedCoverage.java
Merge "Redirect document commandRelation and commandExecutorRelation terminals"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / coverage / CombinedCoverage.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 CombinedCoverage extends AbstractCoverage {
9     public final THashMap<String, ModuleCoverage> moduleCoverages;
10
11     public final int totalFunctionCount;
12     public final int coveredFunctionCount;
13     public final double functionCoverage;
14     
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);
23     }
24     
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() + ")");
36         }   
37     }
38
39 }