import { describe, it, expect } from 'vitest';
import { XP_RAW, xpForLevel, levelFromXp } from '@domain/value-objects/XpTable';

describe('XpTable', () => {
  it('has 200 entries', () => {
    expect(Object.keys(XP_RAW)).toHaveLength(200);
  });

  it('level 1 requires 0 XP', () => {
    expect(xpForLevel(1)).toBe(0);
  });

  it('level 200 requires 867582 XP', () => {
    expect(xpForLevel(200)).toBe(867582);
  });

  it('clamps below 1', () => {
    expect(xpForLevel(0)).toBe(0);
    expect(xpForLevel(-5)).toBe(0);
  });

  it('clamps above 200', () => {
    expect(xpForLevel(250)).toBe(867582);
  });

  it('levelFromXp returns correct level', () => {
    expect(levelFromXp(0)).toBe(1);
    expect(levelFromXp(18)).toBe(1);
    expect(levelFromXp(19)).toBe(2);
    expect(levelFromXp(867582)).toBe(200);
    expect(levelFromXp(999999)).toBe(200);
  });

  it('roundtrip: xpForLevel → levelFromXp', () => {
    for (let lvl = 1; lvl <= 200; lvl++) {
      expect(levelFromXp(xpForLevel(lvl))).toBe(lvl);
    }
  });

  it('XP values are monotonically increasing', () => {
    for (let lvl = 2; lvl <= 200; lvl++) {
      expect(XP_RAW[lvl]!).toBeGreaterThan(XP_RAW[lvl - 1]!);
    }
  });
});
