source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDcalcCoverage.java @ 922

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