Commit a1ebdc32 by Daniel Seemaier

added some simple test cases to test infrastructure

```Added a weird comment test case

fixed Eratosthenes test case

Refactoring of test names

fixed typo in test case

Removed redundant tests

parent 1fbee7c0
 class Eratosthenes { /** * @param max a positive integer. * @returns a sorted array of all prime numbers between 1 and max (exclusive). */ public int[] primes(int max) { boolean[] sieve = new boolean[max]; int count = 0; /* Initialize array. */ { sieve[0] = false; sieve[1] = false; int i = 2; while (i < max) { sieve[i] = true; i = i + 1; } } /* Sieve of Eratosthenes algorithm. */ { int prime = 2; while (prime < max) { if (sieve[prime]) { count = count + 1; /* Deliberately unoptimized (strength reduction is possible). */ int mult = prime; while (prime * mult < max) { sieve[prime * mult] = false; mult = mult + 1; } } prime = prime + 1; } } int[] result = new int[count]; { int i = 0; int j = 0; while (i < max) { if (sieve[i]) { result[j] = sieve[i]; j = j + 1; } i = i + 1; } } return result; } public static void main(String[] args) { Eratosthenes e = new Eratosthenes(); int num = System.in.read(); e.sieve(num); } } \ No newline at end of file
 class identifier Eratosthenes { public int [ ] identifier primes ( int identifier max ) { boolean [ ] identifier sieve = new boolean [ identifier max ] ; int identifier count = integer literal 0 ; { identifier sieve [ integer literal 0 ] = false ; identifier sieve [ integer literal 1 ] = false ; int identifier i = integer literal 2 ; while ( identifier i < identifier max ) { identifier sieve [ identifier i ] = true ; identifier i = identifier i + integer literal 1 ; } } { int identifier prime = integer literal 2 ; while ( identifier prime < identifier max ) { if ( identifier sieve [ identifier prime ] ) { identifier count = identifier count + integer literal 1 ; int identifier mult = identifier prime ; while ( identifier prime * identifier mult < identifier max ) { identifier sieve [ identifier prime * identifier mult ] = false ; identifier mult = identifier mult + integer literal 1 ; } } identifier prime = identifier prime + integer literal 1 ; } } int [ ] identifier result = new int [ identifier count ] ; { int identifier i = integer literal 0 ; int identifier j = integer literal 0 ; while ( identifier i < identifier max ) { if ( identifier sieve [ identifier i ] ) { identifier result [ identifier j ] = identifier sieve [ identifier i ] ; identifier j = identifier j + integer literal 1 ; } identifier i = identifier i + integer literal 1 ; } } return identifier result ; } public static void identifier main ( identifier String [ ] identifier args ) { identifier Eratosthenes identifier e = new identifier Eratosthenes ( ) ; int identifier num = identifier System . identifier in . identifier read ( ) ; identifier e . identifier sieve ( identifier num ) ; } } EOF \ No newline at end of file
 fun generateScalingPlot(logs: List, graphs: Array, k: Int, allowedNumberOfCores: Array, filename: String, aspect: (ParEpLog) -> Double) { println(string) val filtered = logs.filter { it.graphName in graphs && it.numberOfCores in allowedNumberOfCores && it.k == k } val runtimes = filtered.groupBy { Pair(it.graphName, it.numberOfCores) } .mapValues { (_, values) -> values.map(aspect).average() } File(filename).bufferedWriter().use { for (graph in graphs) { for (numberOfCores in allowedNumberOfCores) { val key = Pair(graph, numberOfCores) val runtime = runtimes[key] if (runtime != null) { it.write(string_string_string) } else { println(string) } } } } } fun generateTwoPlots(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String, aspect: (Log) -> Double) { println(string) val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } data class Point(val algorithm: String, val x: Int, val y: Double) val points = ArrayList() val instanceNames = graphs .flatMap { graph -> ks.map { k -> Pair(graph, k) } } .sortedBy { (graph, k) -> dimensions[graph]!![string]!! } var x = 0 for ((graph, k) in instanceNames) { val instances = filtered .filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } val values = instances.mapValues { (_, values) -> values.map(aspect).average() } for (algorithm in algorithms) { points.add(Point(algorithm, x, values[algorithm]!!)) } ++x } File(filename).bufferedWriter().use { for ((algorithm, x, y) in points) { it.write(string) it.newLine() } } } fun generateSinglePlot(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String) { println(string) data class Point(val algorithm: String, val x: Double, val y: Double) val points = ArrayList() val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } for (graph in graphs) { for (k in ks) { val instances = filtered .filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } val cuts = instances.mapValues { (_, values) -> values.map { it.vertexCut }.average() } val bestCut = cuts.map { (_, cut) -> cut }.min() as Double val runtimes = instances.mapValues { (_, values) -> values.map { it.time }.average() } val bestRuntime = runtimes.map { (_, runtime) -> runtime }.min() as Double for (algorithm in algorithms) { val cut = cuts[algorithm] if (cut == null) { println(string) continue } val runtime = runtimes[algorithm]!! points.add(Point(algorithm, runtime / bestRuntime, 1 - (bestCut / cut))) } } } File(filename).bufferedWriter().use { for ((algorithm, x, y) in points) { it.write(string) it.newLine() } } } fun generatePerformancePlot(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String, aspect: (Log) -> Double) { println(string) val performanceValues = HashMap>().apply { algorithms.forEach { this/*@*/apply[it] = ArrayList() } } val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } for (graph in graphs) { for (k in ks) { val values = filtered.filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } .mapValues { (_, values) -> values.map(aspect).average() } val best = values.map { (_, average) -> average }.min() if (best == null) { println(string) continue } for (algorithm in algorithms) { val value = values[algorithm] if (value != null) { if (value == 0.0) { throw Exception(string) } performanceValues[algorithm]!!.add(1.0 - best / value) if (algorithm in arrayOf(string)) { println(string) } } else { performanceValues[algorithm]!!.add(1.0) } } } } performanceValues.forEach { (_, values) -> values.sortDescending() } File(filename).bufferedWriter().use { writer -> for (algorithm in algorithms) { var i = 1 performanceValues[algorithm]?.forEach { writer.write(string) writer.newLine() ++i } } } } class PerformancePlotGenerator { private val records = HashMap>() fun add(algorithm: String, performance: Double) = records.getOrPut(algorithm) { ArrayList() }.add(performance) fun generate(writer: Writer) { val (maxLengthAlgorithm, maxLength) = records .mapValues { (_, v) -> v.size } .maxBy { (_, v) -> v }!! val (minLengthAlgorithm, minLength) = records .mapValues { (_, v) -> v.size } .minBy { (_, v) -> v }!! if (minLength != maxLength) { println(string) } for (i in 0 until maxLength) { val notNull = records.filter { (_, v) -> v.size > i } val best = notNull.map { (_, v) -> v[i] }.min()!! val values = notNull.mapValues { (_, v) -> 1.0 - best / v[i] } values.forEach { (k, v) -> records[k]?.let { it[i] = v } } } records.forEach { (_, v) -> v.sort() } for (i in 0 until maxLength) { val notNull = records.filter { (_, v) -> v.size > i } val values = notNull.mapValues { (_, v) -> v[i] } values.forEach { (k, v) -> writer.write(string) } } } } \ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
 int varia/* This is a comment */ble = 666; in/*This is comment 2*/t variable = 666; publi/*This is comment 3*/c int variable = 666; int variable = 66/*This is a comment 3*/6; \ No newline at end of file
 int identifier varia identifier ble = integer literal 666 ; identifier in identifier t identifier variable = integer literal 666 ; identifier publi identifier c int identifier variable = integer literal 666 ; int identifier variable = integer literal 66 integer literal 6 ; EOF \ No newline at end of file
This diff is collapsed.
This diff is collapsed.
 >>>>>>>>>>; >>>>>; -=; +/*---*/= +=; >>>==; \ No newline at end of file
 >>> >>> >>> > ; >>> >> ; -= ; + = += ; >>>= = ; EOF \ No newline at end of file
 int a = 666; /* This is a bad comment \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!