1 /***
2 * B94Collector
3 *
4 * This class is responsible for gathering and
5 * interpreting results.
6 */
7
8 package junit.quilt.cover.ball94;
9
10 import org.apache.commons.graph.*;
11
12 import cern.colt.matrix.*;
13 import cern.colt.matrix.impl.*;
14 import cern.colt.matrix.linalg.*;
15
16 import junit.quilt.framework.*;
17 import junit.quilt.cover.generic.*;
18
19 import java.util.Set;
20 import java.util.List;
21 import java.util.HashSet;
22 import java.util.Iterator;
23
24 public class B94Collector
25 extends QuiltCollectorImpl
26 {
27 private DoubleMatrix2D edgeMatrix = null;
28 private ControlFlowGraph graph = null;
29 private List edges = null;
30 private List vertices = null;
31 private int stats[];
32
33 private static String capabilities[] = {
34 BRANCH_COVERAGE
35 };
36
37 /***
38 * Create a new collector for the particular
39 * graph. The matrix provided is in the format:
40 *
41 * e0 e1 e2 ... eE
42 * i0
43 * i1
44 * .
45 * .
46 * iI
47 * v0
48 * v1
49 * .
50 * .
51 * vV
52 *
53 * This is why Lists are passed around, and not Sets.
54 */
55 public B94Collector( List vertices,
56 List edges,
57 DoubleMatrix2D edgeMatrix,
58 int stats[])
59 {
60 super( capabilities );
61 this.stats = stats;
62 this.graph = graph;
63 this.vertices = vertices;
64 this.edges = edges;
65 this.edgeMatrix = edgeMatrix;
66 }
67
68 public Set getBranchCoverage() {
69 Algebra alg = new Algebra(0.001);
70 DoubleMatrix2D C = new DenseDoubleMatrix2D( (vertices.size() +
71 stats.length), 1 );
72
73 for (int i = 0; i < stats.length; i++) {
74 C.set( i, 0, stats[i]);
75 }
76
77 DoubleMatrix2D X = alg.solve( edgeMatrix, C );
78
79 Set RC = new HashSet();
80 for (int i = 0; i < X.rows(); i++) {
81 BranchSegment BS =
82 new BranchSegment("Unknown",
83 (FlowControlEdge) edges.get(i));
84 BS.setNumVisits( (int) Math.abs( X.get( i, 0 ) ));
85 RC.add( BS );
86 }
87
88 return RC;
89 }
90
91
92 public Set getAll( String coverage ) {
93 if (coverage.equals(BRANCH_COVERAGE)) {
94 return getBranchCoverage();
95 }
96 return null;
97 }
98
99 public void reset() {
100 for (int i = 0; i < stats.length; i++) {
101 stats[i] = 0;
102 }
103 }
104 }
This page was automatically generated by Maven