Added more tests
This commit is contained in:
23
tests/programs/factorial.q
Normal file
23
tests/programs/factorial.q
Normal file
@ -0,0 +1,23 @@
|
||||
main() {
|
||||
for i := 0..10 {
|
||||
assert fac1(i) == fac2(i)
|
||||
}
|
||||
}
|
||||
|
||||
fac1(n int) -> int {
|
||||
x := 1
|
||||
|
||||
for i := 1..n+1 {
|
||||
x = x * i
|
||||
}
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
fac2(n int) -> int {
|
||||
if n <= 1 {
|
||||
return 1
|
||||
}
|
||||
|
||||
return n * fac2(n - 1)
|
||||
}
|
Reference in New Issue
Block a user