Skip to content

Commit 604e4ea

Browse files
committed
cosmetic
1 parent 0ea5cb4 commit 604e4ea

File tree

6 files changed

+36
-83
lines changed

6 files changed

+36
-83
lines changed
Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
import com.sun.tools.javac.Main
21
import org.antlr.Java8Lexer
32
import org.antlr.Java8Parser
43
import org.antlr.v4.runtime.CharStreams
54
import org.antlr.v4.runtime.CommonTokenStream
6-
import org.junit.jupiter.api.Test
5+
import org.junit.jupiter.api.Disabled
76
import java.io.File
87

9-
fun main(args: Array<String>){
8+
fun main(args: Array<String>) {
109
try {
1110
AntlrBenchmark().parse(File(args[0]).readText())
12-
}
13-
catch (e: Throwable){
11+
} catch (e: Throwable) {
1412
println(e)
1513
System.exit(1)
1614
}
1715
}
16+
1817
class AntlrBenchmark : ParsingBenchmarks() {
1918

2019
override fun getShortName(): String = "Antlr"
2120

22-
23-
2421
@Override
2522
override fun parse(text: String) {
2623
var x = 30
27-
while(x-- > 0) {
24+
while (x-- > 0) {
2825
val antlrParser = Java8Parser(
2926
CommonTokenStream(
3027
Java8Lexer(
@@ -40,43 +37,9 @@ class AntlrBenchmark : ParsingBenchmarks() {
4037
}
4138
}
4239

43-
@Test
44-
fun t() {
45-
parse("""/**
46-
* Copyright (c) 2016-present, RxJava Contributors.
47-
*
48-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
49-
* compliance with the License. You may obtain a copy of the License at
50-
*
51-
* http://www.apache.org/licenses/LICENSE-2.0
52-
*
53-
* Unless required by applicable law or agreed to in writing, software distributed under the License is
54-
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
55-
* the License for the specific language governing permissions and limitations under the License.
56-
*/
57-
58-
package io.reactivex.exceptions;
59-
60-
/**
61-
* Wrapper for Throwable errors that are sent to `RxJavaPlugins.onError`.
62-
* <p>History: 2.0.6 - experimental; 2.1 - beta
63-
* @since 2.2
64-
*/
65-
public final class UndeliverableException extends IllegalStateException {
66-
67-
private static final long serialVersionUID = 1644750035281290266L;
68-
69-
/**
70-
* Construct an instance by wrapping the given, non-null
71-
* cause Throwable.
72-
* @param cause the cause, not null
73-
*/
74-
public UndeliverableException(Throwable cause) {
75-
super("The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | " + cause, cause);
76-
}
77-
}""")
40+
@Disabled
41+
fun testOne() {
42+
parse("")
7843
}
79-
80-
8144
}
8245

benchmarks/src/test/kotlin/AntlrFastBenchmark.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import org.junit.jupiter.api.Timeout
1010
import java.io.File
1111
import java.nio.file.Files
1212
import java.nio.file.Path
13-
import kotlin.test.Ignore
1413

15-
fun main(args: Array<String>){
14+
fun main(args: Array<String>) {
1615
try {
1716
AntlrFastBenchmark().parse(File(args[0]).readText())
18-
}
19-
catch (e: Throwable){
17+
} catch (e: Throwable) {
2018
println(e)
2119
System.exit(1)
2220
}
2321
}
24-
class AntlrFastBenchmark: ParsingBenchmarks() {
22+
23+
class AntlrFastBenchmark : ParsingBenchmarks() {
2524

2625
override fun getShortName(): String = "AntlrFast"
2726

28-
fun main(args: Array<String>){
27+
fun main(args: Array<String>) {
2928
parse(File(args[0]).readText())
3029
}
30+
3131
@Override
3232
override fun parse(text: String) {
3333
val antlrParser =
@@ -40,8 +40,7 @@ class AntlrFastBenchmark: ParsingBenchmarks() {
4040
)
4141
try {
4242
var compilationUnit = antlrParser.compilationUnit()
43-
}
44-
catch (e: Exception){
43+
} catch (e: Exception) {
4544
print(e)
4645
}
4746
}
@@ -58,6 +57,7 @@ class AntlrFastBenchmark: ParsingBenchmarks() {
5857

5958
var sum_count: Int = 0
6059
val fileName = "tokens_count.csv"
60+
6161
@TestFactory
6262
@Timeout(100)
6363
fun getTokensCount(): Collection<DynamicTest> {

benchmarks/src/test/kotlin/OfflineUcfsBenchmark.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import org.ucfs.input.LinearInputLabel
22
import java.io.File
33

4-
fun main(args: Array<String>){
4+
fun main(args: Array<String>) {
55
try {
66
OfflineUcfsBenchmark().parse(File(args[0]).readText())
7-
}
8-
catch (e: Throwable){
7+
} catch (e: Throwable) {
98
println(e)
109
System.exit(1)
1110
}
1211
}
12+
1313
class OfflineUcfsBenchmark : ParsingBenchmarks() {
1414
override fun getShortName(): String = "UcfsOff"
1515

16-
fun main(args: Array<String>){
16+
fun main(args: Array<String>) {
1717
parse(File(args[0]).readText())
1818
}
19+
1920
override fun parse(text: String) {
2021
val parser = org.ucfs.Java8Parser<Int, LinearInputLabel>()
2122
parser.setInput(getTokenStream(text))

benchmarks/src/test/kotlin/OnlineUcfsBenchmark.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
import org.junit.jupiter.api.Test
31
import org.ucfs.Java8
42
import org.ucfs.parser.Gll
53
import org.ucfs.sppf.writeSppfToDot
@@ -16,14 +14,13 @@ class OnlineUcfsBenchmark : ParsingBenchmarks() {
1614
}
1715

1816

19-
// @Test
2017
fun parseOne() {
2118
val startState = Java8().rsm
2219
val tokens = getTokenStream(sourceCode)
2320
val gll = Gll.gll(startState, tokens)
2421
val sppf = gll.parse().first
25-
assert(sppf != null){ "can't build sppf" }
26-
writeSppfToDot(sppf!!, "beeb.dot")
22+
assert(sppf != null) { "can't build sppf" }
23+
writeSppfToDot(sppf!!, "sppf.dot")
2724
}
2825

2926
val sourceCode: String =

benchmarks/src/test/kotlin/ParsingBenchmarks.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import org.junit.jupiter.api.Assertions
2-
import org.junit.jupiter.api.DynamicTest
1+
import org.junit.jupiter.api.*
32
import org.junit.jupiter.api.DynamicTest.dynamicTest
4-
import org.junit.jupiter.api.TestFactory
5-
import org.junit.jupiter.api.Timeout
63
import java.io.File
74
import java.nio.file.Files
85
import java.nio.file.Path
@@ -19,10 +16,9 @@ abstract class ParsingBenchmarks {
1916
private val timePerTestCase: Long = 400
2017
private val repeatCount: Int = 10
2118
lateinit var file: File
22-
// rxjava-2-2-2
23-
// junit-4-12
19+
2420
val datasetName = "junit-4-12"
25-
//val datasetName = "rxjava-2-2-2"
21+
//val datasetName = "rxjava-2-2-2"
2622

2723
val resourceFolder: Path = Path.of("java", "correct", datasetName)
2824
private lateinit var csvFileName: String
@@ -47,7 +43,7 @@ abstract class ParsingBenchmarks {
4743
private fun getHeapSize(): Long = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()
4844

4945
private fun getPrintableHeapSize(heapSize: Long? = null): String {
50-
return String.format("%.2f", (heapSize ?: getHeapSize()) * 1.0/ memoryDivider)
46+
return String.format("%.2f", (heapSize ?: getHeapSize()) * 1.0 / memoryDivider)
5147
.trimEnd('0').trimEnd('.')
5248
}
5349

@@ -75,8 +71,7 @@ abstract class ParsingBenchmarks {
7571
} catch (e: Exception) {
7672
report(fileName, e.javaClass.name, getPrintableHeapSize())
7773
assert(false) { e.toString() }
78-
}
79-
catch (e : OutOfMemoryError){
74+
} catch (e: OutOfMemoryError) {
8075
System.gc()
8176
report(fileName, e.javaClass.name, "OOM")
8277
}
@@ -100,6 +95,8 @@ abstract class ParsingBenchmarks {
10095
return Path.of(res.toURI())
10196
}
10297

98+
// Disable for running on CI
99+
@Disabled
103100
@TestFactory
104101
@Timeout(100)
105102
fun timeTest(): Collection<DynamicTest> {
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
21
import org.junit.jupiter.api.Test
3-
import org.ucfs.Java8
42
import org.ucfs.input.IInputGraph
53
import org.ucfs.input.LinearInput
64
import org.ucfs.input.LinearInputLabel
@@ -12,10 +10,11 @@ import org.ucfs.sppf.writeSppfToDot
1210
import kotlin.test.Ignore
1311

1412
@Ignore
15-
class SimpleUcfsCorrect{
13+
class SimpleUcfsCorrect {
1614
val grammar = SimpleGrammar()
15+
1716
@Test
18-
fun parseOne(){
17+
fun parseOne() {
1918
val startState = grammar.rsm
2019
val tokens = getTokenStream(sourceCode)
2120
val gll = Gll.gll(startState, tokens)
@@ -27,22 +26,18 @@ class SimpleUcfsCorrect{
2726

2827

2928
fun getTokenStream(input: List<Term<String>>): IInputGraph<Int, LinearInputLabel> {
30-
val inputGraph = LinearInput<Int, LinearInputLabel>()
29+
val inputGraph = LinearInput<Int, LinearInputLabel>()
3130
var vertexId = 1
3231

3332
inputGraph.addVertex(vertexId)
3433
inputGraph.addStartVertex(vertexId)
35-
for(term in input) {
34+
for (term in input) {
3635
inputGraph.addEdge(vertexId, LinearInputLabel(term), ++vertexId)
3736
}
3837

3938
return inputGraph
4039
}
4140

4241
val sourceCode: List<Term<String>>
43-
// compilationUnit /= Option(packageDeclaration) * Many(importDeclaration) * Many(typeDeclaration)
44-
//get() = listOf(grammar.b, grammar.a, grammar.a, grammar.b, grammar.b)
45-
46-
get() = listOf(grammar.c, grammar.c)
47-
// get() = listOf(grammar.a, grammar.a, grammar.c, grammar.b)
42+
get() = listOf(grammar.c, grammar.c)
4843
}

0 commit comments

Comments
 (0)