diff --git a/src/test/java/it/unibz/inf/isochrone/network/AlgorithmRuntimeTest.java b/src/test/java/it/unibz/inf/isochrone/network/AlgorithmRuntimeTest.java index d06d522aa01400b1fcd14ebc34fdfea95097fefb..9cfeb39b33c0c93a11dd776cc4d2b30067337510 100644 --- a/src/test/java/it/unibz/inf/isochrone/network/AlgorithmRuntimeTest.java +++ b/src/test/java/it/unibz/inf/isochrone/network/AlgorithmRuntimeTest.java @@ -1,5 +1,7 @@ package it.unibz.inf.isochrone.network; +import com.google.common.base.Charsets; + import it.unibz.inf.isochrone.algorithm.Isochrone; import it.unibz.inf.isochrone.algorithm.MDijkstra; import it.unibz.inf.isochrone.algorithm.MineX; @@ -38,6 +40,8 @@ import org.testng.annotations.Test; public final class AlgorithmRuntimeTest { private static final Logger LOGGER = LoggerFactory.getLogger(AlgorithmRuntimeTest.class); private static final int REPEAT_COUNT = 5; + private static final String RESULTFILE_ENCODING = Charsets.UTF_8.toString(); + private static final String RESULTFILE_CSV_RUNTIME = "build/reports/tests/algorithm-runtimes.csv"; private static final String RESULTFILE_XML_RUNTIME = "build/reports/tests/algorithm-runtimes.xml"; private static final Direction DIRECTION = Direction.INCOMING; private static final Mode MODE = Mode.MULTIMODAL; @@ -106,9 +110,9 @@ public final class AlgorithmRuntimeTest { // Public static methods @AfterClass - public static void writeRuntimeXML() { - final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet(); - writeMapToXML(new File(RESULTFILE_XML_RUNTIME), resultSet, REPEAT_COUNT); + public static void writeRuntimes() { + writeRuntimeXML(); + writeRuntimeCSV(); } @BeforeClass @@ -211,7 +215,7 @@ public final class AlgorithmRuntimeTest { private static void addRuntimeEntry(final String time, final String algorithm, final long runtime) { if (!runtimes.containsKey(time)) { - runtimes.put(time, new HashMap<String, Long>()); + runtimes.put(time, new LinkedHashMap<String, Long>()); } final Map<String, Long> algorithmMap = runtimes.get(time); @@ -223,11 +227,50 @@ public final class AlgorithmRuntimeTest { } } + private static void writeMapToCSV(final File file, final Set<Entry<String, Map<String, Long>>> resultSet, final int repeatCount) { + BufferedWriter fw = null; + try { + fw = new BufferedWriter(new PrintWriter(file, RESULTFILE_ENCODING)); + boolean isFirstLine = true; + for (Entry<String, Map<String, Long>> runtimeEntry : resultSet) { + final String time = runtimeEntry.getKey(); + final Map<String, Long> results = runtimeEntry.getValue(); + if (isFirstLine) { + fw.write("Runtime;"); + final Set<String> algorithms = results.keySet(); + for (String algorithmName : algorithms) { + fw.write(algorithmName + ";"); + } + fw.newLine(); + isFirstLine = false; + } + + fw.write(time + ";"); + final Set<Entry<String, Long>> timeSet = results.entrySet(); + for (Entry<String, Long> entry : timeSet) { + fw.write((entry.getValue().longValue() / repeatCount) + ";"); + } + fw.newLine(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fw != null) { + try { + fw.flush(); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + private static void writeMapToXML(final File file, final Set<Entry<String, Map<String, Long>>> resultSet, final int repeatCount) { BufferedWriter fw = null; try { - fw = new BufferedWriter(new PrintWriter(file, "UTF-8")); - fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); + fw = new BufferedWriter(new PrintWriter(file, RESULTFILE_ENCODING)); + fw.write("<?xml version=\"1.0\" encoding=\"" + RESULTFILE_ENCODING + "\"?>"); fw.newLine(); fw.write("<results numberOfRuns=\"" + repeatCount + "\">"); fw.newLine(); @@ -262,4 +305,14 @@ public final class AlgorithmRuntimeTest { } } + private static void writeRuntimeCSV() { + final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet(); + writeMapToCSV(new File(RESULTFILE_CSV_RUNTIME), resultSet, REPEAT_COUNT); + } + + private static void writeRuntimeXML() { + final Set<Entry<String, Map<String, Long>>> resultSet = runtimes.entrySet(); + writeMapToXML(new File(RESULTFILE_XML_RUNTIME), resultSet, REPEAT_COUNT); + } + }