import t from 'tap';
import { reorderElements } from './collections.js';

void t.test('reorderElements', (t) => {
    const checkReordering = (
        oldIndex: number,
        newIndex: number,
        expected: string,
    ) => {
        t.matchOnlyStrict(
            reorderElements('abcde'.split(''), oldIndex, newIndex),
            expected.split(''),
        );
    };

    checkReordering(0, -1, 'bcde');
    checkReordering(1, -1, 'acde');
    checkReordering(2, -1, 'abde');
    checkReordering(3, -1, 'abce');
    checkReordering(4, -1, 'abcd');
    checkReordering(5, -1, 'abcde');

    checkReordering(0, 0, 'abcde');
    checkReordering(0, 1, 'bacde');
    checkReordering(0, 2, 'bcade');
    checkReordering(0, 3, 'bcdae');
    checkReordering(0, 4, 'bcdea');
    checkReordering(1, 0, 'bacde');
    checkReordering(1, 1, 'abcde');
    checkReordering(1, 2, 'acbde');
    checkReordering(1, 3, 'acdbe');
    checkReordering(1, 4, 'acdeb');
    checkReordering(2, 0, 'cabde');
    checkReordering(2, 1, 'acbde');
    checkReordering(2, 2, 'abcde');
    checkReordering(2, 3, 'abdce');
    checkReordering(2, 4, 'abdec');
    checkReordering(3, 0, 'dabce');
    checkReordering(3, 1, 'adbce');
    checkReordering(3, 2, 'abdce');
    checkReordering(3, 3, 'abcde');
    checkReordering(3, 4, 'abced');
    checkReordering(4, 0, 'eabcd');
    checkReordering(4, 1, 'aebcd');
    checkReordering(4, 2, 'abecd');
    checkReordering(4, 3, 'abced');
    checkReordering(4, 4, 'abcde');
    t.end();
});
