Move ir box test under "box/ir"
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) {
|
||||
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
|
||||
}
|
||||
}
|
||||
|
||||
class Test(val x: Int) {
|
||||
val y = x + 1
|
||||
val z: Int
|
||||
init {
|
||||
z = y + 1
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test(1)
|
||||
assertEquals(test.x, 1)
|
||||
assertEquals(test.y, 2)
|
||||
assertEquals(test.z, 3)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun foo(x: String): String {
|
||||
fun bar(y: String) = x + y
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = foo("O")
|
||||
@@ -0,0 +1,8 @@
|
||||
fun <X : Any> foo(x: X): String {
|
||||
fun <Y : Any> bar(y: Y) =
|
||||
x.toString() + y.toString()
|
||||
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = foo("O")
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(x: String): String {
|
||||
fun bar(y: String): String {
|
||||
fun qux(z: String): String =
|
||||
x + y + z
|
||||
return qux("")
|
||||
}
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
foo("O")
|
||||
@@ -0,0 +1,6 @@
|
||||
fun String.foo(): String {
|
||||
fun bar(y: String) = this + y
|
||||
return bar("K")
|
||||
}
|
||||
|
||||
fun box() = "O".foo()
|
||||
@@ -0,0 +1,8 @@
|
||||
class Outer {
|
||||
val x = "O"
|
||||
inner class Inner {
|
||||
val y = x + "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer().Inner().y
|
||||
@@ -0,0 +1,7 @@
|
||||
class Outer(val x: String) {
|
||||
inner class Inner(val y: String) {
|
||||
val z = x + y
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Outer("O").Inner("K").z
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
var result = ""
|
||||
fun add(s: String) {
|
||||
result += s
|
||||
}
|
||||
add("O")
|
||||
add("K")
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
fun testBoolean(v: Boolean): Boolean {
|
||||
var value = false
|
||||
fun setValue(v: Boolean) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testChar(v: Char): Char {
|
||||
var value = 0.toChar()
|
||||
fun setValue(v: Char) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testByte(v: Byte): Byte {
|
||||
var value = 0.toByte()
|
||||
fun setValue(v: Byte) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testShort(v: Short): Short {
|
||||
var value = 0.toShort()
|
||||
fun setValue(v: Short) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testInt(v: Int): Int {
|
||||
var value = 0.toInt()
|
||||
fun setValue(v: Int) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testLong(v: Long): Long {
|
||||
var value = 0.toLong()
|
||||
fun setValue(v: Long) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testFloat(v: Float): Float {
|
||||
var value = 0.toFloat()
|
||||
fun setValue(v: Float) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun testDouble(v: Double): Double {
|
||||
var value = 0.toDouble()
|
||||
fun setValue(v: Double) {
|
||||
value = v
|
||||
}
|
||||
setValue(v)
|
||||
return value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when {
|
||||
testBoolean(true) != true -> "testBoolean"
|
||||
testChar('a') != 'a' -> "testChar"
|
||||
testByte(1) != 1.toByte() -> "testByte"
|
||||
testShort(1) != 1.toShort() -> "testShort"
|
||||
testInt(1) != 1 -> "testInt"
|
||||
testLong(1) != 1L -> "testLong"
|
||||
testFloat(1.0F) != 1.0F -> "testFloat"
|
||||
testDouble(1.0) != 1.0 -> "testDouble"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) {
|
||||
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
|
||||
}
|
||||
}
|
||||
|
||||
enum class Test {
|
||||
OK
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(Test.OK.ordinal, 0)
|
||||
assertEquals(Test.OK.name, "OK")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) {
|
||||
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
|
||||
}
|
||||
}
|
||||
|
||||
enum class TestEnumClass(val x: Int) {
|
||||
ZERO
|
||||
// {
|
||||
// init {
|
||||
// }
|
||||
// }
|
||||
;
|
||||
constructor(): this(0)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(TestEnumClass.ZERO.x, 0)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) {
|
||||
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
|
||||
}
|
||||
}
|
||||
|
||||
enum class TestEnumClass {
|
||||
ZERO {
|
||||
override fun describe() = "nothing"
|
||||
};
|
||||
abstract fun describe(): String
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(TestEnumClass.ZERO.describe(), "nothing")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) {
|
||||
throw java.lang.AssertionError("Assertion failed: $actual != $expected")
|
||||
}
|
||||
}
|
||||
|
||||
val x = 1
|
||||
val y = x + 1
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(x, 1)
|
||||
assertEquals(y, 2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
object Test {
|
||||
val ok = "OK"
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
Test.ok
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
fun ltDD(x: Comparable<Double>, y: Double) =
|
||||
x is Double && x < y
|
||||
|
||||
fun ltCD(x: Comparable<Double>, y: Double) =
|
||||
x < y
|
||||
|
||||
fun box(): String {
|
||||
val Z = 0.0
|
||||
val NZ = -0.0
|
||||
|
||||
if (ltDD(NZ, Z)) return "Fail 1"
|
||||
if (!ltCD(NZ, Z)) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fun eqeq(x: Any, y: Any) =
|
||||
x is Double && y is Double && x == y
|
||||
|
||||
fun anyEqeq(x: Any, y: Any) =
|
||||
x == y
|
||||
|
||||
fun box(): String {
|
||||
val Z = 0.0
|
||||
val NZ = -0.0
|
||||
|
||||
if (!(Z == NZ)) return "Fail 1"
|
||||
if (!eqeq(Z, NZ)) return "Fail 2"
|
||||
|
||||
if (anyEqeq(Z, NZ)) return "Fail A"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
fun eqeq(x: Any, y: Any) =
|
||||
x is Float && y is Float && x == y
|
||||
|
||||
fun anyEqeq(x: Any, y: Any) =
|
||||
x == y
|
||||
|
||||
fun box(): String {
|
||||
val Z = 0.0F
|
||||
val NZ = -0.0F
|
||||
|
||||
if (!(Z == NZ)) return "Fail 1"
|
||||
if (!eqeq(Z, NZ)) return "Fail 2"
|
||||
|
||||
if (anyEqeq(Z, NZ)) return "Fail A"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun ltDI(x: Any, y: Any) =
|
||||
x is Double && y is Int && x < y
|
||||
|
||||
fun box(): String {
|
||||
if (ltDI(-0.0, 0)) return "Fail 1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Test(val ok: String)
|
||||
|
||||
fun box() = Test("OK").ok
|
||||
Reference in New Issue
Block a user