/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { strict as assert } from "assert";
import { noFailure, verifyChangeRebaser } from "../../core/index.js";
const counterRebaser = {
    compose: (changes) => changes.map((c) => c.change).reduce((a, b) => a + b, 0),
    invert: (change) => -change.change,
    rebase: (change, over) => change,
};
const incorrectCounterRebaser = {
    compose: (changes) => changes.map((c) => c.change).reduce((a, b) => a + b - 1, 0),
    invert: (change) => -change.change + 1,
    rebase: (change, over) => change + 1,
};
describe("verifyChangeRebaser", () => {
    it("test counter with safe integers", () => {
        const output = verifyChangeRebaser(counterRebaser, new Set([-1, 2, 3, 0, -2, 4]), isEquivalent);
        assert.deepEqual(output, noFailure);
    });
    it("test counter with unsafe integers", () => {
        const output = verifyChangeRebaser(counterRebaser, new Set([Number.MAX_SAFE_INTEGER, -10, 2]), isEquivalent);
        assert.deepEqual(output.rebaseLeftDistributivity, []);
        assert(output.composeAssociativity.length > 0);
        assert.deepEqual(output.rebaseRightDistributivity, []);
        assert.deepEqual(output.rebaseOverDoUndoPairIsNoOp, []);
        assert.deepEqual(output.rebaseOverUndoRedoPairIsNoOp, []);
        assert.deepEqual(output.composeWithInverseIsNoOp, []);
        assert.deepEqual(output.composeWithEmptyIsNoOp, []);
        assert.deepEqual(output.rebaseOverEmptyIsNoOp, []);
        assert.deepEqual(output.rebaseEmptyIsEmpty, []);
        assert.deepEqual(output.emptyInverseIsEmpty, []);
    });
    it("test incorrect counter with safe integers", () => {
        const output = verifyChangeRebaser(incorrectCounterRebaser, new Set([-1, 2, 3, 0, -2, 4]), isEquivalent);
        assert(output.rebaseLeftDistributivity.length > 0);
        assert(output.composeAssociativity.length > 0);
        assert(output.rebaseRightDistributivity.length > 0);
        assert(output.rebaseOverDoUndoPairIsNoOp.length > 0);
        assert(output.rebaseOverUndoRedoPairIsNoOp.length > 0);
        assert(output.composeWithInverseIsNoOp.length > 0);
        assert(output.composeWithEmptyIsNoOp.length > 0);
        assert(output.rebaseOverEmptyIsNoOp.length > 0);
        assert(output.rebaseEmptyIsEmpty.length > 0);
        assert(output.emptyInverseIsEmpty.length > 0);
    });
});
function isEquivalent(a, b) {
    return a === b || (isNaN(a) && isNaN(b));
}
//# sourceMappingURL=verifyChangeRebaser.spec.js.map