Skip to content

Commit cd21f62

Browse files
authored
test(calculate): verify streak formulas for multiple weeks gaps timeline (Variation 3) (JhaSourav07#1489) (JhaSourav07#1906)
## Description This PR adds test coverage to verify the streak formulas when there are multiple weeks of zero contribution gaps between active streaks, acting as Variation 3 of the multiple weeks gaps timeline tests. Fixes JhaSourav07#1489 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (Tests only) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=boss477`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have starred the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents c01f36d + 69e3c83 commit cd21f62

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

lib/calculate.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,72 @@ describe('calculateStreak', () => {
517517
expect(result.currentStreak).toBe(15);
518518
expect(result.longestStreak).toBe(15);
519519
});
520+
521+
it('verify streak formulas for multiple weeks gaps timeline (Variation 3)', () => {
522+
// Streak 1: 5 days
523+
// Gap 1: 14 days (2 weeks of zeros)
524+
// Streak 2: 10 days (longest)
525+
// Gap 2: 21 days (3 weeks of zeros)
526+
// Streak 3: 3 days (current) ending on the last day
527+
const calendar = buildCalendar([
528+
1,
529+
1,
530+
1,
531+
1,
532+
1, // Streak 1 (5 days)
533+
0,
534+
0,
535+
0,
536+
0,
537+
0,
538+
0,
539+
0,
540+
0,
541+
0,
542+
0,
543+
0,
544+
0,
545+
0,
546+
0, // Gap 1 (14 days)
547+
1,
548+
1,
549+
1,
550+
1,
551+
1,
552+
1,
553+
1,
554+
1,
555+
1,
556+
1, // Streak 2 (10 days)
557+
0,
558+
0,
559+
0,
560+
0,
561+
0,
562+
0,
563+
0,
564+
0,
565+
0,
566+
0,
567+
0,
568+
0,
569+
0,
570+
0,
571+
0,
572+
0,
573+
0,
574+
0,
575+
0,
576+
0,
577+
0, // Gap 2 (21 days)
578+
1,
579+
1,
580+
1, // Streak 3 (3 days - ending on last day)
581+
]);
582+
const result = calculateStreak(calendar);
583+
expect(result.longestStreak).toBe(10);
584+
expect(result.currentStreak).toBe(3);
585+
});
520586
});
521587

522588
it('handles massive single-day commit spike timeline', () => {

0 commit comments

Comments
 (0)