...
 
Commits (5)
......@@ -35,18 +35,7 @@ public abstract class Application<T> {
this.randomGenerator = new Random(seed);
this.applicationSize = applicationSize;
this.dataStructure = structure;
this.baseStructureSize = 0;
clearDataStructure(); // TODO: This is a bit odd
// 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();
}
initialize(structure);
List<Method> callableMethods = getRunnableMethods();
if (callableMethods.isEmpty()) { return; }
......@@ -74,7 +63,16 @@ public abstract class Application<T> {
}
}
// TODO: Some copy-paste here
initialize(structure);
}
/**
* Initialized the data structure and potential arguments for the
* application.
* @param structure
*/
private void initialize(T structure) {
this.dataStructure = structure;
this.baseStructureSize = 0;
clearDataStructure();
......@@ -86,7 +84,6 @@ public abstract class Application<T> {
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
Application(int seed, List<String> trace, T structure) {
......
import org.junit.Assert;
import org.junit.Test;
import se.lth.cs.ApplicationGeneration.ListApplicationGenerator;
import se.lth.cs.ApplicationRunner;
import se.lth.cs.TrainingSetValue;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ApplicationRunnerTest {
@Test
public void TestApplicationGeneratorSpread() throws InvocationTargetException, IllegalAccessException {
ApplicationRunner r = new ApplicationRunner();
Long threshold = 3l;
List<TrainingSetValue> values =
r.createListApplicationsSpread(threshold, 10,new ListApplicationGenerator());
Map<String, Long> histogram = values.stream().collect(
Collectors.groupingBy(TrainingSetValue::getBestDataStructure, Collectors.counting())
);
Assert.assertEquals(3, histogram.keySet().size());
Assert.assertTrue( histogram.values().stream().min(Long::compareTo).orElse(0l) >= threshold);
}
}
......@@ -201,38 +201,6 @@ public class ApplicationTest {
}
}
@Test
public void TestMedian() {
List<Double> values = new ArrayList<>();
for (Integer i = 0; i < 10; ++i) {
values.add(i.doubleValue());
}
Assert.assertEquals(4.5, UtilsKt.median(values), 0.001);
List<Double> values1 = new ArrayList<>();
values1.add(1.0);
values1.add(4.0);
values1.add(5.0);
values1.add(3.0);
Assert.assertEquals(3.5, UtilsKt.median(values1), 0.0001);
}
@Test
public void TestApplicationGeneratorSpread() throws InvocationTargetException, IllegalAccessException {
ApplicationRunner r = new ApplicationRunner();
Long threshold = 3l;
List<TrainingSetValue> values =
r.createListApplicationsSpread(threshold, 10,new ListApplicationGenerator());
Map<String, Long> histogram = values.stream().collect(
Collectors.groupingBy(TrainingSetValue::getBestDataStructure, Collectors.counting())
);
Assert.assertEquals(3, histogram.keySet().size());
Assert.assertTrue( histogram.values().stream().min(Long::compareTo).orElse(0l) >= threshold);
}
@Test
public void testHistogram2() {
for (int seed = 0; seed < 100; seed++) {
......@@ -279,24 +247,10 @@ public class ApplicationTest {
);
}
@Test
public void testRandomConstant() {
int s = 0;
Random r = new Random(s);
IntStream ints = r.ints(5);
String actual =
ints.collect(StringBuilder::new,
StringBuilder::append, StringBuilder::append)
.toString();
String expected = "-1155484576-7239554001033096058-1690734402-1557280266";
Assert.assertEquals(expected, actual);
}
/** Test that emptying and repopulating the data structure does not change the app.
*
*/
@Test
/** Test that emptying and repopulating the data structure does not change the app.
*
*/
public void testPopulate() {
ListApplication app1 = new ListApplication(4, 100, 100, new ArrayList<>());
ListApplication app2 = new ListApplication(4, 100, 100, new ArrayList<>());
......
import org.junit.Assert
import org.junit.Test
import se.lth.cs.median
import java.util.ArrayList
class UtilsTest {
@Test
fun TestMedian() {
val values = ArrayList<Double>()
for (i in 0..9) {
values.add(i.toDouble())
}
Assert.assertEquals(4.5, median(values), 0.001)
val values1 = ArrayList<Double>()
values1.add(1.0)
values1.add(4.0)
values1.add(5.0)
values1.add(3.0)
Assert.assertEquals(3.5, median(values1), 0.0001)
}
}