Files
gridpilot.gg/core/racing/domain/entities/result/IncidentCount.test.ts
2026-01-16 19:46:49 +01:00

46 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
import { IncidentCount } from './IncidentCount';
describe('IncidentCount', () => {
describe('create', () => {
it('should create an IncidentCount with valid non-negative integer', () => {
const incidentCount = IncidentCount.create(5);
expect(incidentCount.toNumber()).toBe(5);
});
it('should create with zero', () => {
const incidentCount = IncidentCount.create(0);
expect(incidentCount.toNumber()).toBe(0);
});
it('should throw error for negative number', () => {
expect(() => IncidentCount.create(-1)).toThrow(RacingDomainValidationError);
});
it('should throw error for non-integer', () => {
expect(() => IncidentCount.create(1.5)).toThrow(RacingDomainValidationError);
});
});
describe('toNumber', () => {
it('should return the number value', () => {
const incidentCount = IncidentCount.create(3);
expect(incidentCount.toNumber()).toBe(3);
});
});
describe('equals', () => {
it('should return true for equal incident counts', () => {
const ic1 = IncidentCount.create(2);
const ic2 = IncidentCount.create(2);
expect(ic1.equals(ic2)).toBe(true);
});
it('should return false for different incident counts', () => {
const ic1 = IncidentCount.create(2);
const ic2 = IncidentCount.create(3);
expect(ic1.equals(ic2)).toBe(false);
});
});
});