import { describe, it, expect } from 'vitest';
import { inPlayProbs } from './inplay';

describe('inPlayProbs', () => {
  it('sums to 1 and roughly matches pre-match at kickoff', () => {
    const p = inPlayProbs(1.8, 0.9, 0, 0, 0);
    expect(p.home + p.draw + p.away).toBeCloseTo(1, 6);
    expect(p.home).toBeGreaterThan(p.away); // stronger side favoured
  });

  it('locks the result at full time', () => {
    expect(inPlayProbs(1.5, 1.2, 90, 2, 1)).toEqual({ home: 1, draw: 0, away: 0 });
    expect(inPlayProbs(1.5, 1.2, 95, 1, 1)).toEqual({ home: 0, draw: 1, away: 0 });
    expect(inPlayProbs(1.5, 1.2, 90, 0, 2)).toEqual({ home: 0, draw: 0, away: 1 });
  });

  it('a lead becomes more decisive as time runs down', () => {
    const early = inPlayProbs(1.4, 1.4, 20, 1, 0);
    const late = inPlayProbs(1.4, 1.4, 80, 1, 0);
    expect(late.home).toBeGreaterThan(early.home);
    expect(late.away).toBeLessThan(early.away);
  });

  it('chasing team still has hope early but little late', () => {
    const trailingEarly = inPlayProbs(1.3, 1.3, 30, 0, 1).home;
    const trailingLate = inPlayProbs(1.3, 1.3, 85, 0, 1).home;
    expect(trailingEarly).toBeGreaterThan(trailingLate);
    expect(trailingLate).toBeLessThan(0.1);
  });
});
