Skip to content

Commit 348372a

Browse files
authored
test(layout): verify all towers have non-negative height values (JhaSourav07#2222)
## Description Adds a regression test to ensure all towers returned by computeTowers have non-negative height values. ## Changes Added a test covering varied contribution counts (0, 1, 5, 20). Verifies every generated tower satisfies h >= 0. Fixes JhaSourav07#727 ## Pillar - [x] 📐 Pillar 2 — Geometric SVG Improvement - [x] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview ## 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=YOUR_USERNAME`). - [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 started 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 37dabe7 + 2bb7aa3 commit 348372a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/svg/layout.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ describe('computeTowers edge cases', () => {
215215
// Assert intensityLevel is calculated correctly based on lines of code (60/60 = 100%, so intensity 4)
216216
expect(testTower.intensityLevel).toBe(4);
217217
});
218+
it('ensures all tower heights are non-negative', () => {
219+
const calendar = {
220+
totalContributions: 26,
221+
weeks: [
222+
{
223+
contributionDays: [
224+
{ contributionCount: 0, date: '2024-06-10' },
225+
{ contributionCount: 1, date: '2024-06-11' },
226+
{ contributionCount: 5, date: '2024-06-12' },
227+
{ contributionCount: 20, date: '2024-06-13' },
228+
],
229+
},
230+
],
231+
} as unknown as ContributionCalendar;
232+
233+
const towers = computeTowers(calendar, 'linear', '2024-06-13');
234+
235+
towers.forEach((tower) => {
236+
expect(tower.h).toBeGreaterThanOrEqual(0);
237+
});
238+
});
218239
});
219240

220241
it('assigns correct row and col values based on week/day position', () => {

0 commit comments

Comments
 (0)