Files
gridpilot.gg/core/racing/domain/entities/result/LapTime.test.ts
2025-12-17 00:33:13 +01:00

45 lines
1.3 KiB
TypeScript

import { LapTime } from './LapTime';
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
describe('LapTime', () => {
describe('create', () => {
it('should create a LapTime with valid non-negative number', () => {
const lapTime = LapTime.create(120.5);
expect(lapTime.toNumber()).toBe(120.5);
});
it('should create with zero', () => {
const lapTime = LapTime.create(0);
expect(lapTime.toNumber()).toBe(0);
});
it('should throw error for negative number', () => {
expect(() => LapTime.create(-1)).toThrow(RacingDomainValidationError);
});
it('should throw error for NaN', () => {
expect(() => LapTime.create(NaN)).toThrow(RacingDomainValidationError);
});
});
describe('toNumber', () => {
it('should return the number value', () => {
const lapTime = LapTime.create(95.2);
expect(lapTime.toNumber()).toBe(95.2);
});
});
describe('equals', () => {
it('should return true for equal lap times', () => {
const lt1 = LapTime.create(100.0);
const lt2 = LapTime.create(100.0);
expect(lt1.equals(lt2)).toBe(true);
});
it('should return false for different lap times', () => {
const lt1 = LapTime.create(100.0);
const lt2 = LapTime.create(101.0);
expect(lt1.equals(lt2)).toBe(false);
});
});
});