mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
27
samples/Terra/fib2.t
Normal file
27
samples/Terra/fib2.t
Normal file
@@ -0,0 +1,27 @@
|
||||
local test = require("test")
|
||||
|
||||
local Num = int
|
||||
|
||||
terra fib(a : Num) : Num
|
||||
if a == 0 then
|
||||
return 1
|
||||
elseif a == 1 then
|
||||
return 1
|
||||
else
|
||||
return fib(a - 1) + fib(a - 2)
|
||||
end
|
||||
end
|
||||
|
||||
function fib2(a)
|
||||
if a == 0 then
|
||||
return 1
|
||||
elseif a == 1 then
|
||||
return 1
|
||||
else
|
||||
return fib2(a - 1) + fib2(a - 2)
|
||||
end
|
||||
end
|
||||
for i = 0,10 do
|
||||
print(fib(i))
|
||||
test.eq(fib(i),fib2(i))
|
||||
end
|
||||
Reference in New Issue
Block a user