From dce40257ed097dd0e0d60c6601916c545a15ebe6 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Tue, 14 Oct 2025 05:44:14 -0700 Subject: [PATCH] Feat: Add CSV processor test --- tests/6_csv_processor/test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/6_csv_processor/test.js diff --git a/tests/6_csv_processor/test.js b/tests/6_csv_processor/test.js new file mode 100644 index 0000000..3a31180 --- /dev/null +++ b/tests/6_csv_processor/test.js @@ -0,0 +1,17 @@ +export default { + functionName: 'processCSV', + 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.`, + 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 result = await processCSV(csv, config); + assert.deepStrictEqual(result, [{ department: 'Engineering', value: 90000 }], 'Test Failed: Aggregation incorrect.'); + } +};