import { describe, it, expect } from 'vitest';
import { seededRandom, manhattan, lerp, raycast } from '../math';

describe('Math Utilities', () => {
  describe('seededRandom', () => {
    it('should return consistent results for the same seed', () => {
      const rng1 = seededRandom(12345);
      const rng2 = seededRandom(12345);
      
      expect(rng1()).toBe(rng2());
      expect(rng1()).toBe(rng2());
      expect(rng1()).toBe(rng2());
    });

    it('should return different results for different seeds', () => {
      const rng1 = seededRandom(12345);
      const rng2 = seededRandom(67890);
      
      expect(rng1()).not.toBe(rng2());
    });
  });

  describe('raycast', () => {
    it('should return straight horizontal line', () => {
      const points = raycast(0, 0, 3, 0);
      expect(points).toEqual([
        { x: 0, y: 0 },
        { x: 1, y: 0 },
        { x: 2, y: 0 },
        { x: 3, y: 0 }
      ]);
    });

    it('should return straight vertical line', () => {
      const points = raycast(0, 0, 0, 3);
      expect(points).toEqual([
        { x: 0, y: 0 },
        { x: 0, y: 1 },
        { x: 0, y: 2 },
        { x: 0, y: 3 }
      ]);
    });

    it('should return diagonal line', () => {
      const points = raycast(0, 0, 2, 2);
      expect(points).toEqual([
        { x: 0, y: 0 },
        { x: 1, y: 1 },
        { x: 2, y: 2 }
      ]);
    });
  });

  describe('manhattan', () => {
    it('should calculate correct distance', () => {
      expect(manhattan({ x: 0, y: 0 }, { x: 3, y: 4 })).toBe(7);
      expect(manhattan({ x: 1, y: 1 }, { x: 4, y: 5 })).toBe(7);
      expect(manhattan({ x: -1, y: -1 }, { x: -2, y: -2 })).toBe(2);
    });
  });

  describe('lerp', () => {
    it('should interpolate correctly', () => {
      expect(lerp(0, 10, 0.5)).toBe(5);
      expect(lerp(0, 10, 0)).toBe(0);
      expect(lerp(0, 10, 1)).toBe(10);
      expect(lerp(10, 20, 0.5)).toBe(15);
    });
  });
});
