From a33d342c596a15cc6183d229d205467d9fb767ac Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Mon, 13 Oct 2025 10:24:39 -0700 Subject: [PATCH] Refactor: Make test harness browser-compatible --- tests/2_convex_hull/test.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/2_convex_hull/test.js b/tests/2_convex_hull/test.js index d6337e8..76c5295 100644 --- a/tests/2_convex_hull/test.js +++ b/tests/2_convex_hull/test.js @@ -1,4 +1,5 @@ export default { + functionName: 'findConvexHull', prompt: ` // Your goal is to write a production-ready and maintainable JavaScript function. Apply code-golfing practices without sacrificing readability by putting everything on one line. Do not include any comments in your code. // @@ -7,26 +8,16 @@ export default { // - 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, ordered clockwise. `, - harness: ` -import assert from 'assert'; -async function runTest() { - 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} - ]; - const expectedHull = [ - {x: 0, y: 0}, {x: 3, y: 1}, {x: 4, y: 4}, {x: 0, y: 3} - ]; - try { + runTest: async (findConvexHull) => { + const assert = { + deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, + }; + 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} + ]; + const expected = [{x: 0, y: 0}, {x: 3, y: 1}, {x: 4, y: 4}, {x: 0, y: 3}]; const hull = await findConvexHull(points); - assert.deepStrictEqual(hull, expectedHull, "Test Failed: Convex hull does not match expected output."); - console.log("Test Passed!"); - process.exit(0); - } catch (e) { - console.error("Test Execution Error:", e.message); - process.exit(1); + assert.deepStrictEqual(hull, expected, "Test Failed: Convex hull does not match."); } -} -runTest(); -` };