cpp-peglib/language/samples/test.cul

65 lines
858 B
Plaintext
Raw Normal View History

2015-07-07 19:44:33 +00:00
test_call = fn () {
ret = fn(){[1,fn(){[4,5,6]},3]}()[1]()[1]
assert(ret == 5)
}
test_closure = fn () {
make_func = fn (mut x) {
mut n = 100
fn () {
n = n + 1
x = x + 1 + n
}
}
f = make_func(10)
f()
f()
ret = f()
assert(ret == 319)
}
2015-07-07 19:44:33 +00:00
test_sum = fn () {
mut i = 1
mut ret = 0
while i <= 10 {
ret = ret + i
i = i + 1
}
assert(ret == 55)
}
2015-07-21 10:45:24 +00:00
test_array = fn () {
a = [1,2,3]
assert(a.size() == 3)
a.push(4)
assert(a.size() == 4)
b = []
assert(b.size() == 0)
}
2015-07-07 19:44:33 +00:00
test_fib = fn () {
fib = fn (x) {
if x < 2 {
x
} else {
self(x - 2) + self(x -1)
}
}
ret = fib(15)
assert(ret == 610)
}
test_call()
test_closure()
2015-07-21 10:45:24 +00:00
test_array()
2015-07-07 19:44:33 +00:00
test_sum()
test_fib()