Skip to content

Commit 35f8231

Browse files
committed
test(calculate): verify longest streak is found in middle of calendar
1 parent 7ee2274 commit 35f8231

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff 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

215263
describe('calculateStreak — timezone awareness', () => {

0 commit comments

Comments
 (0)