...
 
Commits (2)
......@@ -66,13 +66,6 @@ public class ListApplication extends CollectionApplication<List<Integer>> {
return dataStructure.get(generateIndex());
}
public Integer runGet2() {
if (dataStructure.isEmpty()) {
return null;
}
return dataStructure.get(generateIndex());
}
public int runIndexOf() {
return dataStructure.indexOf(randomGenerator.nextInt());
}
......
......@@ -44,7 +44,7 @@ class ApplicationDataPrinter(out : Writer) {
size,
baseStructureSize,
application.dataStructureSimpleName,
kvp.first,
printFunction(kvp.first),
kvp.second.toString()
)
}
......
......@@ -2,9 +2,11 @@ package se.lth.cs
import java.lang.IllegalArgumentException
// The table that allows to map from java standard method names to run* names
import org.apache.commons.collections4.BidiMap
import org.apache.commons.collections4.bidimap.DualHashBidiMap
val MethodNameTable = mapOf(
// The table that allows to map from java standard method names to run* names
val MethodNameTable = DualHashBidiMap(mapOf(
Pair("add(Object)", "runAdd"),
Pair("add(int, Object)", "runAdd2"),
Pair("addAll(Collection)", "runAddAll"),
......@@ -24,6 +26,7 @@ val MethodNameTable = mapOf(
Pair("keySet()", "runKeySet"),
Pair("lastIndexOf(Object)", "runLastIndexOf"),
Pair("listIterator()", "runListIterator"),
Pair("listIterator(int)", "runListIterator2"),
Pair("put(Object, Object)", "runPut"),
Pair("putAll(Map)", "runPutAll"),
Pair("remove(Object)", "runRemove"),
......@@ -35,9 +38,9 @@ val MethodNameTable = mapOf(
Pair("sort(Comparator)", "runSort"),
Pair("subList(int, int)", "runSubList"),
Pair("toArray()", "runToArray"),
Pair("toArray(Object[])", "runToArray"),
Pair("toArray(Object[])", "runToArray2"),
Pair("values()", "runValues")
)
))
/**
* Converts the name of a method to the run* method that should be run in the application
......@@ -60,3 +63,8 @@ fun matchFunction(methodName : String) : String {
return match
}
}
fun printFunction(runMethodName : String) : String {
return MethodNameTable.getKey(runMethodName)?:
error(String.format("Could not translate method '%s'", runMethodName))
}
......@@ -221,11 +221,10 @@ public class ApplicationTest {
// Expected: {runAddAll=1, runIsEmpty=1, runToArray=2, runAdd=1}
HashMap<String, Long> expected = new HashMap<String, Long>();
expected.put("runSubList", 1L);
expected.put("runListIterator2", 1L);
expected.put("runAdd", 1L);
expected.put("runRemove", 1L);
expected.put("runIterator", 1L);
expected.put("runToArray2", 2L);
expected.put("runRemoveAll", 1L);
expected.put("runClear", 1L);
expected.put("runContains", 1L);
Assert.assertEquals(
expected,
app.methodHistogram()
......
......@@ -7,6 +7,7 @@ import org.junit.Test
import se.lth.cs.Application
import se.lth.cs.ApplicationDataPrinter
import se.lth.cs.ListApplication
import se.lth.cs.printFunction
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
......@@ -57,6 +58,7 @@ class ApplicationDataPrinterTest {
Pair(it.get("method"), it.get("count").toLong())
}
val targetHistogram = app.methodHistogram()
.mapKeys { printFunction(it.key) }
Assert.assertEquals(
TreeMap(targetHistogram).toString(),
TreeMap(pairs.toMap()).toString()
......@@ -74,14 +76,15 @@ class ApplicationDataPrinterTest {
printer!!.printToCSV(apps)
val expected=
"seed,size,base_structure_size,data_structure,method,count\n" +
"0,10,0,ArrayList,runAdd,1\n" +
"0,10,0,ArrayList,runAddAll,2\n" +
"0,10,0,ArrayList,runAddAll2,2\n" +
"0,10,0,ArrayList,runGet2,1\n" +
"0,10,0,ArrayList,runIterator,1\n" +
"0,10,0,ArrayList,runListIterator2,1\n" +
"0,10,0,ArrayList,runRemove,1\n" +
"0,10,0,ArrayList,runSubList,1\n"
"0,10,0,ArrayList,\"add(int, Object)\",1\n" +
"0,10,0,ArrayList,clear(),1\n" +
"0,10,0,ArrayList,contains(Object),1\n" +
"0,10,0,ArrayList,containsAll(Collection),1\n" +
"0,10,0,ArrayList,equals(Object),1\n" +
"0,10,0,ArrayList,hashCode(),1\n" +
"0,10,0,ArrayList,remove(int),1\n" +
"0,10,0,ArrayList,removeAll(Collection),1\n" +
"0,10,0,ArrayList,toArray(Object[]),2\n"
Assert.assertEquals(
expected, writer.toString()
)
......