Files
gridpilot.gg/core/racing/domain/services/StrengthOfFieldCalculator.test.ts
2026-01-24 12:18:31 +01:00

36 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { AverageStrengthOfFieldCalculator, DriverRating } from './StrengthOfFieldCalculator';
describe('AverageStrengthOfFieldCalculator', () => {
const calculator = new AverageStrengthOfFieldCalculator();
it('should return null for empty list', () => {
expect(calculator.calculate([])).toBeNull();
});
it('should return null if no valid ratings (>0)', () => {
const ratings: DriverRating[] = [
{ driverId: '1', rating: 0 },
{ driverId: '2', rating: -100 },
];
expect(calculator.calculate(ratings)).toBeNull();
});
it('should calculate average of valid ratings', () => {
const ratings: DriverRating[] = [
{ driverId: '1', rating: 1000 },
{ driverId: '2', rating: 2000 },
{ driverId: '3', rating: 0 }, // Should be ignored
];
expect(calculator.calculate(ratings)).toBe(1500);
});
it('should round the result', () => {
const ratings: DriverRating[] = [
{ driverId: '1', rating: 1000 },
{ driverId: '2', rating: 1001 },
];
expect(calculator.calculate(ratings)).toBe(1001); // (1000+1001)/2 = 1000.5 -> 1001
});
});