Skip to content

Commit

Permalink
feat: add test case covering recursive functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpy committed May 24, 2024
1 parent 9915bd1 commit 01ff188
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/types/__snapshots__/resolveStatements.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1407,3 +1407,76 @@ exports[`resolveStatements should resolve statements for case-21 1`] = `
],
]
`;
exports[`resolveStatements should resolve statements for case-22 1`] = `
[
[
"n",
"Int",
],
[
"0",
"Int",
],
[
"n <= 0",
"Bool",
],
[
"0",
"Int",
],
[
"n",
"Int",
],
[
"1",
"Int",
],
[
"n == 1",
"Bool",
],
[
"1",
"Int",
],
[
"n",
"Int",
],
[
"1",
"Int",
],
[
"n - 1",
"Int",
],
[
"fib(n - 1)",
"Int",
],
[
"n",
"Int",
],
[
"2",
"Int",
],
[
"n - 2",
"Int",
],
[
"fib(n - 2)",
"Int",
],
[
"fib(n - 1) + fib(n - 2)",
"Int",
],
]
`;
7 changes: 7 additions & 0 deletions src/types/stmts/case-22.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
primitive Int;

fun fib(n: Int): Int {
if (n <= 0) { return 0; }
if (n == 1) { return 1; }
return fib(n - 1) + fib(n - 2);
}

0 comments on commit 01ff188

Please sign in to comment.