'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const { listCalendarDays, pivotDailyRows, bucketIntoChunks, bucketMapIntoChunks, } = require('../src/v2/baseline'); test('listCalendarDays inclui inicio e fim, sem pular nenhum dia', () => { const dias = listCalendarDays('2026-08-01', '2026-08-05'); assert.deepEqual(dias, ['2026-08-01', '2026-08-02', '2026-08-03', '2026-08-04', '2026-08-05']); }); test('pivotDailyRows preenche com zero os dias sem chamados (nao enviesa a media)', () => { const allDayKeys = ['2026-08-01', '2026-08-02', '2026-08-03']; const rows = [ { dia: '2026-08-01', nome: 'Hardware', total: 2 }, { dia: '2026-08-03', nome: 'Hardware', total: 4 }, ]; const pivot = pivotDailyRows(rows, allDayKeys); assert.deepEqual(pivot.get('Hardware'), [2, 0, 4]); }); test('pivotDailyRows aceita objetos Date do driver MySQL, nao so string', () => { const allDayKeys = ['2026-08-01', '2026-08-02']; const rows = [{ dia: new Date(2026, 7, 1), nome: 'Software', total: 5 }]; const pivot = pivotDailyRows(rows, allDayKeys); assert.deepEqual(pivot.get('Software'), [5, 0]); }); test('bucketIntoChunks agrupa dias em blocos de 7 (semana)', () => { const serie = [1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]; assert.deepEqual(bucketIntoChunks(serie, 7), [7, 14]); }); test('bucketMapIntoChunks aplica o bucket em todas as chaves do mapa', () => { const mapa = new Map([ ['A', [1, 1, 1, 1, 1, 1, 1]], ['B', [2, 0, 0, 0, 0, 0, 0]], ]); const bucketed = bucketMapIntoChunks(mapa, 7); assert.deepEqual(bucketed.get('A'), [7]); assert.deepEqual(bucketed.get('B'), [2]); });