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
RevLine 
[432]1package de.ugoe.cs.quest.commands;
[117]2
3import java.security.InvalidParameterException;
4import java.util.Collection;
5import java.util.List;
6
[432]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;
[117]14import de.ugoe.cs.util.console.Command;
15import de.ugoe.cs.util.console.Console;
16
[171]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 */
[117]25public class CMDcalcCoverage implements Command {
26
[171]27        /*
28         * (non-Javadoc)
29         *
30         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
31         */
[117]32        @SuppressWarnings("unchecked")
33        @Override
34        public void run(List<Object> parameters) {
[171]35                String modelname;
[241]36                String observedName;
[117]37                String[] sequenceNames;
38                int minLength;
39                int maxLength;
40                try {
41                        modelname = (String) parameters.get(0);
[241]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));
[171]46                } catch (Exception e) {
[117]47                        throw new InvalidParameterException();
48                }
[171]49
50                IStochasticProcess process = null;
[127]51                Collection<List<? extends Event<?>>> observedSequences = null;
[119]52                Collection<List<? extends Event<?>>> sequences = null;
[171]53                Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
54                                modelname);
55                Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
56                                observedName);
57                if (dataObjectProcess == null) {
[240]58                        CommandHelpers.objectNotFoundMessage(modelname);
[127]59                        return;
[117]60                }
[171]61                if (!(dataObjectProcess instanceof IStochasticProcess)) {
[240]62                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
[127]63                        return;
64                }
[171]65                if (dataObjectObserved == null) {
[240]66                        CommandHelpers.objectNotFoundMessage(observedName);
[127]67                        return;
68                }
[209]69                if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
[240]70                        CommandHelpers.objectNotType(observedName,
71                                        "Collection<List<Event<?>>>");
[127]72                        return;
73                }
74                process = (IStochasticProcess) dataObjectProcess;
75                observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved;
[171]76
[127]77                Console.print("seqName");
[171]78                for (int length = minLength; length <= maxLength; length++) {
[127]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("");
[171]93                for (String sequenceName : sequenceNames) {
94                        Object dataObjectSequences = GlobalDataContainer.getInstance()
95                                        .getData(sequenceName);
96                        if (dataObjectSequences == null) {
[240]97                                CommandHelpers.objectNotFoundMessage(sequenceName);
[209]98                                return;
99                        } else if (!SequenceInstanceOf
100                                        .isCollectionOfSequences(dataObjectSequences)) {
[240]101                                CommandHelpers.objectNotType(sequenceName,
102                                                "Collection<List<Event<?>>>");
[127]103                                return;
104                        }
105                        sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
106                        Console.print(sequenceName);
[171]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);
[127]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());
[171]120                                Console.print(";"
121                                                + covCalcObs.getCoverageObservedWeigth(process));
[127]122                                Console.print(";" + covCalcObs.getNewPercentage());
123                                Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
[171]124                                Console.print(";"
125                                                + covCalcObs.getCoveragePossibleNewWeight(process));
[117]126                        }
127                        Console.println("");
128                }
129        }
130
[171]131        /*
132         * (non-Javadoc)
133         *
134         * @see de.ugoe.cs.util.console.Command#help()
135         */
[117]136        @Override
137        public void help() {
[241]138                Console.println("Usage: calcCoverage <modelname> <observedSequences> [sequenceNames] <minCovLength> <maxCovLength>");
[117]139        }
140
141}
Note: See TracBrowser for help on using the repository browser.