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