Added tests for simple closure examples.
This commit is contained in:
@@ -28,4 +28,14 @@ public class FunctionTest extends AbstractExpressionTest {
|
|||||||
public void functionLiteral() throws Exception {
|
public void functionLiteral() throws Exception {
|
||||||
testFooBoxIsTrue("functionLiteral.kt");
|
testFooBoxIsTrue("functionLiteral.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adderClosure() throws Exception {
|
||||||
|
testFooBoxIsTrue("adderClosure.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loopClosure() throws Exception {
|
||||||
|
testFooBoxIsTrue("loopClosure.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace foo
|
||||||
|
|
||||||
|
fun box() : Boolean {
|
||||||
|
var sum = 0
|
||||||
|
val adder = {(a: Int) => sum += a }
|
||||||
|
adder(3)
|
||||||
|
adder(2)
|
||||||
|
return sum == 5
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace foo
|
||||||
|
|
||||||
|
var b = 0
|
||||||
|
|
||||||
|
fun loop(var times : Int) {
|
||||||
|
while(times > 0) {
|
||||||
|
val u : fun(value : Int) : Unit = {
|
||||||
|
b++
|
||||||
|
}
|
||||||
|
u(times--)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : Boolean {
|
||||||
|
loop(5)
|
||||||
|
return b == 5
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user