File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -210,6 +210,54 @@ describe('calculateStreak', () => {
210210 expect ( result . currentStreak ) . toBe ( 0 ) ;
211211 expect ( result . longestStreak ) . toBe ( 0 ) ;
212212 } ) ;
213+
214+ it ( 'should find the longest streak when it is in the middle of the calendar' , ( ) => {
215+ // buildCalendar groups elements by sets of 7 (weeks) from left to right.
216+ // The very last element of the flat array represents "today".
217+ const calendar = buildCalendar ( [
218+ 0 ,
219+ 0 ,
220+ 0 ,
221+ 0 ,
222+ 0 ,
223+ 0 ,
224+ 0 , // Week 1 — Buffer gap
225+ 1 ,
226+ 1 ,
227+ 1 ,
228+ 1 ,
229+ 1 ,
230+ 1 ,
231+ 1 , // Week 2 — Longest streak start (7 days)
232+ 1 ,
233+ 1 ,
234+ 1 ,
235+ 0 ,
236+ 0 ,
237+ 0 ,
238+ 0 , // Week 3 — Longest streak ends (+3 days = 10 total) followed by a gap
239+ 1 ,
240+ 1 ,
241+ 1 ,
242+ 1 ,
243+ 1 ,
244+ 0 ,
245+ 0 , // Week 4 — Intermediate streak (5 days) broken by a gap
246+ 0 ,
247+ 0 ,
248+ 1 ,
249+ 1 ,
250+ 1 ,
251+ 1 ,
252+ 1 , // Week 5 — 5-day active current streak ending on the final day ("today")
253+ ] ) ;
254+
255+ const result = calculateStreak ( calendar ) ;
256+
257+ // Assertions (Definition of Done)
258+ expect ( result . longestStreak ) . toBe ( 10 ) ;
259+ expect ( result . currentStreak ) . toBe ( 5 ) ;
260+ } ) ;
213261} ) ;
214262
215263describe ( 'calculateStreak — timezone awareness' , ( ) => {
You can’t perform that action at this time.
0 commit comments