1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.LinkedHashSet;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
9 | import de.ugoe.cs.eventbench.data.Event;
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import 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 | */
|
---|
22 | public 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 | }
|
---|