From eb8cff62563b1d41ab3a8c4411608890271e61a9 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 13 Nov 2025 17:29:02 -0800 Subject: [PATCH] Fix: Clarify exact average calculation expectation --- tests/6_csv_processor/test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/6_csv_processor/test.js b/tests/6_csv_processor/test.js index 1b49c63..0b23e4d 100644 --- a/tests/6_csv_processor/test.js +++ b/tests/6_csv_processor/test.js @@ -3,17 +3,22 @@ export default { prompt: `// Write an async JavaScript function 'processCSV' that parses CSV data, filters rows, and performs aggregations. // - The function must accept a CSV string and a configuration object: { filterColumn: string, filterValue: any, groupBy: string, aggregateColumn: string, operation: 'sum'|'avg'|'count' }. // - 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 }].`, +// - Parse the CSV with headers. Filter rows where filterColumn equals filterValue (use loose equality ==). +// - Group filtered rows by the groupBy column value. +// - For each group, perform the operation on the aggregateColumn: 'sum' adds all values, 'avg' calculates mean (sum/count), 'count' returns row count. +// - Convert aggregateColumn values to numbers. Treat non-numeric values as 0. +// - Return an array of objects, one per group: [{ [groupBy]: groupValue, result: aggregatedNumber }]. +// - For 'avg', return the exact mathematical average without rounding.`, runTest: async (processCSV) => { const assert = { - deepStrictEqual: (a, e, m) => { if (JSON.stringify(a) !== JSON.stringify(e)) throw new Error(m) }, + strictEqual: (a, e, m) => { if (a !== e) throw new Error(m || `FAIL: ${a} !== ${e}`) }, }; 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 result = await processCSV(csv, config); - const res = result[0] || {}; - const val = res.result ?? res.avg ?? res.value; - assert.deepStrictEqual([{ department: res.department, result: val }], [{ department: 'Engineering', result: 90000 }], 'Test Failed: Aggregation incorrect.'); + assert.strictEqual(result.length, 1, 'Test Failed: Should return exactly 1 group.'); + const res = result[0]; + assert.strictEqual(res.department, 'Engineering', 'Test Failed: Wrong department.'); + assert.strictEqual(res.result, 90000, 'Test Failed: Average should be exactly 90000.'); } };