@@ -84,7 +84,7 @@ describe('buildWeeklyEvolution', () => {
8484 expect ( result [ 1 ] ! . weekEnd ) . toBe ( '2025-03-10' )
8585 } )
8686
87- it ( 'aligns from last non-zero data day, ignoring trailing zeros' , ( ) => {
87+ it ( 'always aligns from rangeEnd, even with trailing zeros' , ( ) => {
8888 const daily = [
8989 { day : '2025-03-01' , value : 10 } ,
9090 { day : '2025-03-02' , value : 10 } ,
@@ -99,10 +99,14 @@ describe('buildWeeklyEvolution', () => {
9999
100100 const result = buildWeeklyEvolution ( daily , '2025-03-01' , '2025-03-09' )
101101
102- expect ( result ) . toHaveLength ( 1 )
103- expect ( result [ 0 ] ! . value ) . toBe ( 70 )
102+ // Bucket 0: 03-03..03-09 = 50, Bucket 1: 03-01..03-02 (partial, scaled )
103+ expect ( result ) . toHaveLength ( 2 )
104104 expect ( result [ 0 ] ! . weekStart ) . toBe ( '2025-03-01' )
105- expect ( result [ 0 ] ! . weekEnd ) . toBe ( '2025-03-07' )
105+ expect ( result [ 0 ] ! . weekEnd ) . toBe ( '2025-03-02' )
106+ expect ( result [ 0 ] ! . value ) . toBe ( Math . round ( ( 20 * 7 ) / 2 ) )
107+ expect ( result [ 1 ] ! . weekStart ) . toBe ( '2025-03-03' )
108+ expect ( result [ 1 ] ! . weekEnd ) . toBe ( '2025-03-09' )
109+ expect ( result [ 1 ] ! . value ) . toBe ( 50 )
106110 } )
107111
108112 it ( 'returns empty array for empty input' , ( ) => {
0 commit comments