Skip to content

Commit 3636917

Browse files
authored
test(calculate): verify longest streak is found in middle of calendar (JhaSourav07#821)
2 parents 0b73bcc + 35f8231 commit 3636917

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
@@ -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

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

0 commit comments

Comments
 (0)