Commit a1ebdc32 authored by Daniel Seemaier's avatar Daniel Seemaier

added some simple test cases to test infrastructure

Added a weird comment test case

fixed Eratosthenes test case

Refactoring of test names

added empty test case

added a lexer test case that is only comments

fixed typo in test case

Added unclosed comment test

Added a tasty pi test

Removed redundant tests

Added weird operators test case

added another test case
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<ParEpLog>, graphs: Array<String>, k: Int, allowedNumberOfCores: Array<Int>, 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<String>, graphs: Array<String>, ks: Array<Int>, 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<Point>()
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<String>, graphs: Array<String>, ks: Array<Int>, filename: String) {
println(string)
data class Point(val algorithm: String, val x: Double, val y: Double)
val points = ArrayList<Point>()
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<String>, graphs: Array<String>, ks: Array<Int>, filename: String, aspect: (Log) -> Double) {
println(string)
val performanceValues = HashMap<String, MutableList<Double>>().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<String, ArrayList<Double>>()
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
identifier fun
identifier generateScalingPlot
(
identifier logs
:
identifier List
<
identifier ParEpLog
>
,
identifier graphs
:
identifier Array
<
identifier String
>
,
identifier k
:
identifier Int
,
identifier allowedNumberOfCores
:
identifier Array
<
identifier Int
>
,
identifier filename
:
identifier String
,
identifier aspect
:
(
identifier ParEpLog
)
-
>
identifier Double
)
{
identifier println
(
identifier string
)
identifier val
identifier filtered
=
identifier logs
.
identifier filter
{
identifier it
.
identifier graphName
identifier in
identifier graphs
&&
identifier it
.
identifier numberOfCores
identifier in
identifier allowedNumberOfCores
&&
identifier it
.
identifier k
==
identifier k
}
identifier val
identifier runtimes
=
identifier filtered
.
identifier groupBy
{
identifier Pair
(
identifier it
.
identifier graphName
,
identifier it
.
identifier numberOfCores
)
}
.
identifier mapValues
{
(
identifier _
,
identifier values
)
-
>
identifier values
.
identifier map
(
identifier aspect
)
.
identifier average
(
)
}
identifier File
(
identifier filename
)
.
identifier bufferedWriter
(
)
.
identifier use
{
for
(
identifier graph
identifier in
identifier graphs
)
{
for
(
identifier numberOfCores
identifier in
identifier allowedNumberOfCores
)
{
identifier val
identifier key
=
identifier Pair
(
identifier graph
,
identifier numberOfCores
)
identifier val
identifier runtime
=
identifier runtimes
[
identifier key
]
if
(
identifier runtime
!=
null
)
{
identifier it
.
identifier write
(
identifier string_string_string
)
}
else
{
identifier println
(
identifier string
)
}
}
}
}
}
identifier fun
identifier generateTwoPlots
(
identifier db
:
identifier Db
,
identifier algorithms
:
identifier Array
<
identifier String
>
,
identifier graphs
:
identifier Array
<
identifier String
>
,
identifier ks
:
identifier Array
<
identifier Int
>
,
identifier filename
:
identifier String
,
identifier aspect
:
(
identifier Log
)
-
>
identifier Double
)
{
identifier println
(
identifier string
)
identifier val
identifier filtered
=
identifier db
.
identifier filter
{
identifier it
.
identifier algorithm
identifier in
identifier algorithms
&&
identifier it
.
identifier graphName
identifier in
identifier graphs
&&
identifier it
.
identifier k
identifier in
identifier ks
}
identifier data
class
identifier Point
(
identifier val
identifier algorithm
:
identifier String
,
identifier val
identifier x
:
identifier Int
,
identifier val
identifier y
:
identifier Double
)
identifier val
identifier points
=
identifier ArrayList
<
identifier Point
>
(
)
identifier val
identifier instanceNames
=
identifier graphs
.
identifier flatMap
{
identifier graph
-
>
identifier ks
.
identifier map
{
identifier k
-
>
identifier Pair
(
identifier graph