[927] | 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 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.usage;
|
---|
[117] | 16 |
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 21 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
| 22 | import de.ugoe.cs.autoquest.coverage.CoverageCalculatorObserved;
|
---|
| 23 | import de.ugoe.cs.autoquest.coverage.CoverageCalculatorProcess;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 25 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[117] | 26 | import de.ugoe.cs.util.console.Command;
|
---|
| 27 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 28 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[117] | 29 |
|
---|
[171] | 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 | */
|
---|
[117] | 38 | public class CMDcalcCoverage implements Command {
|
---|
| 39 |
|
---|
[171] | 40 | /*
|
---|
| 41 | * (non-Javadoc)
|
---|
| 42 | *
|
---|
| 43 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 44 | */
|
---|
[117] | 45 | @SuppressWarnings("unchecked")
|
---|
| 46 | @Override
|
---|
| 47 | public void run(List<Object> parameters) {
|
---|
[171] | 48 | String modelname;
|
---|
[241] | 49 | String observedName;
|
---|
[117] | 50 | String[] sequenceNames;
|
---|
| 51 | int minLength;
|
---|
| 52 | int maxLength;
|
---|
| 53 | try {
|
---|
| 54 | modelname = (String) parameters.get(0);
|
---|
[241] | 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));
|
---|
[171] | 59 | } catch (Exception e) {
|
---|
[766] | 60 | throw new IllegalArgumentException();
|
---|
[117] | 61 | }
|
---|
[171] | 62 |
|
---|
| 63 | IStochasticProcess process = null;
|
---|
[547] | 64 | Collection<List<Event>> observedSequences = null;
|
---|
| 65 | Collection<List<Event>> sequences = null;
|
---|
[171] | 66 | Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
|
---|
| 67 | modelname);
|
---|
| 68 | Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
|
---|
| 69 | observedName);
|
---|
| 70 | if (dataObjectProcess == null) {
|
---|
[240] | 71 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[127] | 72 | return;
|
---|
[117] | 73 | }
|
---|
[171] | 74 | if (!(dataObjectProcess instanceof IStochasticProcess)) {
|
---|
[240] | 75 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
[127] | 76 | return;
|
---|
| 77 | }
|
---|
[171] | 78 | if (dataObjectObserved == null) {
|
---|
[240] | 79 | CommandHelpers.objectNotFoundMessage(observedName);
|
---|
[127] | 80 | return;
|
---|
| 81 | }
|
---|
[209] | 82 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
|
---|
[240] | 83 | CommandHelpers.objectNotType(observedName,
|
---|
| 84 | "Collection<List<Event<?>>>");
|
---|
[127] | 85 | return;
|
---|
| 86 | }
|
---|
| 87 | process = (IStochasticProcess) dataObjectProcess;
|
---|
[547] | 88 | observedSequences = (Collection<List<Event>>) dataObjectObserved;
|
---|
[171] | 89 |
|
---|
[127] | 90 | Console.print("seqName");
|
---|
[171] | 91 | for (int length = minLength; length <= maxLength; length++) {
|
---|
[127] | 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("");
|
---|
[171] | 106 | for (String sequenceName : sequenceNames) {
|
---|
| 107 | Object dataObjectSequences = GlobalDataContainer.getInstance()
|
---|
| 108 | .getData(sequenceName);
|
---|
| 109 | if (dataObjectSequences == null) {
|
---|
[240] | 110 | CommandHelpers.objectNotFoundMessage(sequenceName);
|
---|
[209] | 111 | return;
|
---|
| 112 | } else if (!SequenceInstanceOf
|
---|
| 113 | .isCollectionOfSequences(dataObjectSequences)) {
|
---|
[240] | 114 | CommandHelpers.objectNotType(sequenceName,
|
---|
| 115 | "Collection<List<Event<?>>>");
|
---|
[127] | 116 | return;
|
---|
| 117 | }
|
---|
[547] | 118 | sequences = (Collection<List<Event>>) dataObjectSequences;
|
---|
[127] | 119 | Console.print(sequenceName);
|
---|
[171] | 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);
|
---|
[127] | 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());
|
---|
[171] | 133 | Console.print(";"
|
---|
| 134 | + covCalcObs.getCoverageObservedWeigth(process));
|
---|
[127] | 135 | Console.print(";" + covCalcObs.getNewPercentage());
|
---|
| 136 | Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
|
---|
[171] | 137 | Console.print(";"
|
---|
| 138 | + covCalcObs.getCoveragePossibleNewWeight(process));
|
---|
[117] | 139 | }
|
---|
| 140 | Console.println("");
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[171] | 144 | /*
|
---|
| 145 | * (non-Javadoc)
|
---|
| 146 | *
|
---|
| 147 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 148 | */
|
---|
[117] | 149 | @Override
|
---|
[664] | 150 | public String help() {
|
---|
[726] | 151 | return "calcCoverage <modelname> <observedSequences> [<sequenceNames>] <minCovLength> <maxCovLength>";
|
---|
[117] | 152 | }
|
---|
| 153 |
|
---|
| 154 | }
|
---|