|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { calculateIRatingGain, RaceResult } from './iratingGain'; |
| 3 | + |
| 4 | +interface Driver { |
| 5 | + idx: number; |
| 6 | +} |
| 7 | + |
| 8 | +describe('calculateIRatingGain', () => { |
| 9 | + it('should match the sample data results', () => { |
| 10 | + // Sample data from sample.ts |
| 11 | + const sampleData: RaceResult<Driver>[] = [ |
| 12 | + { driver: { idx: 0 }, finishRank: 1, startIRating: 2502, started: true }, |
| 13 | + { driver: { idx: 1 }, finishRank: 2, startIRating: 1202, started: true }, |
| 14 | + { driver: { idx: 2 }, finishRank: 3, startIRating: 1585, started: true }, |
| 15 | + { driver: { idx: 3 }, finishRank: 4, startIRating: 1409, started: true }, |
| 16 | + { driver: { idx: 4 }, finishRank: 5, startIRating: 1531, started: true }, |
| 17 | + { driver: { idx: 5 }, finishRank: 6, startIRating: 967, started: true }, |
| 18 | + { driver: { idx: 6 }, finishRank: 7, startIRating: 1016, started: true }, |
| 19 | + { driver: { idx: 7 }, finishRank: 8, startIRating: 459, started: true }, |
| 20 | + { driver: { idx: 8 }, finishRank: 9, startIRating: 770, started: true }, |
| 21 | + { driver: { idx: 9 }, finishRank: 10, startIRating: 926, started: true }, |
| 22 | + { driver: { idx: 10 }, finishRank: 11, startIRating: 815, started: false }, |
| 23 | + { driver: { idx: 11 }, finishRank: 12, startIRating: 1518, started: false } |
| 24 | + ]; |
| 25 | + |
| 26 | + const results = calculateIRatingGain(sampleData); |
| 27 | + |
| 28 | + // Expected results from sample.ts |
| 29 | + const expectedResults = [ |
| 30 | + { idx: 0, iratingChange: 51.526181519664114 }, |
| 31 | + { idx: 1, iratingChange: 85.93706251432899 }, |
| 32 | + { idx: 2, iratingChange: 45.76839250350699 }, |
| 33 | + { idx: 3, iratingChange: 34.726798295045704 }, |
| 34 | + { idx: 4, iratingChange: 8.75717685896802 }, |
| 35 | + { idx: 5, iratingChange: 22.00892280681238 }, |
| 36 | + { idx: 6, iratingChange: -1.1847185527524153 }, |
| 37 | + { idx: 7, iratingChange: 26.417252365382087 }, |
| 38 | + { idx: 8, iratingChange: -22.43830479379796 }, |
| 39 | + { idx: 9, iratingChange: -54.257888044345336 }, |
| 40 | + { idx: 10, iratingChange: -78.76773919166914 }, |
| 41 | + { idx: 11, iratingChange: -118.49313628114338 } |
| 42 | + ]; |
| 43 | + |
| 44 | + // Compare results with expected values |
| 45 | + results.forEach((result, index) => { |
| 46 | + const expected = expectedResults[index]; |
| 47 | + expect(result.iratingChange).toBe(expected.iratingChange); |
| 48 | + expect(result.raceResult.driver.idx).toBe(expected.idx); |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments