import { describe, it, expect } from 'vitest';
import { hashStringSeed, seededShuffle } from '@/lib/shuffle';

describe('seededShuffle', () => {
  it('ist deterministisch fuer denselben Seed', () => {
    const input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    const a = seededShuffle(input, 1234);
    const b = seededShuffle(input, 1234);
    expect(a).toEqual(b);
  });

  it('ist eine Permutation (gleiche Elemente, keine Duplikate)', () => {
    const input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    const out = seededShuffle(input, 42);
    expect(out).toHaveLength(input.length);
    expect([...out].sort((x, y) => x - y)).toEqual([...input].sort((x, y) => x - y));
  });

  it('laesst das Original-Array unveraendert', () => {
    const input = [1, 2, 3, 4, 5];
    seededShuffle(input, 7);
    expect(input).toEqual([1, 2, 3, 4, 5]);
  });

  it('liefert fuer unterschiedliche Seeds in der Regel unterschiedliche Reihenfolgen', () => {
    const input = Array.from({ length: 100 }, (_, i) => i);
    const a = seededShuffle(input, 1);
    const b = seededShuffle(input, 2);
    expect(a).not.toEqual(b);
  });

  it('hashStringSeed liefert stabile 32-Bit-Werte', () => {
    expect(hashStringSeed('abc')).toBe(hashStringSeed('abc'));
    expect(hashStringSeed('abc')).not.toBe(hashStringSeed('abd'));
  });
});
