From 0b2e5b4acfc9bd628ee3a854bd5dd6cbafcde05a Mon Sep 17 00:00:00 2001 From: Rakshak05 Date: Fri, 12 Jun 2026 02:47:47 +0530 Subject: [PATCH 1/2] test(generatorConstants-massive-scaling): verify Massive Data Sets and Extreme High Bounds Scaling --- ...generatorConstants.massive-scaling.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/svg/generatorConstants.massive-scaling.test.ts diff --git a/lib/svg/generatorConstants.massive-scaling.test.ts b/lib/svg/generatorConstants.massive-scaling.test.ts new file mode 100644 index 000000000..3cec86efe --- /dev/null +++ b/lib/svg/generatorConstants.massive-scaling.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, it } from 'vitest'; +import { SVG_WIDTH, SVG_HEIGHT, isFontKey } from './generatorConstants'; +import { FONT_MAP } from './fonts'; + +describe('generatorConstants Massive Scaling', () => { + it('isFontKey returns true for all known keys across 10,000 lookups', () => { + const keys = Object.keys(FONT_MAP); + const start = performance.now(); + for (let i = 0; i < 10_000; i++) { + const key = keys[i % keys.length]; + expect(isFontKey(key)).toBe(true); + } + expect(performance.now() - start).toBeLessThan(500); // performance guard + }); + + it('isFontKey returns false for 5,000 synthetic unknown font names', () => { + const unknowns = Array.from({ length: 5_000 }, (_, i) => `font_${i}`); + unknowns.forEach((f) => expect(isFontKey(f)).toBe(false)); + }); + + it('SVG_WIDTH and SVG_HEIGHT do not drift under 10,000 repeated reads', () => { + for (let i = 0; i < 10_000; i++) { + expect(SVG_WIDTH).toBe(600); + expect(SVG_HEIGHT).toBe(420); + } + }); + + it('SVG_WIDTH and SVG_HEIGHT yield valid coordinate bounds for 10,000 simulated contributor positions', () => { + const positions = Array.from({ length: 10_000 }, (_, i) => ({ + x: i % SVG_WIDTH, + y: Math.floor(i / SVG_WIDTH) % SVG_HEIGHT, + })); + positions.forEach(({ x, y }) => { + expect(x).toBeGreaterThanOrEqual(0); + expect(x).toBeLessThan(SVG_WIDTH); + expect(y).toBeGreaterThanOrEqual(0); + expect(y).toBeLessThan(SVG_HEIGHT); + }); + }); + + it('isFontKey handles extreme string lengths without timing out', () => { + const extremeInputs = ['', 'a', 'x'.repeat(100), 'x'.repeat(10_000), 'x'.repeat(100_000)]; + const start = performance.now(); + extremeInputs.forEach((s) => expect(isFontKey(s)).toBe(false)); + expect(performance.now() - start).toBeLessThan(200); + }); +}); From ce48f46c8348218e76e153f5ca021f609bd07aa7 Mon Sep 17 00:00:00 2001 From: Rakshak05 Date: Fri, 12 Jun 2026 02:58:41 +0530 Subject: [PATCH 2/2] refactor(generatorConstants-massive-scaling): optimize assertion count, memory usage, sentinel safety --- ...generatorConstants.massive-scaling.test.ts | 76 ++++++++++++++----- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/lib/svg/generatorConstants.massive-scaling.test.ts b/lib/svg/generatorConstants.massive-scaling.test.ts index 3cec86efe..010fba484 100644 --- a/lib/svg/generatorConstants.massive-scaling.test.ts +++ b/lib/svg/generatorConstants.massive-scaling.test.ts @@ -5,43 +5,81 @@ import { FONT_MAP } from './fonts'; describe('generatorConstants Massive Scaling', () => { it('isFontKey returns true for all known keys across 10,000 lookups', () => { const keys = Object.keys(FONT_MAP); + expect(keys.length).toBeGreaterThan(0); + + let allValid = true; const start = performance.now(); for (let i = 0; i < 10_000; i++) { const key = keys[i % keys.length]; - expect(isFontKey(key)).toBe(true); + if (!isFontKey(key)) { + allValid = false; + break; + } } - expect(performance.now() - start).toBeLessThan(500); // performance guard + const duration = performance.now() - start; + + expect(allValid).toBe(true); + // Generous performance margin to prevent CI flakiness + expect(duration).toBeLessThan(5000); }); it('isFontKey returns false for 5,000 synthetic unknown font names', () => { - const unknowns = Array.from({ length: 5_000 }, (_, i) => `font_${i}`); - unknowns.forEach((f) => expect(isFontKey(f)).toBe(false)); + const knownKeys = new Set(Object.keys(FONT_MAP)); + for (let i = 0; i < 5_000; i++) { + const candidate = `nonexistent_font_sentinel_${i}`; + if (!knownKeys.has(candidate)) { + expect(isFontKey(candidate)).toBe(false); + } + } }); it('SVG_WIDTH and SVG_HEIGHT do not drift under 10,000 repeated reads', () => { + let widthSum = 0; + let heightSum = 0; for (let i = 0; i < 10_000; i++) { - expect(SVG_WIDTH).toBe(600); - expect(SVG_HEIGHT).toBe(420); + widthSum += SVG_WIDTH; + heightSum += SVG_HEIGHT; } + expect(widthSum).toBe(600 * 10_000); + expect(heightSum).toBe(420 * 10_000); }); it('SVG_WIDTH and SVG_HEIGHT yield valid coordinate bounds for 10,000 simulated contributor positions', () => { - const positions = Array.from({ length: 10_000 }, (_, i) => ({ - x: i % SVG_WIDTH, - y: Math.floor(i / SVG_WIDTH) % SVG_HEIGHT, - })); - positions.forEach(({ x, y }) => { - expect(x).toBeGreaterThanOrEqual(0); - expect(x).toBeLessThan(SVG_WIDTH); - expect(y).toBeGreaterThanOrEqual(0); - expect(y).toBeLessThan(SVG_HEIGHT); - }); + let allValid = true; + for (let i = 0; i < 10_000; i++) { + const x = i % SVG_WIDTH; + const y = Math.floor(i / SVG_WIDTH) % SVG_HEIGHT; + if ( + x < 0 || + x >= SVG_WIDTH || + y < 0 || + y >= SVG_HEIGHT || + !Number.isFinite(x) || + !Number.isFinite(y) + ) { + allValid = false; + break; + } + } + expect(allValid).toBe(true); }); it('isFontKey handles extreme string lengths without timing out', () => { - const extremeInputs = ['', 'a', 'x'.repeat(100), 'x'.repeat(10_000), 'x'.repeat(100_000)]; + const knownKeys = new Set(Object.keys(FONT_MAP)); + const extremeInputs = [ + '', + 'a', + 'x'.repeat(100), + 'x'.repeat(10_000), + 'x'.repeat(100_000), + ].filter((s) => !knownKeys.has(s)); + const start = performance.now(); - extremeInputs.forEach((s) => expect(isFontKey(s)).toBe(false)); - expect(performance.now() - start).toBeLessThan(200); + extremeInputs.forEach((s) => { + expect(isFontKey(s)).toBe(false); + }); + const duration = performance.now() - start; + // Generous performance margin to prevent CI flakiness + expect(duration).toBeLessThan(5000); }); });