SyntheticBenchmarkTracePrinterTest.kt 5.33 KB
Newer Older
1
2
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
3
import se.lth.cs.SyntheticBenchmarkTracePrinter
Noric Couderc's avatar
Noric Couderc committed
4
import se.lth.cs.bcgen.BCBenchmarkPackage
5
6
7
import java.io.StringWriter

class SyntheticBenchmarkTracePrinterTest {
8

Noric Couderc's avatar
Noric Couderc committed
9
    val methodOutputFormat : String = "JAVA-STANDARD-FORMAT"
10

11
12
    @Test
    fun testEmptySynthBenchmark() {
13
        val benchmark = BCBenchmarkPackage.MAP(0, 0, 0, HashMap<Any, Any>())
14
15

        val writer = StringWriter()
16
        val csvPrinter = SyntheticBenchmarkTracePrinter(writer, methodOutputFormat)
17

Noric Couderc's avatar
Noric Couderc committed
18
        csvPrinter.printToCSV(listOf<BCBenchmarkPackage<*>>(benchmark))
19
        Assertions.assertEquals(
20
                "benchmark_id,seed,size,base_structure_size,data_structure,method,step\n", writer.toString())
21
22
23
24
    }

    @Test
    fun testSynthesizedBenchmark() {
25
        val benchmark = BCBenchmarkPackage.MAP(0, 10, 0, HashMap<Any, Any>())
26
27

        val writer = StringWriter()
28
        val csvPrinter = SyntheticBenchmarkTracePrinter(writer, methodOutputFormat)
29

Noric Couderc's avatar
Noric Couderc committed
30
        csvPrinter.printToCSV(listOf<BCBenchmarkPackage<*>>(benchmark))
31

32
    	val expected =
33
				("benchmark_id,seed,size,base_structure_size,data_structure,method,step\n" +
34
35
36
37
38
39
40
41
42
43
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,clear(),0\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,size(),1\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsValue(java.lang.Object),2\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",3\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,keySet(),4\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",5\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsKey(java.lang.Object),6\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,remove(int),7\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsValue(java.lang.Object),8\n" +
				"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",9\n")
44

45
        Assertions.assertEquals(expected, writer.toString())
46
47
    }

48
49
    @Test
    fun testSynthesizedBenchmark1() {
50
        val benchmark = BCBenchmarkPackage.MAP(0, 10, 0, HashMap<Any, Any>())
51
52
53
54

        val writer = StringWriter()
        val csvPrinter = SyntheticBenchmarkTracePrinter(writer, "SYNTHETIC-RUN-FORMAT")

Noric Couderc's avatar
Noric Couderc committed
55
        csvPrinter.printToCSV(listOf<BCBenchmarkPackage<*>>(benchmark))
56

57
58
    	val expected =
    	    ("benchmark_id,seed,size,base_structure_size,data_structure,method,step\n" +
59
60
61
62
63
64
65
66
67
68
			"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runClear,0\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runSize,1\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runContainsValue,2\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runPut,3\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runKeySet,4\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runPut,5\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runContainsKey,6\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runRemove2,7\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runContainsValue,8\n" +
		    "Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,runPut,9\n")
69

70
        Assertions.assertEquals(expected, writer.toString())
71
72
    }

73
74
    @Test
    fun testSynthesizedBenchmarkList() {
75
        val benchmarks = listOf<BCBenchmarkPackage<*>>(
76
77
                BCBenchmarkPackage.MAP(0, 10, 0, HashMap<Any, Any>()),
                BCBenchmarkPackage.MAP(1, 10, 0, HashMap<Any, Any>())
78
79
80
        )

        val writer = StringWriter()
81
        val csvPrinter = SyntheticBenchmarkTracePrinter(writer, methodOutputFormat)
82

Noric Couderc's avatar
Noric Couderc committed
83
        csvPrinter.printToCSV(benchmarks)
84

Christoph Reichenbach's avatar
Christoph Reichenbach committed
85
86
	val expected =
		("benchmark_id,seed,size,base_structure_size,data_structure,method,step\n" +
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,clear(),0\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,size(),1\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsValue(java.lang.Object),2\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",3\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,keySet(),4\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",5\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsKey(java.lang.Object),6\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,remove(int),7\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,containsValue(java.lang.Object),8\n" +
		"Synth:POLYA:0:10:Map:0:HashMap,0,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",9\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,clear(),0\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,clear(),1\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,keySet(),2\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,size(),3\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,clear(),4\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,containsKey(java.lang.Object),5\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",6\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,\"put(java.lang.Object,java.lang.Object)\",7\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,toString(),8\n" +
		"Synth:POLYA:1:10:Map:0:HashMap,1,10,0,HashMap,containsKey(java.lang.Object),9\n")
107

108
        Assertions.assertEquals(expected, writer.toString())
109
    }
110
}