refactor
This commit is contained in:
45
core/racing/domain/value-objects/PointsTable.test.ts
Normal file
45
core/racing/domain/value-objects/PointsTable.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { PointsTable } from './PointsTable';
|
||||
|
||||
describe('PointsTable', () => {
|
||||
it('should create points table from record', () => {
|
||||
const table = new PointsTable({ 1: 25, 2: 18, 3: 15 });
|
||||
expect(table.getPointsForPosition(1)).toBe(25);
|
||||
expect(table.getPointsForPosition(2)).toBe(18);
|
||||
expect(table.getPointsForPosition(3)).toBe(15);
|
||||
});
|
||||
|
||||
it('should create points table from map', () => {
|
||||
const map = new Map([[1, 25], [2, 18]]);
|
||||
const table = new PointsTable(map);
|
||||
expect(table.getPointsForPosition(1)).toBe(25);
|
||||
expect(table.getPointsForPosition(2)).toBe(18);
|
||||
});
|
||||
|
||||
it('should return 0 for invalid positions', () => {
|
||||
const table = new PointsTable({ 1: 25 });
|
||||
expect(table.getPointsForPosition(0)).toBe(0);
|
||||
expect(table.getPointsForPosition(-1)).toBe(0);
|
||||
expect(table.getPointsForPosition(1.5)).toBe(0);
|
||||
expect(table.getPointsForPosition(2)).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
it('should equal same points table', () => {
|
||||
const t1 = new PointsTable({ 1: 25, 2: 18 });
|
||||
const t2 = new PointsTable({ 1: 25, 2: 18 });
|
||||
expect(t1.equals(t2)).toBe(true);
|
||||
});
|
||||
|
||||
it('should not equal different points table', () => {
|
||||
const t1 = new PointsTable({ 1: 25, 2: 18 });
|
||||
const t2 = new PointsTable({ 1: 25, 2: 19 });
|
||||
expect(t1.equals(t2)).toBe(false);
|
||||
});
|
||||
|
||||
it('should not equal table with different size', () => {
|
||||
const t1 = new PointsTable({ 1: 25 });
|
||||
const t2 = new PointsTable({ 1: 25, 2: 18 });
|
||||
expect(t1.equals(t2)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user