]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/ModuleCoverage.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / coverage / ModuleCoverage.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/ModuleCoverage.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/coverage/ModuleCoverage.java
new file mode 100644 (file)
index 0000000..bad4012
--- /dev/null
@@ -0,0 +1,41 @@
+package org.simantics.scl.compiler.module.coverage;\r
+\r
+import java.io.PrintStream;\r
+import java.util.Arrays;\r
+\r
+import gnu.trove.map.hash.THashMap;\r
+\r
+public class ModuleCoverage extends AbstractCoverage {\r
+    \r
+    public final THashMap<String, FunctionCoverage> functionCoverages;\r
+    \r
+    public final int totalFunctionCount;\r
+    public final int coveredFunctionCount;\r
+    public final double functionCoverage;\r
+    \r
+    public ModuleCoverage(String moduleName, THashMap<String, FunctionCoverage> functionCoverages,\r
+            int totalCodeSize, int coveredCodeSize,\r
+            int totalFunctionCount, int coveredFunctionCount) {\r
+        \r
+        super(moduleName, totalCodeSize, coveredCodeSize);\r
+        this.functionCoverages = functionCoverages;\r
+        this.totalFunctionCount = totalFunctionCount;\r
+        this.coveredFunctionCount = coveredFunctionCount;\r
+        this.functionCoverage = CoverageUtils.safeDiv(coveredFunctionCount, totalFunctionCount);\r
+    }\r
+    \r
+    public void print(PrintStream s) {\r
+        s.println("Code coverage: " + toPercent(getCoverage()) +\r
+                " (" + getCoveredCodeSize() + " / " + getTotalCodeSize() + ")"); \r
+        s.println("Function coverage: " + toPercent(functionCoverage) +\r
+                " (" + coveredFunctionCount + " / " + totalFunctionCount + ")");\r
+        String[] functionNames = functionCoverages.keySet().toArray(new String[functionCoverages.size()]);\r
+        Arrays.sort(functionNames);\r
+        for(String functionName : functionNames) {\r
+            FunctionCoverage fCov = functionCoverages.get(functionName);\r
+            s.println("    " + functionName + ": " + toPercent(fCov.getCoverage()) +\r
+                    " (" + fCov.coveredCodeSize + " / " + fCov.totalCodeSize + ")");\r
+        }   \r
+    }\r
+\r
+}\r