import { describe, it, expect } from 'vitest';
import { rollAbilityScores, pointBuySpent, pointBuyRemaining, pointCost, STANDARD_ARRAY } from './abilityGen';
import { createRng } from '@/lib/rng';

describe('ability generation', () => {
  it('standard array is the canonical spread', () => {
    expect([...STANDARD_ARRAY]).toEqual([15, 14, 13, 12, 10, 8]);
  });

  it('rolls six scores each in 3..18', () => {
    const scores = rollAbilityScores(createRng('chargen'));
    expect(scores).toHaveLength(6);
    for (const s of scores) {
      expect(s).toBeGreaterThanOrEqual(3);
      expect(s).toBeLessThanOrEqual(18);
    }
  });

  it('point-buy costs match the standard table', () => {
    expect(pointCost(8)).toBe(0);
    expect(pointCost(13)).toBe(5);
    expect(pointCost(15)).toBe(9);
    expect(pointCost(16)).toBeNull();
    expect(pointCost(7)).toBeNull();
  });

  it('27-point standard build is exactly spent', () => {
    // all 13s costs 30 (>27), but 15,15,15,8,8,8 = 9+9+9 = 27
    expect(pointBuySpent([15, 15, 15, 8, 8, 8])).toBe(27);
    expect(pointBuyRemaining([15, 15, 15, 8, 8, 8])).toBe(0);
    expect(pointBuyRemaining([8, 8, 8, 8, 8, 8])).toBe(27);
    expect(pointBuySpent([16, 8, 8, 8, 8, 8])).toBe(Infinity);
  });
});
