source: trunk/quest-ui-core/src/de/ugoe/cs/quest/commands/CMDcalcCoverage.java @ 432

Last change on this file since 432 was 432, checked in by sherbold, 12 years ago
  • renamed packages to fir QUEST project structure
  • Property svn:mime-type set to text/plain
File size: 4.8 KB
Line 
1package de.ugoe.cs.quest.commands;
2
3import java.security.InvalidParameterException;
4import java.util.Collection;
5import java.util.List;
6
7import de.ugoe.cs.quest.CommandHelpers;
8import de.ugoe.cs.quest.SequenceInstanceOf;
9import de.ugoe.cs.quest.coverage.CoverageCalculatorObserved;
10import de.ugoe.cs.quest.coverage.CoverageCalculatorProcess;
11import de.ugoe.cs.quest.data.Event;
12import de.ugoe.cs.quest.data.GlobalDataContainer;
13import de.ugoe.cs.quest.models.IStochasticProcess;
14import de.ugoe.cs.util.console.Command;
15import 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 */
25public 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 observedName;
37                String[] sequenceNames;
38                int minLength;
39                int maxLength;
40                try {
41                        modelname = (String) parameters.get(0);
42                        observedName = (String) parameters.get(1);
43                        sequenceNames = (String[]) parameters.get(2);
44                        minLength = Integer.parseInt((String) parameters.get(3));
45                        maxLength = Integer.parseInt((String) parameters.get(4));
46                } catch (Exception e) {
47                        throw new InvalidParameterException();
48                }
49
50                IStochasticProcess process = null;
51                Collection<List<? extends Event<?>>> observedSequences = null;
52                Collection<List<? extends Event<?>>> sequences = null;
53                Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
54                                modelname);
55                Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
56                                observedName);
57                if (dataObjectProcess == null) {
58                        CommandHelpers.objectNotFoundMessage(modelname);
59                        return;
60                }
61                if (!(dataObjectProcess instanceof IStochasticProcess)) {
62                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
63                        return;
64                }
65                if (dataObjectObserved == null) {
66                        CommandHelpers.objectNotFoundMessage(observedName);
67                        return;
68                }
69                if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
70                        CommandHelpers.objectNotType(observedName,
71                                        "Collection<List<Event<?>>>");
72                        return;
73                }
74                process = (IStochasticProcess) dataObjectProcess;
75                observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved;
76
77                Console.print("seqName");
78                for (int length = minLength; length <= maxLength; length++) {
79                        Console.print(";numObs_" + length);
80                        Console.print(";numCov_" + length);
81                        Console.print(";numNew_" + length);
82                        Console.print(";numPos_" + length);
83                        Console.print(";all_" + length);
84                        Console.print(";pos_" + length);
85                        Console.print(";poswei_" + length);
86                        Console.print(";obs_" + length);
87                        Console.print(";obswei_" + length);
88                        Console.print(";new_" + length);
89                        Console.print(";newpos_" + length);
90                        Console.print(";newposwei_" + length);
91                }
92                Console.println("");
93                for (String sequenceName : sequenceNames) {
94                        Object dataObjectSequences = GlobalDataContainer.getInstance()
95                                        .getData(sequenceName);
96                        if (dataObjectSequences == null) {
97                                CommandHelpers.objectNotFoundMessage(sequenceName);
98                                return;
99                        } else if (!SequenceInstanceOf
100                                        .isCollectionOfSequences(dataObjectSequences)) {
101                                CommandHelpers.objectNotType(sequenceName,
102                                                "Collection<List<Event<?>>>");
103                                return;
104                        }
105                        sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
106                        Console.print(sequenceName);
107                        for (int length = minLength; length <= maxLength; length++) {
108                                CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(
109                                                process, sequences, length);
110                                CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(
111                                                observedSequences, sequences, length);
112                                Console.print(";" + covCalcObs.getNumObserved());
113                                Console.print(";" + covCalcObs.getNumCovered());
114                                Console.print(";" + covCalcObs.getNumNew());
115                                Console.print(";" + covCalcProc.getNumPossible());
116                                Console.print(";" + covCalcProc.getCoverageAllNoWeight());
117                                Console.print(";" + covCalcProc.getCoveragePossibleNoWeight());
118                                Console.print(";" + covCalcProc.getCoveragePossibleWeight());
119                                Console.print(";" + covCalcObs.getCoverageObserved());
120                                Console.print(";"
121                                                + covCalcObs.getCoverageObservedWeigth(process));
122                                Console.print(";" + covCalcObs.getNewPercentage());
123                                Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
124                                Console.print(";"
125                                                + covCalcObs.getCoveragePossibleNewWeight(process));
126                        }
127                        Console.println("");
128                }
129        }
130
131        /*
132         * (non-Javadoc)
133         *
134         * @see de.ugoe.cs.util.console.Command#help()
135         */
136        @Override
137        public void help() {
138                Console.println("Usage: calcCoverage <modelname> <observedSequences> [sequenceNames] <minCovLength> <maxCovLength>");
139        }
140
141}
Note: See TracBrowser for help on using the repository browser.