"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const mocha_1 = require("mocha");
const utils_1 = require("../../../src/utils");
const unit_1 = require("../../helpers/unit");
(0, mocha_1.describe)('Partition', () => {
    before(unit_1.unitBeforeHelper);
    after(unit_1.unitAfterHelper);
    it('should split an array of 5 to 5 arrays', () => {
        const testArr = [1, 2, 3, 4, 5];
        const partitioned = (0, utils_1.partition)(testArr, 5);
        (0, chai_1.expect)(partitioned).to.deep.equal([[1, 2, 3, 4, 5]]);
        (0, chai_1.expect)(testArr).to.deep.equal([1, 2, 3, 4, 5]);
    });
    it('should handle 0', () => {
        const testArr = [1, 2, 3, 4, 5];
        const partitioned = (0, utils_1.partition)(testArr, 0);
        (0, chai_1.expect)(partitioned).to.deep.equal([[1], [2], [3], [4], [5]]);
        (0, chai_1.expect)(testArr).to.deep.equal([1, 2, 3, 4, 5]);
    });
    it('should handle one', () => {
        const testArr = [1, 2, 3, 4, 5];
        const partitioned = (0, utils_1.partition)(testArr, 1);
        (0, chai_1.expect)(partitioned).to.deep.equal([[1], [2], [3], [4], [5]]);
        (0, chai_1.expect)(testArr).to.deep.equal([1, 2, 3, 4, 5]);
    });
    it('should handle two', () => {
        const testArr = [1, 2, 3, 4, 5];
        const partitioned = (0, utils_1.partition)(testArr, 2);
        (0, chai_1.expect)(partitioned).to.deep.equal([[1, 2], [3, 4], [5]]);
        (0, chai_1.expect)(testArr).to.deep.equal([1, 2, 3, 4, 5]);
    });
    it('should handle between one and zero', () => {
        const testArr = [1, 2, 3, 4, 5];
        const partitioned = (0, utils_1.partition)(testArr, 0.15);
        (0, chai_1.expect)(partitioned).to.deep.equal([[1], [2], [3], [4], [5]]);
        (0, chai_1.expect)(testArr).to.deep.equal([1, 2, 3, 4, 5]);
    });
    it('should handle different sizes of arrays', () => {
        for (let i = 0; i < 1000; i++) {
            const randomLen = Math.floor(Math.random() * 100) + 1;
            let adjustment = 0;
            const randomArr = new Array(randomLen).fill(1).map(num => num + adjustment++);
            const partitioned = (0, utils_1.partition)(randomArr, 3);
            const amountInBatches = partitioned.reduce((sum, arr) => sum + arr.length, 0);
            (0, chai_1.expect)(amountInBatches).to.equal(randomLen);
            (0, chai_1.expect)(partitioned.length).to.be.gte(Math.floor(randomLen / 3));
            const lastBatch = partitioned[partitioned.length - 1];
            if (!lastBatch) {
                console.error('Array partition fails with length', randomLen);
            }
            (0, chai_1.expect)(randomArr.length).to.deep.equal(randomLen);
        }
    });
});
//# sourceMappingURL=partition.test.js.map