Refactor codegen tests
- initialize environment only once in setUp() - add comments on why some tests are disabled - modify and rename some tests - re-enable now working tests - extract some tests into files with box() - remove useless 'throws' declarations and commented code
This commit is contained in:
committed by
Alexander Udalov
parent
99827d10a8
commit
0df71bd696
@@ -0,0 +1,11 @@
|
||||
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
|
||||
this[index1 + index2] = elem
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = Array<String>(1, { "" })
|
||||
s[1, -1] = "O"
|
||||
s[2, -2] += "K"
|
||||
return s[-3, 3]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
|
||||
this[index1 + index2] = elem
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = Array<String>(1, { "" })
|
||||
s[1, -1] = "OK"
|
||||
return s[-2, 2]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
val s = IntArray(1)
|
||||
s[0] = 5
|
||||
s[0] += 7
|
||||
return if (s[0] == 12) "OK" else "Fail ${s[0]}"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||
this[index1 + index2] = elem
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = ArrayList<String>(1)
|
||||
s.add("")
|
||||
s[1, -1] = "O"
|
||||
s[2, -2] += "K"
|
||||
return s[2, -2]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.ArrayList
|
||||
|
||||
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
|
||||
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
|
||||
this[index1 + index2] = elem
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = ArrayList<String>(1)
|
||||
s.add("")
|
||||
s[1, -1] = "OK"
|
||||
return s[2, -2]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in BooleanArray(5)) {
|
||||
if (x != false) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in ByteArray(5)) {
|
||||
if (x != 0.toByte()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in CharArray(5)) {
|
||||
if (x != 0.toChar()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in DoubleArray(5)) {
|
||||
if (x != 0.toDouble()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in FloatArray(5)) {
|
||||
if (x != 0.toFloat()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in IntArray(5)) {
|
||||
if (x != 0) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in LongArray(5)) {
|
||||
if (x != 0.toLong()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun box(): String {
|
||||
for (x in ShortArray(5)) {
|
||||
if (x != 0.toShort()) return "Fail $x"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.util.HashMap
|
||||
|
||||
fun HashMap<String, Int?>.set(index: String, elem: Int?) {
|
||||
this.put(index, elem)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val s = HashMap<String, Int?>()
|
||||
s["239"] = 239
|
||||
return if (s["239"] == 239) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
val a = Array<Int>(5, {it})
|
||||
val x = a.indices.iterator()
|
||||
while (x.hasNext()) {
|
||||
val i = x.next()
|
||||
if (a[i] != i) return "Fail $i ${a[i]}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
val a = CharArray(5)
|
||||
val x = a.indices.iterator()
|
||||
while (x.hasNext()) {
|
||||
val i = x.next()
|
||||
if (a[i] != 0.toChar()) return "Fail $i ${a[i]}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
val x = Array<Int>(5, { it } ).iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (x.next() != i) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = BooleanArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = ByteArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = ByteArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.nextByte()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = CharArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = DoubleArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = FloatArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = IntArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = LongArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = LongArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.nextLong()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box(): String {
|
||||
val a = ShortArray(5)
|
||||
val x = a.iterator()
|
||||
var i = 0
|
||||
while (x.hasNext()) {
|
||||
if (a[i] != x.next()) return "Fail $i"
|
||||
i++
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
|
||||
fun IntArray.get(index: Long) = this[index.toInt()]
|
||||
|
||||
fun box(): String {
|
||||
var l = IntArray(1)
|
||||
l[0.toLong()] = 4
|
||||
l[0.toLong()] += 6
|
||||
return if (l[0.toLong()] == 10) "OK" else "Fail"
|
||||
}
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
import java.lang.Integer
|
||||
|
||||
open class C {
|
||||
open fun f(): Any = "C f"
|
||||
}
|
||||
@@ -12,12 +12,14 @@ class X {
|
||||
|
||||
fun test() {
|
||||
for (i in C()) {
|
||||
System.out.println(i)
|
||||
foo(i)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
X().test()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ class X {
|
||||
|
||||
fun test() {
|
||||
for (i in C()) {
|
||||
System.out.println(i)
|
||||
foo(i)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
X().test()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ class X {
|
||||
|
||||
fun test() {
|
||||
for (i in C()) {
|
||||
System.out.println(i)
|
||||
foo(i)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
X().test()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ fun box() : String {
|
||||
for (el in b) {
|
||||
sum = sum + (el ?: 0)
|
||||
}
|
||||
System.out?.println(sum)
|
||||
if(sum != 10) return "b failed"
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -4,7 +4,6 @@ fun box() : String {
|
||||
val processors = Runtime.getRuntime()!!.availableProcessors()
|
||||
var threadNum = 1
|
||||
while(threadNum <= 1024) {
|
||||
System.out?.println(threadNum)
|
||||
if(threadNum < 2 * processors)
|
||||
threadNum += 1
|
||||
else
|
||||
|
||||
@@ -34,9 +34,8 @@ fun box() : String {
|
||||
a[2*i+1] = -2*i-1
|
||||
}
|
||||
a.quicksort()
|
||||
for(i in 0..9) {
|
||||
System.out?.print(a[i])
|
||||
System.out?.print(' ')
|
||||
for(i in 0..a.size-2) {
|
||||
if (a[i] > a[i+1]) return "Fail $i: ${a[i]} > ${a[i+1]}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ class C() {
|
||||
|
||||
fun testReceiver() : String {
|
||||
val res : String = "mama".toMyPrefixedString("111", "222")
|
||||
System.out?.println(res)
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun loop(var times : Int) {
|
||||
while(times > 0) {
|
||||
val u : (value : Int) -> Unit = {
|
||||
System.out?.println(it)
|
||||
foo(it)
|
||||
}
|
||||
u(times--)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import A.B.foo
|
||||
import A.B.x
|
||||
|
||||
class A() {
|
||||
class object {
|
||||
class B() {
|
||||
class object {
|
||||
val x = 1
|
||||
fun foo() = "2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = if (x == 1 && foo() == "2") "OK" else "fail"
|
||||
@@ -1,3 +1,6 @@
|
||||
// KT-2148
|
||||
|
||||
|
||||
fun f(p: Int?): Int {
|
||||
return when(p) {
|
||||
null -> 3
|
||||
|
||||
@@ -6,4 +6,13 @@ fun test(a : A) {
|
||||
if (a.method != null) {
|
||||
a.method!!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override val method = { }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(B())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -6,4 +6,13 @@ fun test(a : A) {
|
||||
if (a.method != null) {
|
||||
a.method!!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override val method = { }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(B())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -12,15 +12,14 @@ fun t2() : Boolean {
|
||||
|
||||
fun t3() {
|
||||
val d: D = D("s")
|
||||
System.out?.println(d?.s)
|
||||
System.out?.println(d?.s == "s") //prints true
|
||||
System.out?.println(d) //ok
|
||||
val x = d?.s
|
||||
if (!(d?.s == "s")) throw AssertionError()
|
||||
}
|
||||
|
||||
fun t4() {
|
||||
val e: E? = E()
|
||||
System.out?.println(e?.bar() == e) //verify error
|
||||
System.out?.println(e?.foo()) //verify error
|
||||
if (!(e?.bar() == e)) throw AssertionError()
|
||||
val x = e?.foo()
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import java.util.LinkedList
|
||||
import java.util.ArrayList
|
||||
|
||||
open class BaseStringList: LinkedList<String>() {
|
||||
open class BaseStringList: ArrayList<String>() {
|
||||
}
|
||||
|
||||
class StringList: BaseStringList() {
|
||||
@@ -14,6 +14,6 @@ fun box(): String {
|
||||
myStringList.add("first element")
|
||||
if (myStringList.get(0) != "StringList.get()") return "Fail #1"
|
||||
if ((myStringList: BaseStringList).get(0) != "StringList.get()") return "Fail #2"
|
||||
if ((myStringList: LinkedList<String>).get(0) != "StringList.get()") return "Fail #3"
|
||||
if ((myStringList: ArrayList<String>).get(0) != "StringList.get()") return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package test
|
||||
|
||||
class List<T>(len: Int, cls : java.lang.Class) {
|
||||
val a : Array<T?> = Array<T?>(len)
|
||||
class List<T>(len: Int) {
|
||||
val a = Array<T?>(len) { null }
|
||||
|
||||
fun reverse() {
|
||||
var i = 0
|
||||
@@ -17,19 +15,19 @@ class List<T>(len: Int, cls : java.lang.Class) {
|
||||
fun box() : String {
|
||||
val d = List<Int>(1)
|
||||
d.a[0] = 10
|
||||
println(d.a[0])
|
||||
checkEquals(d.a[0], 10)
|
||||
|
||||
val a = List<String>(1)
|
||||
a.a[0] = "1"
|
||||
println(a.a[0])
|
||||
checkEquals(a.a[0], "1")
|
||||
|
||||
val b = List<Int?>(1)
|
||||
b.a[0] = 10
|
||||
println(b.a[0])
|
||||
checkEquals(b.a[0], 10)
|
||||
|
||||
val c = List<Array<Int>>(1)
|
||||
c.a[0] = Array<Int>(4,{-1})
|
||||
println(c.a[0]?.size)
|
||||
checkEquals(c.a[0]?.size, 4)
|
||||
|
||||
val e = List<Int>(5)
|
||||
e.a[0] = 0
|
||||
@@ -38,12 +36,16 @@ fun box() : String {
|
||||
e.a[3] = 3
|
||||
e.a[4] = 4
|
||||
e.reverse()
|
||||
for(el in e.a)
|
||||
println(el)
|
||||
for (i in 0..4)
|
||||
checkEquals(e.a[i], 4-i)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun println(s : Any?) {
|
||||
System.out?.println(s);
|
||||
fun checkEquals(a: Any?, b: Any?) {
|
||||
if (a != b) throw AssertionError("Expected: $b, actual: $a")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(box())
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ fun box() : String {
|
||||
for (i in vals.indices)
|
||||
for (j in i..vals.lastIndex())
|
||||
diffs.add(vals[i] - vals[j])
|
||||
System.out?.println(diffs.size())
|
||||
val size = diffs.size()
|
||||
|
||||
if (size != 8) return "Fail $size"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import java.util.*
|
||||
|
||||
class Template() {
|
||||
val collected = LinkedList<String>()
|
||||
val collected = ArrayList<String>()
|
||||
|
||||
fun String.plus() {
|
||||
collected.add(this@plus)
|
||||
|
||||
@@ -16,7 +16,9 @@ class N() : M() {
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
n.a
|
||||
n.b
|
||||
n.superb
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ class N() : M {
|
||||
|
||||
fun box(): String {
|
||||
val n = N()
|
||||
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb)
|
||||
n.a
|
||||
n.b
|
||||
n.superb
|
||||
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user