Improve tests
This commit is contained in:
parent
b0d934707b
commit
a1acefab0e
4 changed files with 21 additions and 2 deletions
|
|
@ -15,8 +15,9 @@ void main(){
|
|||
}
|
||||
return r;
|
||||
}
|
||||
assert([ "./lox", "test/fib21.lox" ].execute.output == fib(6765));
|
||||
assert([ "./lox", "test/fib10.lox" ].execute.output == fib(34));
|
||||
assert([ "./lox", "test/closure.lox" ].execute.output == "1\n2\n");
|
||||
assert([ "./lox", "test/fib_for.lox" ].execute.output == fib(6765));
|
||||
assert([ "./lox", "test/fib_recursive.lox" ].execute.output == fib(34));
|
||||
assert([ "./lox", "test/fib_closure.lox" ].execute.output == fib(34));
|
||||
}
|
||||
|
||||
|
|
|
|||
18
test/fib_closure.lox
Normal file
18
test/fib_closure.lox
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
fun fibonacci(){
|
||||
var a = 0;
|
||||
var b = 1;
|
||||
fun f(){
|
||||
var next = a;
|
||||
a = b;
|
||||
b = next + b;
|
||||
return next;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
var nextFibonacci = fibonacci();
|
||||
|
||||
for(var i = 0; i < 10; i = i + 1)
|
||||
print nextFibonacci();
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue