From 413eaa284e164143c5416cdce5a1de0f9f992409 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 9 Nov 2025 21:08:12 -0800 Subject: map + reduce --- tests/type-consistency/spec/mapReduce.ts | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/type-consistency/spec/mapReduce.ts (limited to 'tests/type-consistency/spec/mapReduce.ts') diff --git a/tests/type-consistency/spec/mapReduce.ts b/tests/type-consistency/spec/mapReduce.ts new file mode 100644 index 0000000..b5077ff --- /dev/null +++ b/tests/type-consistency/spec/mapReduce.ts @@ -0,0 +1,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 }, + ], + }); -- cgit v1.2.3-70-g09d2