1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
8 | import de.ugoe.cs.eventbench.SequenceInstanceOf;
|
---|
9 | import de.ugoe.cs.eventbench.coverage.CoverageCalculatorObserved;
|
---|
10 | import de.ugoe.cs.eventbench.coverage.CoverageCalculatorProcess;
|
---|
11 | import de.ugoe.cs.eventbench.data.Event;
|
---|
12 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
13 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
14 | import de.ugoe.cs.util.console.Command;
|
---|
15 | import de.ugoe.cs.util.console.Console;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * <p>
|
---|
19 | * Command to calculate the coverage of a test suite.
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @author Steffen Herbold
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 | public class CMDcalcCoverage implements Command {
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * (non-Javadoc)
|
---|
29 | *
|
---|
30 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
31 | */
|
---|
32 | @SuppressWarnings("unchecked")
|
---|
33 | @Override
|
---|
34 | public void run(List<Object> parameters) {
|
---|
35 | String modelname;
|
---|
36 | String[] sequenceNames;
|
---|
37 | int minLength;
|
---|
38 | int maxLength;
|
---|
39 | String observedName = "sequences";
|
---|
40 | try {
|
---|
41 | modelname = (String) parameters.get(0);
|
---|
42 | sequenceNames = (String[]) parameters.get(1);
|
---|
43 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
44 | maxLength = Integer.parseInt((String) parameters.get(3));
|
---|
45 | if (parameters.size() == 5) {
|
---|
46 | observedName = (String) parameters.get(4);
|
---|
47 | }
|
---|
48 | } catch (Exception e) {
|
---|
49 | throw new InvalidParameterException();
|
---|
50 | }
|
---|
51 |
|
---|
52 | IStochasticProcess process = null;
|
---|
53 | Collection<List<? extends Event<?>>> observedSequences = null;
|
---|
54 | Collection<List<? extends Event<?>>> sequences = null;
|
---|
55 | Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
|
---|
56 | modelname);
|
---|
57 | Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
|
---|
58 | observedName);
|
---|
59 | if (dataObjectProcess == null) {
|
---|
60 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | if (!(dataObjectProcess instanceof IStochasticProcess)) {
|
---|
64 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | if (dataObjectObserved == null) {
|
---|
68 | CommandHelpers.objectNotFoundMessage(observedName);
|
---|
69 | return;
|
---|
70 | }
|
---|
71 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
|
---|
72 | CommandHelpers.objectNotType(observedName,
|
---|
73 | "Collection<List<Event<?>>>");
|
---|
74 | return;
|
---|
75 | }
|
---|
76 | process = (IStochasticProcess) dataObjectProcess;
|
---|
77 | observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved;
|
---|
78 |
|
---|
79 | Console.print("seqName");
|
---|
80 | for (int length = minLength; length <= maxLength; length++) {
|
---|
81 | Console.print(";numObs_" + length);
|
---|
82 | Console.print(";numCov_" + length);
|
---|
83 | Console.print(";numNew_" + length);
|
---|
84 | Console.print(";numPos_" + length);
|
---|
85 | Console.print(";all_" + length);
|
---|
86 | Console.print(";pos_" + length);
|
---|
87 | Console.print(";poswei_" + length);
|
---|
88 | Console.print(";obs_" + length);
|
---|
89 | Console.print(";obswei_" + length);
|
---|
90 | Console.print(";new_" + length);
|
---|
91 | Console.print(";newpos_" + length);
|
---|
92 | Console.print(";newposwei_" + length);
|
---|
93 | }
|
---|
94 | Console.println("");
|
---|
95 | for (String sequenceName : sequenceNames) {
|
---|
96 | Object dataObjectSequences = GlobalDataContainer.getInstance()
|
---|
97 | .getData(sequenceName);
|
---|
98 | if (dataObjectSequences == null) {
|
---|
99 | CommandHelpers.objectNotFoundMessage(sequenceName);
|
---|
100 | return;
|
---|
101 | } else if (!SequenceInstanceOf
|
---|
102 | .isCollectionOfSequences(dataObjectSequences)) {
|
---|
103 | CommandHelpers.objectNotType(sequenceName,
|
---|
104 | "Collection<List<Event<?>>>");
|
---|
105 | return;
|
---|
106 | }
|
---|
107 | sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
|
---|
108 | Console.print(sequenceName);
|
---|
109 | for (int length = minLength; length <= maxLength; length++) {
|
---|
110 | CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(
|
---|
111 | process, sequences, length);
|
---|
112 | CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(
|
---|
113 | observedSequences, sequences, length);
|
---|
114 | Console.print(";" + covCalcObs.getNumObserved());
|
---|
115 | Console.print(";" + covCalcObs.getNumCovered());
|
---|
116 | Console.print(";" + covCalcObs.getNumNew());
|
---|
117 | Console.print(";" + covCalcProc.getNumPossible());
|
---|
118 | Console.print(";" + covCalcProc.getCoverageAllNoWeight());
|
---|
119 | Console.print(";" + covCalcProc.getCoveragePossibleNoWeight());
|
---|
120 | Console.print(";" + covCalcProc.getCoveragePossibleWeight());
|
---|
121 | Console.print(";" + covCalcObs.getCoverageObserved());
|
---|
122 | Console.print(";"
|
---|
123 | + covCalcObs.getCoverageObservedWeigth(process));
|
---|
124 | Console.print(";" + covCalcObs.getNewPercentage());
|
---|
125 | Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
|
---|
126 | Console.print(";"
|
---|
127 | + covCalcObs.getCoveragePossibleNewWeight(process));
|
---|
128 | }
|
---|
129 | Console.println("");
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * (non-Javadoc)
|
---|
135 | *
|
---|
136 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
137 | */
|
---|
138 | @Override
|
---|
139 | public void help() {
|
---|
140 | Console.println("Usage: calcCoverage <modelname> [sequenceNames] <minCovLength> <maxCovLength>");
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|