import * as fc from 'fast-check'; import { describe, it, expect } from 'vitest'; import { getColor } from '../src/utils/color.js'; /** * Feature: ball-block-breaker, Property 17: 颜色计算有效性 * **Validates: Requirements 8.6** * * 对于任意正整数 count,getColor(count) 应返回一个有效的7字符十六进制颜色字符串(格式为 #RRGGBB)。 */ describe('Color Utils', () => { it('Property 17: getColor returns a valid 7-character hex color string for any positive integer', () => { fc.assert( fc.property( fc.integer({ min: 1, max: 1_000_000 }), (count) => { const color = getColor(count); // Must be a string of exactly 7 characters expect(typeof color).toBe('string'); expect(color).toHaveLength(7); // Must start with '#' expect(color[0]).toBe('#'); // Remaining 6 characters must be valid hex digits [0-9a-f] const hexPart = color.slice(1); expect(hexPart).toMatch(/^[0-9a-f]{6}$/); } ), { numRuns: 100 } ); }); });