import { describe, it, expect } from 'vitest'; import { WinRateFormatter } from './WinRateFormatter'; describe('WinRateFormatter', () => { describe('calculate', () => { it('should return "0.0" when no races completed', () => { expect(WinRateFormatter.calculate(0, 0)).toBe('0.0'); }); it('should calculate win rate correctly', () => { expect(WinRateFormatter.calculate(10, 5)).toBe('50.0'); expect(WinRateFormatter.calculate(100, 25)).toBe('25.0'); expect(WinRateFormatter.calculate(100, 75)).toBe('75.0'); }); it('should handle 100% win rate', () => { expect(WinRateFormatter.calculate(10, 10)).toBe('100.0'); }); it('should handle 0% win rate', () => { expect(WinRateFormatter.calculate(10, 0)).toBe('0.0'); }); it('should handle decimal win rates', () => { expect(WinRateFormatter.calculate(10, 3)).toBe('30.0'); expect(WinRateFormatter.calculate(10, 7)).toBe('70.0'); }); }); describe('format', () => { it('should format rate with 1 decimal place and % sign', () => { expect(WinRateFormatter.format(50.0)).toBe('50.0%'); expect(WinRateFormatter.format(25.5)).toBe('25.5%'); expect(WinRateFormatter.format(100.0)).toBe('100.0%'); }); it('should handle null rate', () => { expect(WinRateFormatter.format(null)).toBe('0.0%'); }); it('should handle undefined rate', () => { expect(WinRateFormatter.format(undefined)).toBe('0.0%'); }); it('should handle zero rate', () => { expect(WinRateFormatter.format(0)).toBe('0.0%'); }); it('should handle decimal rates', () => { expect(WinRateFormatter.format(12.34)).toBe('12.3%'); expect(WinRateFormatter.format(99.99)).toBe('100.0%'); }); }); });