Files
gridpilot.gg/core/racing/domain/services/StrengthOfFieldCalculator.test.ts
2026-01-22 18:05:30 +01:00

55 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { AverageStrengthOfFieldCalculator } from './StrengthOfFieldCalculator';
describe('AverageStrengthOfFieldCalculator', () => {
const calculator = new AverageStrengthOfFieldCalculator();
it('should calculate average SOF and round it', () => {
const ratings = [
{ driverId: 'd1', rating: 1500 },
{ driverId: 'd2', rating: 2000 },
{ driverId: 'd3', rating: 1750 },
];
const sof = calculator.calculate(ratings);
expect(sof).toBe(1750);
});
it('should handle rounding correctly', () => {
const ratings = [
{ driverId: 'd1', rating: 1000 },
{ driverId: 'd2', rating: 1001 },
];
const sof = calculator.calculate(ratings);
expect(sof).toBe(1001); // (1000 + 1001) / 2 = 1000.5 -> 1001
});
it('should return null for empty ratings', () => {
expect(calculator.calculate([])).toBeNull();
});
it('should filter out non-positive ratings', () => {
const ratings = [
{ driverId: 'd1', rating: 1500 },
{ driverId: 'd2', rating: 0 },
{ driverId: 'd3', rating: -100 },
];
const sof = calculator.calculate(ratings);
expect(sof).toBe(1500);
});
it('should return null if all ratings are non-positive', () => {
const ratings = [
{ driverId: 'd1', rating: 0 },
{ driverId: 'd2', rating: -500 },
];
expect(calculator.calculate(ratings)).toBeNull();
});
});