Revert: Update test.js

This commit is contained in:
2025-11-13 16:49:19 -08:00
parent f2e9b766dc
commit 53833b2084

View File

@@ -4,21 +4,19 @@ export default {
// - The function must accept an array of points, e.g., [{x: 0, y: 3}, {x: 1, y: 1}, ...]. // - 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. // - 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.`, // - The function should return an array of points representing the convex hull.`,
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) => { runTest: async (findConvexHull) => {
const assert = { const assert = {
deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) },
}; };
const [points] = globalThis.getTestCases ? globalThis.getTestCases() : this.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}
];
const expected = [{x: 0, y: 0}, {x: 3, y: 1}, {x: 4, y: 4}, {x: 0, 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); const hull = await findConvexHull(points);
const sortFn = (a, b) => a.x - b.x || a.y - b.y; 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."); assert.deepStrictEqual(hull.sort(sortFn), expected.sort(sortFn), "Test Failed: Convex hull points do not match.");
} }
}; };