From 6c5fcba939b3d06ac1e2fb1821386371a642ed26 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 13 Nov 2025 16:45:20 -0800 Subject: [PATCH] Refactor: Export test case inputs for debug page --- tests/2_convex_hull/test.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/2_convex_hull/test.js b/tests/2_convex_hull/test.js index dc16dc6..1ef1c7b 100644 --- a/tests/2_convex_hull/test.js +++ b/tests/2_convex_hull/test.js @@ -4,18 +4,21 @@ export default { // - The function must accept an array of points, e.g., [{x: 0, y: 3}, {x: 1, y: 1}, ...]. // - You MUST use a dynamic import() to load the 'lodash' library from a CDN for sorting and uniqueness operations. // - The function should return an array of points representing the convex hull.`, - runTest: async (findConvexHull) => { - const assert = { - deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, - }; + getTestCases: () => { const points = [ {x: 0, y: 3}, {x: 1, y: 1}, {x: 2, y: 2}, {x: 4, y: 4}, {x: 0, y: 0}, {x: 1, y: 2}, {x: 3, y: 1}, {x: 3, y: 3} ]; + return [points]; + }, + runTest: async (findConvexHull) => { + const assert = { + deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, + }; + const [points] = globalThis.getTestCases ? globalThis.getTestCases() : this.getTestCases(); const expected = [{x: 0, y: 0}, {x: 3, y: 1}, {x: 4, y: 4}, {x: 0, y: 3}]; const hull = await findConvexHull(points); const sortFn = (a, b) => a.x - b.x || a.y - b.y; assert.deepStrictEqual(hull.sort(sortFn), expected.sort(sortFn), "Test Failed: Convex hull points do not match."); } }; -