From 190f85ff1ac23f952a7b4960638fee79495e249a Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Sun, 9 Nov 2025 21:52:06 -0800 Subject: filter --- tests/type-consistency/spec/index.ts | 4 +- tests/type-consistency/spec/mapReduce.ts | 34 ----------------- tests/type-consistency/spec/mapReduceFilter.ts | 53 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 36 deletions(-) delete mode 100644 tests/type-consistency/spec/mapReduce.ts create mode 100644 tests/type-consistency/spec/mapReduceFilter.ts (limited to 'tests') diff --git a/tests/type-consistency/spec/index.ts b/tests/type-consistency/spec/index.ts index 780c20c..c9b8c7a 100644 --- a/tests/type-consistency/spec/index.ts +++ b/tests/type-consistency/spec/index.ts @@ -2,7 +2,7 @@ import array from "./array"; import functions from "./function"; import types from "./types"; import tostring from "./tostring"; -import mapreduce from "./mapReduce"; +import mapreducefilter from "./mapReduceFilter"; import recursion from "./recursion"; -export default [array, functions, types, tostring, mapreduce, recursion]; +export default [array, functions, types, tostring, mapreducefilter, recursion]; diff --git a/tests/type-consistency/spec/mapReduce.ts b/tests/type-consistency/spec/mapReduce.ts deleted file mode 100644 index b5077ff..0000000 --- a/tests/type-consistency/spec/mapReduce.ts +++ /dev/null @@ -1,34 +0,0 @@ -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 }, - ], - }); diff --git a/tests/type-consistency/spec/mapReduceFilter.ts b/tests/type-consistency/spec/mapReduceFilter.ts new file mode 100644 index 0000000..4594e71 --- /dev/null +++ b/tests/type-consistency/spec/mapReduceFilter.ts @@ -0,0 +1,53 @@ +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 }, + ], + }) + .createFunctionTest({ + name: "Filter: remove 0s", + program: "fn(a, filter(a, fn(n, ?(eq(n, 0), false, true))))", + cases: [ + { input: [1, 2, 3], output: [1, 2, 3] }, + { input: [1, 0, 10], output: [1, 10] }, + { input: [0, 0, 0], output: [] }, + { input: [0, 0, 3, 0, 5, 0, 7, 0], output: [3, 5, 7] }, + ], + }) + .createFunctionTest({ + name: "Filter: remove first element", + program: "fn(a, filter(a, fn(n, idx, ?(eq(idx, 0), false, true))))", + cases: [ + { input: [true, true, false], output: [true, false] }, + { input: [1, 0, 10], output: [0, 10] }, + { input: ["hi", ["test", "test2"]], output: [["test", "test2"]] }, + ], + }); -- cgit v1.2.3-70-g09d2