import Lines from './Lines';
import { describe, expect, it } from '@jest/globals';

describe('Lines', () =>
{
    const sampleLines = [
        [0, 1, 2],
        [2, 1, 0],
        [1, 1, 1],
    ] as const;

    it('returns clones for the full matrix', () =>
    {
        const lines = new Lines(sampleLines);
        const cloned = lines.lines;

        expect(cloned).toEqual(sampleLines);

        cloned[0] = [9, 9, 9];

        expect(lines.lines).toEqual(sampleLines);
    });

    it('returns clones for a single line', () =>
    {
        const lines = new Lines(sampleLines);
        const line = lines.get(0);

        expect(line).toEqual(sampleLines[0]);

        line[0] = 7;

        expect(lines.get(0)).toEqual(sampleLines[0]);
    });

    it('reports invalid indices', () =>
    {
        const lines = new Lines(sampleLines);

        expect(() => lines.get(-1)).toThrow('There isn\'t a line with the index -1');
        expect(() => lines.get(3)).toThrow('There isn\'t a line with the index 3');
        expect(() => lines.get(1.5)).toThrow('There isn\'t a line with the index 1.5');
    });

    it('validates constructor input', () =>
    {
        expect(() => new Lines(null)).toThrow('Please, provide the Lines with data. use \'Lines.init(your_data)\'');
        expect(() => new Lines(undefined)).toThrow('Please, provide the Lines with data. use \'Lines.init(your_data)\'');
        expect(() => new Lines([1 as unknown as number[]])).toThrow('Line 0 must be an array of reel positions.');
        expect(() => new Lines([[0, 1, 2.5]])).toThrow('Line 0 has invalid reel position at column 2.');
    });

    it('counts available lines', () =>
    {
        const lines = new Lines(sampleLines);

        expect(lines.numberOfLines()).toBe(sampleLines.length);
    });
});
