"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_assert_1 = __importDefault(require("node:assert"));
const ordinal_js_1 = require("../ordinal.js");
const mergeTreeOperationRunner_js_1 = require("./mergeTreeOperationRunner.js");
function computeNumericOrdinal(index) {
    const prefixLen = Math.floor(index / 0xffff);
    // Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.
    // The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.
    // eslint-disable-next-line unicorn/prefer-code-point
    const prefix = String.fromCharCode(0xffff).repeat(prefixLen);
    // eslint-disable-next-line unicorn/prefer-code-point
    return `${prefix}${String.fromCharCode(index - prefixLen * 0xffff)}`;
}
describe("MergeTree.ordinals", () => {
    (0, mergeTreeOperationRunner_js_1.doOverRange)({ min: 1, max: 16 }, (i) => i + 1, (max) => {
        // eslint-disable-next-line unicorn/prefer-code-point
        let parentOrdinal = String.fromCharCode(0);
        it(`Max ${max}`, () => {
            (0, mergeTreeOperationRunner_js_1.doOverRange)({ min: 1, max }, (i) => i + 1, (count) => {
                let previous = "";
                for (let i = 0; i < count; i++) {
                    const current = (0, ordinal_js_1.computeHierarchicalOrdinal)(max, count, parentOrdinal, previous);
                    (0, node_assert_1.default)(current > previous, "subsequent ordinal should be greater than previous");
                    (0, node_assert_1.default)(current.length > parentOrdinal.length, "child ordinals should be  more than parent");
                    previous = current;
                }
                parentOrdinal = previous ?? parentOrdinal;
            });
        });
    });
    it("numericOrdinal", () => {
        // eslint-disable-next-line unicorn/prefer-code-point
        let previous = String.fromCharCode(0);
        for (let i = 2; i < Number.MAX_SAFE_INTEGER; i = Math.pow(i, 2)) {
            const current = computeNumericOrdinal(i);
            (0, node_assert_1.default)(current > previous, `subsequent ordinal should be greater than previous ${i.toString(16)}`);
            previous = current;
        }
    });
});
//# sourceMappingURL=ordinal.spec.js.map