Merge boxWithStdlib testData into box, delete BoxWithStdlib test
This commit is contained in:
committed by
Alexander Udalov
parent
22bfc9786a
commit
06a67e6602
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R?, block : (R?) -> T) : T {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1L, foo(1) { x -> x!!.toLong() })
|
||||
assertEquals(1.toShort(), foo(1) { x -> x!!.toShort() })
|
||||
assertEquals(1.toByte(), foo(1L) { x -> x!!.toByte() })
|
||||
assertEquals(1.toShort(), foo(1L) { x -> x!!.toShort() })
|
||||
assertEquals('a'.toDouble(), foo('a') { x -> x!!.toDouble() })
|
||||
assertEquals(1.0.toByte(), foo(1.0) { x -> x!!.toByte() })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R, y : R, block : (R) -> T) : T {
|
||||
val a = x is Number
|
||||
val b = x is Object
|
||||
|
||||
val b1 = x as Object
|
||||
|
||||
if (a && b) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, foo(1, 2) { x -> x as Int })
|
||||
assertEquals("def", foo("abc", "def") { x -> x as String })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box() : String {
|
||||
val x = LongArray(5)
|
||||
for (i in 0..4) {
|
||||
x[i] = (i + 1).toLong()
|
||||
}
|
||||
|
||||
assertEquals(15L, x.fold(0L) { x, y -> x + y })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val result = (1..5).fold(0) { x, y -> x + y }
|
||||
|
||||
assertEquals(15, result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun test1() {
|
||||
val u = when (true) {
|
||||
true -> 42
|
||||
else -> 1.0
|
||||
}
|
||||
|
||||
assertEquals(42, u)
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
val u = 1L.let {
|
||||
when (it) {
|
||||
is Long -> if (it.toLong() == 2L) it.toLong() else it * 2L // CompilationException
|
||||
else -> it.toDouble()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(2L, u)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test1()
|
||||
test2()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun checkLongAB5E(x: Long) = assertEquals(0xAB5EL, x)
|
||||
fun checkDouble1(y: Double) = assertEquals(1.0, y)
|
||||
fun checkByte10(z: Byte) = assertEquals(10.toByte(), z)
|
||||
|
||||
fun box(): String {
|
||||
val x = java.lang.Long.valueOf("AB5E", 16)
|
||||
checkLongAB5E(x)
|
||||
|
||||
val y = java.lang.Double.valueOf("1.0")
|
||||
checkDouble1(y)
|
||||
|
||||
val z = java.lang.Byte.valueOf("A", 16)
|
||||
checkByte10(z)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val x = (10L..50).map { it * 40L }
|
||||
assertEquals(400L, x.first())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R?, y : R?, block : (R?) -> T) : T {
|
||||
if (x == null) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(3, foo(1, 2) { x -> if (x != null) 3 else 4 })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box() : String {
|
||||
|
||||
val result1 = (1..100).count { x -> x % 2 == 0 }
|
||||
val result2 = (1..100).filter { x -> x % 2 == 0 }.size
|
||||
assertEquals(result1, 50)
|
||||
assertEquals(result2, 50)
|
||||
|
||||
val result3 = (1..100).map { x -> 2 * x }.count { x -> x % 2 == 0 }
|
||||
val result4 = (1..100).map { x -> 2 * x }.filter { x -> x % 2 == 0 }.size
|
||||
assertEquals(result3, 100)
|
||||
assertEquals(result4, 100)
|
||||
|
||||
val result5 = (1L..100L).count { x -> x % 2 == 0L }
|
||||
val result6 = (1L..100L).filter { x -> x % 2 == 0L }.size
|
||||
assertEquals(result5, 50)
|
||||
assertEquals(result6, 50)
|
||||
|
||||
val result7 = (1L..100L).map { x -> 2 * x }.count { x -> x % 2 == 0L }
|
||||
val result8 = (1L..100L).map { x -> 2 * x }.filter { x -> x % 2 == 0L }.size
|
||||
assertEquals(result7, 100)
|
||||
assertEquals(result8, 100)
|
||||
|
||||
val result9 = (0..10).reduce { total, next -> total + next }
|
||||
val result10 = (0L..10L).reduce { total, next -> total + next }
|
||||
assertEquals(result9, 55)
|
||||
assertEquals(result10, 55L)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A(val x : Int, val y : A?)
|
||||
|
||||
fun check(a : A?) : Int {
|
||||
return a?.y?.x ?: (a?.x ?: 3)
|
||||
}
|
||||
|
||||
fun checkLeftAssoc(a : A?) : Int {
|
||||
return (a?.y?.x ?: a?.x) ?: 3
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a1 = A(2, A(1, null))
|
||||
val a2 = A(2, null)
|
||||
val a3 = null
|
||||
|
||||
assertEquals(1, check(a1))
|
||||
assertEquals(2, check(a2))
|
||||
assertEquals(3, check(a3))
|
||||
|
||||
assertEquals(1, checkLeftAssoc(a1))
|
||||
assertEquals(2, checkLeftAssoc(a2))
|
||||
assertEquals(3, checkLeftAssoc(a3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R> foo(x : R, block : (R) -> R) : R {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val result = foo(1) { x -> x + 1 }
|
||||
assertEquals(2, result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
if (1 == 1) {
|
||||
val x: Int? = 1
|
||||
result += x!!
|
||||
}
|
||||
|
||||
assertEquals(1, result)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun returningBoxed() : Int? = 1
|
||||
fun acceptingBoxed(x : Int?) : Int ? = x
|
||||
|
||||
class A(var x : Int? = null)
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, returningBoxed())
|
||||
assertEquals(1, acceptingBoxed(1))
|
||||
|
||||
val a = A()
|
||||
a.x = 1
|
||||
assertEquals(1, a.x)
|
||||
|
||||
val b = Array<Int?>(1, { null })
|
||||
b[0] = 1
|
||||
assertEquals(1, b[0])
|
||||
|
||||
val x: Int? = 1
|
||||
assertEquals(1, x!!.hashCode())
|
||||
|
||||
val y: Int? = 1000
|
||||
val z: Int? = 1000
|
||||
val res = y === z
|
||||
|
||||
val c1: Any = if (1 == 1) 0 else "abc"
|
||||
val c2: Any = if (1 != 1) 0 else "abc"
|
||||
assertEquals(0, c1)
|
||||
assertEquals("abc", c2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R, block : (R) -> T) : T {
|
||||
var y = x
|
||||
var z = y
|
||||
z = x
|
||||
return block(z)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, foo(1) { x -> x })
|
||||
assertEquals(1f, foo(1f) { x -> x })
|
||||
assertEquals(1L, foo(1L) { x -> x })
|
||||
assertEquals(1.toDouble(), foo(1.toDouble()) { x -> x })
|
||||
assertEquals(1.toShort(), foo(1.toShort()) { x -> x })
|
||||
assertEquals(1.toByte(), foo(1.toByte()) { x -> x })
|
||||
assertEquals('a', foo('a') { x -> x })
|
||||
assertEquals(true, foo(true) { x -> x })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user