summaryrefslogtreecommitdiff
path: root/tests/type-consistency/spec/recursion.ts
blob: c5de83fb7e98fe46644c45377cac590037a4fc16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 },
    ],
  });