summaryrefslogtreecommitdiff
path: root/tests/type-consistency/spec/mapReduce.ts
blob: b5077ff285f20501112c71364006dbbc49b9cd3e (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
26
27
28
29
30
31
32
33
34
import path from "path";
import { createTestHarness } from "../harness";

export default createTestHarness({
  harnessName: "Map reduce",
  generatedPath: path.join(__dirname, "..", "generated"),
})
  .createFunctionTest({
    name: "Map: numbers to string",
    program: "fn(a, map(a, fn(n, tostring(n))))",
    cases: [
      { input: [1, 2, 3], output: ["1", "2", "3"] },
      { input: [50], output: ["50"] },
      { input: [], output: [] },
    ],
  })
  .createFunctionTest({
    name: "Reduce: array length",
    program: "fn(a, reduce(a, fn(acc, add(acc, 1)), 0))",
    cases: [
      { input: [1, 2, 3], output: 3 },
      { input: ["hello", ["hello", "world"]], output: 2 },
      { input: [], output: 0 },
    ],
  })
  .createFunctionTest({
    name: "Reduce: sum of numbers times index",
    program: "fn(a, reduce(a, fn(acc, cur, idx, add(acc, mul(cur, idx))), 0))",
    cases: [
      { input: [1, 2, 3], output: 8 },
      { input: [], output: 0 },
      { input: [50, 10, 0], output: 10 },
    ],
  });