diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2025-11-09 21:08:12 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2025-11-09 21:08:30 -0800 |
| commit | 413eaa284e164143c5416cdce5a1de0f9f992409 (patch) | |
| tree | d999e8cbaddefcce9df3265c594083177427b6cb /tests/type-consistency/spec/recursion.ts | |
| parent | 93992029bd349185d15de02e0f633e95c62695a9 (diff) | |
map + reduce
Diffstat (limited to 'tests/type-consistency/spec/recursion.ts')
| -rw-r--r-- | tests/type-consistency/spec/recursion.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/type-consistency/spec/recursion.ts b/tests/type-consistency/spec/recursion.ts new file mode 100644 index 0000000..c5de83f --- /dev/null +++ b/tests/type-consistency/spec/recursion.ts @@ -0,0 +1,25 @@ +import path from "path"; +import { createTestHarness } from "../harness"; + +export default createTestHarness({ + harnessName: "Recursive functions", + generatedPath: path.join(__dirname, "..", "generated"), +}) + .createFunctionTest({ + name: "n!", + program: "bind(fac,fn(n,?(eq(n, 1),n,mul(n,call(fac,sub(n,1))))))", + cases: [ + { input: 3, output: 6 }, + { input: 1, output: 1 }, + { input: 5, output: 120 }, + ], + }) + .createFunctionTest({ + name: "Sum of natural numbers on [0, n]", + program: "bind(sumnn,fn(n,?(eq(n, 1),n,add(n,call(sumnn,sub(n,1))))))", + cases: [ + { input: 5, output: 15 }, + { input: 1, output: 1 }, + { input: 2, output: 3 }, + ], + }); |
