mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Refactor: Make test harness browser-compatible
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
|
functionName: 'findShortestPath',
|
||||||
prompt: `
|
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.
|
// 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.
|
||||||
//
|
//
|
||||||
@@ -8,27 +9,15 @@ export default {
|
|||||||
// - The function should return the total weight of the shortest path, or Infinity if no path exists.
|
// - The function should return the total weight of the shortest path, or Infinity if no path exists.
|
||||||
// - Graph format: { 'A': { 'B': 1, 'C': 4 }, 'B': { ... }, ... }
|
// - Graph format: { 'A': { 'B': 1, 'C': 4 }, 'B': { ... }, ... }
|
||||||
`,
|
`,
|
||||||
harness: `
|
runTest: async (findShortestPath) => {
|
||||||
import assert from 'assert';
|
const assert = {
|
||||||
async function runTest() {
|
strictEqual: (a, e, m) => { if (a !== e) throw new Error(m || `FAIL: ${a} !== ${e}`) },
|
||||||
const graph = {
|
};
|
||||||
A: { B: 2, C: 5 },
|
const graph = {
|
||||||
B: { A: 2, C: 6, D: 1, E: 3 },
|
A: { B: 2, C: 5 }, B: { A: 2, C: 6, D: 1, E: 3 }, C: { A: 5, B: 6, F: 8 },
|
||||||
C: { A: 5, B: 6, F: 8 },
|
D: { B: 1, E: 4 }, E: { B: 3, D: 4, F: 2 }, F: { C: 8, E: 2 }
|
||||||
D: { B: 1, E: 4 },
|
|
||||||
E: { B: 3, D: 4, F: 2 },
|
|
||||||
F: { C: 8, E: 2 }
|
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
const dist = await findShortestPath(graph, 'A', 'F');
|
const dist = await findShortestPath(graph, 'A', 'F');
|
||||||
assert.strictEqual(dist, 7, "Test Failed: Path A to F should be 7.");
|
assert.strictEqual(dist, 7, "Test Failed: Path A to F should be 7.");
|
||||||
console.log("Test Passed!");
|
|
||||||
process.exit(0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Test Execution Error:", e.message);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
runTest();
|
|
||||||
`
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user