Inline test data structure changed

This commit is contained in:
Mikhael Bogdanov
2014-06-04 15:47:20 +04:00
committed by Michael Bogdanov
parent b37c0d3fff
commit 02c6bdeaa3
115 changed files with 765 additions and 519 deletions
@@ -0,0 +1,23 @@
import test.*
fun test1(s: Long): Boolean {
return doSmth(s)
}
fun test2(s: Int): Boolean {
return doSmth(s)
}
inline fun <T> test3(s: T): Boolean {
return doSmth(s)
}
fun box(): String {
if (!test1(11111.toLong())) return "fail 1"
if (!test2(11111)) return "fail 2"
if (!test3(11111)) return "fail 3.1"
if (!test3("11111")) return "fail 3.2"
if (!test3(11111.3)) return "fail 3.3"
return "OK"
}
@@ -0,0 +1,5 @@
package test
inline fun <T> doSmth(a: T) : Boolean {
return a.identityEquals(a)
}
@@ -0,0 +1,43 @@
import test.*
fun testIf(): String {
if (runIf({it}, 11, 11, 12) != 11) return "testIf 1 test fail"
if (runIf({it}, 11, 1, 12) != 12) return "testIf 2 test fail"
if (runIf({if (it == 11) it else 12}, 11, 11, 0) != 11) return "testIf 3 test fail"
if (runIf({if (it == 11) it else 12}, 11, 1, 0) != 12) return "testIf 4 test fail"
return "OK"
}
fun testIf2(): String {
if (runIf2({it}, 11, 11, 12) != 11) return "testIf2 1 test fail"
if (runIf2({it}, 11, 1, 12) != 12) return "testIf2 2 test fail"
if (runIf2({if (it == 11) it else 12}, 11, 11, 0) != 11) return "testIf2 3 test fail"
if (runIf2({if (it == 11) it else 12}, 11, 1, 0) != 12) return "testIf2 4 test fail"
return "OK"
}
fun testIfElse(): String {
if (runIfElse({it}, 11, 11, 12) != 11) return "testIfElse 1 test fail"
if (runIfElse({it}, 11, 1, 12) != 12) return "testIfElse 2 test fail"
if (runIfElse({if (it == 11) it else 12}, 11, 11, 0) != 11) return "testIfElse 3 test fail"
if (runIfElse({if (it == 11) it else 12}, 11, 1, 0) != 12) return "testIfElse 4 test fail"
return "OK"
}
fun box(): String {
var result = testIf()
if (result != "OK") return "fail1: ${result}"
result = testIf2()
if (result != "OK") return "fail2: ${result}"
result = testIfElse()
if (result != "OK") return "fail2: ${result}"
return "OK"
}
@@ -0,0 +1,25 @@
package test
inline fun <T> runIf(f: (T) -> T, start: T, stop: T, secondStart: T) : T {
if (f(start) == stop) {
return f(start)
}
return f(secondStart)
}
inline fun <T> runIf2(f: (T) -> T, start: T, stop: T, secondStart: T) : T {
val result = f(start)
if (result == stop) {
return result
}
return f(secondStart)
}
inline fun <T> runIfElse(f: (T) -> T, start: T, stop: T, secondStart: T) : T {
if (f(start) == stop) {
return f(start)
} else {
return f(secondStart)
}
}
@@ -0,0 +1,13 @@
fun test1(): Int {
var s = 0;
2.times2 {
s++
}
return s;
}
fun box(): String {
if (test1() != 2) return "test1: ${test1()}"
return "OK"
}
@@ -0,0 +1,7 @@
public inline fun Int.times2(body : () -> Unit) {
var count = this;
while (count > 0) {
body()
count--
}
}
@@ -0,0 +1,18 @@
fun test1(): String {
val inlineX = My()
var d = "";
inlineX.doWork({(z: String) -> d = z; z})
return d
}
fun test2(): Int {
val inlineX = My()
return inlineX.perform({(z: My) -> 11})
}
fun box(): String {
if (test1() != "OK") return "test1: ${test1()}"
if (test2() != 11) return "test1: ${test2()}"
return "OK"
}
@@ -0,0 +1,20 @@
class My
inline fun <T, R> T.perform(job: (T)-> R) : R {
return job(this)
}
inline fun My.someWork(job: (String) -> Any): Unit {
this.perform {
job("OK")
}
}
inline fun My.doWork (closure : (param : String) -> Unit) : Unit {
this.someWork(closure)
}
inline fun My.doPerform (closure : (param : My) -> Int) : Int {
return perform(closure)
}
@@ -0,0 +1,14 @@
import test.*
fun test1(s: Int): Int {
val z = Z(s)
z += {s}
return z.s
}
fun box(): String {
val result = test1(11)
if (result != 22) return "fail1: ${result}"
return "OK"
}
@@ -0,0 +1,7 @@
package test
public class Z(public var s: Int)
inline fun Z.plusAssign(lambda: () -> Int) {
this.s += lambda()
}
@@ -0,0 +1,6 @@
import test.*
fun box(): String {
mfun{ "".toLowerCase2() }
return "OK"
}
@@ -0,0 +1,8 @@
package test
inline fun <R> mfun(f: () -> R) {
f()
f()
}
public inline fun String.toLowerCase2() : String = ""