Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit 0ad2408b authored by Noric Couderc's avatar Noric Couderc

Fixed generation of app from trace

It is now possible to generate an app from a trace and setting the seed directly.
parent 7f769f8b
......@@ -75,11 +75,24 @@ public abstract class Application<T> {
}
// TODO: Some copy-paste here
this.applicationSize = trace.size();
this.dataStructure = structure;
this.baseStructureSize = 0;
clearDataStructure();
// Argument becomes a new data structure of same class as
// the data structure to test
try {
argument = (T) dataStructure.getClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
Application(int seed, List<String> trace, T structure) {
this(trace, structure);
this.seed = seed;
this.randomGenerator.setSeed(seed);
}
/**
......
......@@ -22,6 +22,13 @@ public class CollectionApplication<T extends Collection> extends Application<T>
super(trace, (T) init);
}
public CollectionApplication(int seed, List<String> trace, Collection<Integer> init) {
super(seed, trace, (T) init);
// We add random numbers to it.
randomGenerator.ints(100).forEach((i) -> argument.add(i));
}
@Override
public void populate(int numberElements) {
super.populate(numberElements);
......
......@@ -23,6 +23,16 @@ public class ListApplication extends CollectionApplication<List<Integer>> {
super(trace, init);
}
/**
* Creates a list applications with the random generator set to a specific seed.
* @param seed
* @param trace
* @param init
*/
public ListApplication(int seed, List<String> trace, List<Integer> init) {
super(seed, trace, init);
}
public void runAdd2() {
if (dataStructure.isEmpty()) {
dataStructure.add(0, randomGenerator.nextInt());
......
......@@ -16,6 +16,10 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
super(trace, init);
}
public MapApplication(int seed, List<String> trace, Map<Integer, Integer> init) {
super(seed, trace, init);
}
@Override
public void populate(int numberElements) {
super.populate(numberElements);
......
......@@ -16,4 +16,8 @@ public class SetApplication extends CollectionApplication<Set<Integer>> {
public SetApplication(List<String> trace, Set<Integer> init) {
super(trace, init);
}
public SetApplication(int seed, List<String> trace, Set<Integer> init) {
super(seed, trace, init);
}
}
......@@ -319,7 +319,7 @@ public class ApplicationTest {
"runGet"
);
ListApplication app = new ListApplication(trace, new ArrayList());
ListApplication app = new ListApplication(0, trace, new ArrayList());
while (app.hasNext()) {
app.invokeCurrentMethod();
app.tick();
......@@ -334,6 +334,7 @@ public class ApplicationTest {
Assert.assertEquals(s, app.runSize());
Assert.assertTrue(expected.getDataStructure().contains(e));
Assert.assertTrue(app.getDataStructure().contains(app.runGet()));
Assert.assertEquals(expected.getDataStructure(), app.getDataStructure());
}
@Test
......@@ -345,7 +346,7 @@ public class ApplicationTest {
"runContains"
);
SetApplication app = new SetApplication(trace, new TreeSet<>());
SetApplication app = new SetApplication(0, trace, new TreeSet<>());
while (app.hasNext()) {
app.invokeCurrentMethod();
app.tick();
......@@ -357,6 +358,7 @@ public class ApplicationTest {
int s = expected.runSize();
Assert.assertEquals(s, app.runSize());
Assert.assertEquals(expected.getDataStructure(), app.getDataStructure());
}
@Test
......@@ -368,7 +370,7 @@ public class ApplicationTest {
"runGet"
);
MapApplication app = new MapApplication(trace, new HashMap<>());
MapApplication app = new MapApplication(0, trace, new HashMap<>());
while (app.hasNext()) {
app.invokeCurrentMethod();
app.tick();
......@@ -382,6 +384,9 @@ public class ApplicationTest {
Assert.assertEquals(s, app.runSize());
Assert.assertTrue(expected.getDataStructure().containsValue(e));
Assert.assertEquals(app.getDataStructure(), expected.getDataStructure());
}
@Test
public void testReset() throws InvocationTargetException, IllegalAccessException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment