From 106fd18aab853eae63c825244dd9e9064ccb9d02 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 13 Nov 2025 16:45:32 -0800 Subject: [PATCH] Refactor: Export test case inputs for debug page --- tests/6_csv_processor/test.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/6_csv_processor/test.js b/tests/6_csv_processor/test.js index 47e24fa..3462bf6 100644 --- a/tests/6_csv_processor/test.js +++ b/tests/6_csv_processor/test.js @@ -5,16 +5,19 @@ export default { // - You MUST use dynamic import() to load one or more libraries from a CDN for CSV parsing and data manipulation. // - Parse the CSV, filter rows where filterColumn equals filterValue, group by groupBy column, and perform the specified aggregation. // - Return an array of objects with the groupBy value and the aggregated result, e.g. [{ department: 'Engineering', result: 90000 }].`, + getTestCases: () => { + const csv = `name,department,salary\nAlice,Engineering,90000\nBob,Engineering,85000\nCharlie,Sales,70000\nDiana,Engineering,95000\nEve,Sales,72000`; + const config = { filterColumn: 'department', filterValue: 'Engineering', groupBy: 'department', aggregateColumn: 'salary', operation: 'avg' }; + return [csv, config]; + }, runTest: async (processCSV) => { const assert = { deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, }; - const csv = `name,department,salary\nAlice,Engineering,90000\nBob,Engineering,85000\nCharlie,Sales,70000\nDiana,Engineering,95000\nEve,Sales,72000`; - const config = { filterColumn: 'department', filterValue: 'Engineering', groupBy: 'department', aggregateColumn: 'salary', operation: 'avg' }; + const [csv, config] = globalThis.getTestCases ? globalThis.getTestCases() : this.getTestCases(); const result = await processCSV(csv, config); const res = result[0] || {}; const val = res.result ?? res.avg ?? res.value; assert.deepStrictEqual([{ department: res.department, value: val }], [{ department: 'Engineering', value: 90000 }], 'Test Failed: Aggregation incorrect.'); } }; -