// Quality Intelligence coverage map (Epic #270, Issue #277).
//
// A coverage map relates evidence atoms to the test-case candidates derived from
// them, with a per-mapping confidence in the half-closed range [0, 1]. The runtime
// helper `assertCoverageMapInvariant` enforces the float bound. Pure; no IO.
export const QUALITY_INTELLIGENCE_COVERAGE_KINDS = [
    "derived",
    "asserted",
    "manual",
];
const isValidConfidence = (value) => Number.isFinite(value) && value >= 0 && value <= 1;
/**
 * Throws `RangeError` on any out-of-range confidence (NaN, ±Infinity, < 0, > 1) and
 * on a mapping with an empty `candidateIds` list. Returns `void` on success.
 */
export const assertCoverageMapInvariant = (map) => {
    for (let index = 0; index < map.mappings.length; index += 1) {
        const mapping = map.mappings[index];
        if (mapping === undefined) {
            throw new RangeError(`Coverage map mapping[${String(index)}] is missing`);
        }
        if (!isValidConfidence(mapping.confidence)) {
            throw new RangeError(`Coverage map mapping[${String(index)}] has out-of-range confidence ${String(mapping.confidence)}`);
        }
        if (mapping.candidateIds.length === 0) {
            throw new RangeError(`Coverage map mapping[${String(index)}] must reference at least one candidate`);
        }
    }
};
