source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateGreedy.java @ 292

Last change on this file since 292 was 288, checked in by sherbold, 13 years ago

+ added command generateGreedy that generates a test suite in a non-random way with a greedy strategy to achieve a desired usage-based coverage (not yet fully implemented!)

  • Property svn:mime-type set to text/plain
File size: 2.3 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.Collection;
5import java.util.LinkedHashSet;
6import java.util.List;
7
8import de.ugoe.cs.eventbench.CommandHelpers;
9import de.ugoe.cs.eventbench.data.Event;
10import de.ugoe.cs.eventbench.data.GlobalDataContainer;
11import de.ugoe.cs.eventbench.models.IStochasticProcess;
12import de.ugoe.cs.util.console.Command;
13import de.ugoe.cs.util.console.Console;
14
15/**
16 * <p>
17 * Command to generate test suite with a greedy strategy to achieve a desired coverage.
18 * </p>
19 * @author Steffen Herbold
20 * @version 1.0
21 */
22public class CMDgenerateGreedy implements Command {
23
24        @Override
25        public void run(List<Object> parameters) {
26                String modelname;
27                String sequencesName;
28                int minLength;
29                int maxLength;
30                float desiredCoverage;
31                try {
32                        modelname = (String) parameters.get(0);
33                        sequencesName = (String) parameters.get(1);
34                        minLength = Integer.parseInt((String) parameters.get(2));
35                        maxLength = Integer.parseInt((String) parameters.get(3));
36                        desiredCoverage = Float.parseFloat((String) parameters.get(4));
37                } catch (Exception e) {
38                        throw new InvalidParameterException();
39                }
40
41                IStochasticProcess model = null;
42                Object dataObject = GlobalDataContainer.getInstance()
43                                .getData(modelname);
44                if (dataObject == null) {
45                        CommandHelpers.objectNotFoundMessage(modelname);
46                        return;
47                } else if (!(dataObject instanceof IStochasticProcess)) {
48                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
49                        return;
50                }
51                model = (IStochasticProcess) dataObject;
52                Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>();
53                for (int length = minLength; length <= maxLength; length++) {
54                        sequences.addAll(model.generateValidSequences(length + 2));
55                }
56                Console.traceln("" + sequences.size() + " possible");
57               
58               
59                // TODO implement sequence selection
60               
61                if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
62                        CommandHelpers.dataOverwritten(sequencesName);
63                }
64                Console.println("" + sequences.size() + " sequences generated");
65        }
66
67        @Override
68        public void help() {
69                Console.println("generateGreedy <modelname> <sequencesName> <minLength> <maxLength> <desiredCoverage>");
70        }
71
72}
Note: See TracBrowser for help on using the repository browser.