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

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 5.4 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.commands.usage;
16
17import java.util.Collection;
18import java.util.List;
19
20import de.ugoe.cs.autoquest.CommandHelpers;
21import de.ugoe.cs.autoquest.SequenceInstanceOf;
22import de.ugoe.cs.autoquest.coverage.CoverageCalculatorObserved;
23import de.ugoe.cs.autoquest.coverage.CoverageCalculatorProcess;
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
26import de.ugoe.cs.util.console.Command;
27import de.ugoe.cs.util.console.Console;
28import de.ugoe.cs.util.console.GlobalDataContainer;
29
30/**
31 * <p>
32 * Command to calculate the coverage of a test suite.
33 * </p>
34 *
35 * @author Steffen Herbold
36 * @version 1.0
37 */
38public class CMDcalcCoverage implements Command {
39
40        /*
41         * (non-Javadoc)
42         *
43         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
44         */
45        @SuppressWarnings("unchecked")
46        @Override
47        public void run(List<Object> parameters) {
48                String modelname;
49                String observedName;
50                String[] sequenceNames;
51                int minLength;
52                int maxLength;
53                try {
54                        modelname = (String) parameters.get(0);
55                        observedName = (String) parameters.get(1);
56                        sequenceNames = (String[]) parameters.get(2);
57                        minLength = Integer.parseInt((String) parameters.get(3));
58                        maxLength = Integer.parseInt((String) parameters.get(4));
59                } catch (Exception e) {
60                        throw new IllegalArgumentException();
61                }
62
63                IStochasticProcess process = null;
64                Collection<List<Event>> observedSequences = null;
65                Collection<List<Event>> sequences = null;
66                Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
67                                modelname);
68                Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
69                                observedName);
70                if (dataObjectProcess == null) {
71                        CommandHelpers.objectNotFoundMessage(modelname);
72                        return;
73                }
74                if (!(dataObjectProcess instanceof IStochasticProcess)) {
75                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
76                        return;
77                }
78                if (dataObjectObserved == null) {
79                        CommandHelpers.objectNotFoundMessage(observedName);
80                        return;
81                }
82                if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
83                        CommandHelpers.objectNotType(observedName,
84                                        "Collection<List<Event<?>>>");
85                        return;
86                }
87                process = (IStochasticProcess) dataObjectProcess;
88                observedSequences = (Collection<List<Event>>) dataObjectObserved;
89
90                Console.print("seqName");
91                for (int length = minLength; length <= maxLength; length++) {
92                        Console.print(";numObs_" + length);
93                        Console.print(";numCov_" + length);
94                        Console.print(";numNew_" + length);
95                        Console.print(";numPos_" + length);
96                        Console.print(";all_" + length);
97                        Console.print(";pos_" + length);
98                        Console.print(";poswei_" + length);
99                        Console.print(";obs_" + length);
100                        Console.print(";obswei_" + length);
101                        Console.print(";new_" + length);
102                        Console.print(";newpos_" + length);
103                        Console.print(";newposwei_" + length);
104                }
105                Console.println("");
106                for (String sequenceName : sequenceNames) {
107                        Object dataObjectSequences = GlobalDataContainer.getInstance()
108                                        .getData(sequenceName);
109                        if (dataObjectSequences == null) {
110                                CommandHelpers.objectNotFoundMessage(sequenceName);
111                                return;
112                        } else if (!SequenceInstanceOf
113                                        .isCollectionOfSequences(dataObjectSequences)) {
114                                CommandHelpers.objectNotType(sequenceName,
115                                                "Collection<List<Event<?>>>");
116                                return;
117                        }
118                        sequences = (Collection<List<Event>>) dataObjectSequences;
119                        Console.print(sequenceName);
120                        for (int length = minLength; length <= maxLength; length++) {
121                                CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(
122                                                process, sequences, length);
123                                CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(
124                                                observedSequences, sequences, length);
125                                Console.print(";" + covCalcObs.getNumObserved());
126                                Console.print(";" + covCalcObs.getNumCovered());
127                                Console.print(";" + covCalcObs.getNumNew());
128                                Console.print(";" + covCalcProc.getNumPossible());
129                                Console.print(";" + covCalcProc.getCoverageAllNoWeight());
130                                Console.print(";" + covCalcProc.getCoveragePossibleNoWeight());
131                                Console.print(";" + covCalcProc.getCoveragePossibleWeight());
132                                Console.print(";" + covCalcObs.getCoverageObserved());
133                                Console.print(";"
134                                                + covCalcObs.getCoverageObservedWeigth(process));
135                                Console.print(";" + covCalcObs.getNewPercentage());
136                                Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
137                                Console.print(";"
138                                                + covCalcObs.getCoveragePossibleNewWeight(process));
139                        }
140                        Console.println("");
141                }
142        }
143
144        /*
145         * (non-Javadoc)
146         *
147         * @see de.ugoe.cs.util.console.Command#help()
148         */
149        @Override
150        public String help() {
151                return "calcCoverage <modelname> <observedSequences> [<sequenceNames>] <minCovLength> <maxCovLength>";
152        }
153
154}
Note: See TracBrowser for help on using the repository browser.