From a1acefab0ea05d1bc7437b0f454c54216a9a9152 Mon Sep 17 00:00:00 2001 From: nazrin Date: Mon, 2 Jun 2025 02:58:54 +0000 Subject: [PATCH] Improve tests --- test/all.d | 5 +++-- test/fib_closure.lox | 18 ++++++++++++++++++ test/{fib21.lox => fib_for.lox} | 0 test/{fib10.lox => fib_recursive.lox} | 0 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/fib_closure.lox rename test/{fib21.lox => fib_for.lox} (100%) rename test/{fib10.lox => fib_recursive.lox} (100%) diff --git a/test/all.d b/test/all.d index 5b79f0e..71de62f 100755 --- a/test/all.d +++ b/test/all.d @@ -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)); } diff --git a/test/fib_closure.lox b/test/fib_closure.lox new file mode 100644 index 0000000..42c8fe8 --- /dev/null +++ b/test/fib_closure.lox @@ -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(); + diff --git a/test/fib21.lox b/test/fib_for.lox similarity index 100% rename from test/fib21.lox rename to test/fib_for.lox diff --git a/test/fib10.lox b/test/fib_recursive.lox similarity index 100% rename from test/fib10.lox rename to test/fib_recursive.lox