import { describe, it, expect } from 'vitest';
import { americanToDecimal, deVig, overround } from './odds';

describe('americanToDecimal', () => {
  it('converts favourites and underdogs', () => {
    expect(americanToDecimal(-235)).toBeCloseTo(1.4255, 3);
    expect(americanToDecimal(340)).toBeCloseTo(4.4, 3);
    expect(americanToDecimal(100)).toBeCloseTo(2.0, 6);
    expect(americanToDecimal(-100)).toBeCloseTo(2.0, 6);
  });
});

describe('deVig', () => {
  it('produces probabilities that sum to 1 with the margin removed', () => {
    // tonight's real opening-match lines: Mexico -235 / draw +340 / SA +750
    const p = deVig(-235, 340, 750)!;
    expect(p.home + p.draw + p.away).toBeCloseTo(1, 9);
    expect(p.home).toBeGreaterThan(0.6); // heavy favourite
    expect(p.away).toBeLessThan(0.15);
    // raw implied sum exceeds 1 (the vig)
    expect(overround(-235, 340, 750)).toBeGreaterThan(1);
  });

  it('returns null on missing lines', () => {
    expect(deVig(null, 340, 750)).toBeNull();
    expect(deVig(-235, 0, 750)).toBeNull();
  });
});
