"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
const assert_1 = __importDefault(require("assert"));
const ordinal_1 = require("../ordinal.cjs");
const mergeTreeOperationRunner_1 = require("./mergeTreeOperationRunner.cjs");
function computeNumericOrdinal(index) {
    const prefixLen = Math.floor(index / 0xffff);
    const prefix = String.fromCharCode(0xffff).repeat(prefixLen);
    return `${prefix}${String.fromCharCode(index - prefixLen * 0xffff)}`;
}
describe("MergeTree.ordinals", () => {
    (0, mergeTreeOperationRunner_1.doOverRange)({ min: 1, max: 16 }, (i) => i + 1, (max) => {
        let parentOrdinal = String.fromCharCode(0);
        it(`Max ${max}`, () => {
            (0, mergeTreeOperationRunner_1.doOverRange)({ min: 1, max }, (i) => i + 1, (count) => {
                let previous = "";
                for (let i = 0; i < count; i++) {
                    const current = (0, ordinal_1.computeHierarchicalOrdinal)(max, count, parentOrdinal, previous);
                    (0, assert_1.default)(current > previous, "subsequent ordinal should be greater than previous");
                    (0, assert_1.default)(current.length > parentOrdinal.length, "child ordinals should be  more than parent");
                    previous = current;
                }
                parentOrdinal = previous ?? parentOrdinal;
            });
        });
    });
    it("numericOrdinal", () => {
        let previous = String.fromCharCode(0);
        for (let i = 2; i < Number.MAX_SAFE_INTEGER; i = Math.pow(i, 2)) {
            const current = computeNumericOrdinal(i);
            (0, assert_1.default)(current > previous, `subsequent ordinal should be greater than previous ${i.toString(16)}`);
            previous = current;
        }
    });
});
//# sourceMappingURL=ordinal.spec.cjs.map