45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
|
|
import { Position } from './Position';
|
|
|
|
describe('Position', () => {
|
|
describe('create', () => {
|
|
it('should create a Position with valid positive integer', () => {
|
|
const position = Position.create(1);
|
|
expect(position.toNumber()).toBe(1);
|
|
});
|
|
|
|
it('should throw error for zero', () => {
|
|
expect(() => Position.create(0)).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should throw error for negative number', () => {
|
|
expect(() => Position.create(-1)).toThrow(RacingDomainValidationError);
|
|
});
|
|
|
|
it('should throw error for non-integer', () => {
|
|
expect(() => Position.create(1.5)).toThrow(RacingDomainValidationError);
|
|
});
|
|
});
|
|
|
|
describe('toNumber', () => {
|
|
it('should return the number value', () => {
|
|
const position = Position.create(5);
|
|
expect(position.toNumber()).toBe(5);
|
|
});
|
|
});
|
|
|
|
describe('equals', () => {
|
|
it('should return true for equal positions', () => {
|
|
const pos1 = Position.create(2);
|
|
const pos2 = Position.create(2);
|
|
expect(pos1.equals(pos2)).toBe(true);
|
|
});
|
|
|
|
it('should return false for different positions', () => {
|
|
const pos1 = Position.create(2);
|
|
const pos2 = Position.create(3);
|
|
expect(pos1.equals(pos2)).toBe(false);
|
|
});
|
|
});
|
|
}); |