From 01ff1884a6c9d23352b253dbe6f324f9dddbe889 Mon Sep 17 00:00:00 2001 From: Vitor Py Braga <12871+vitorpy@users.noreply.github.com> Date: Fri, 24 May 2024 21:45:11 +0200 Subject: [PATCH] feat: add test case covering recursive functions --- .../resolveStatements.spec.ts.snap | 73 +++++++++++++++++++ src/types/stmts/case-22.tact | 7 ++ 2 files changed, 80 insertions(+) create mode 100644 src/types/stmts/case-22.tact diff --git a/src/types/__snapshots__/resolveStatements.spec.ts.snap b/src/types/__snapshots__/resolveStatements.spec.ts.snap index 5c6caf733..706bb967f 100644 --- a/src/types/__snapshots__/resolveStatements.spec.ts.snap +++ b/src/types/__snapshots__/resolveStatements.spec.ts.snap @@ -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", + ], +] +`; diff --git a/src/types/stmts/case-22.tact b/src/types/stmts/case-22.tact new file mode 100644 index 000000000..533c56c0d --- /dev/null +++ b/src/types/stmts/case-22.tact @@ -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); +} \ No newline at end of file