campus-errand/miniapp/node_modules/fast-check/lib/arbitrary/option.js
2026-03-01 05:01:47 +08:00

20 lines
893 B
JavaScript

import { constant } from './constant.js';
import { FrequencyArbitrary } from './_internals/FrequencyArbitrary.js';
import { safeHasOwnProperty } from '../utils/globals.js';
export /**@__NO_SIDE_EFFECTS__*/function option(arb, constraints = {}) {
const freq = constraints.freq == null ? 6 : constraints.freq;
const nilValue = safeHasOwnProperty(constraints, 'nil') ? constraints.nil : null;
const nilArb = constant(nilValue);
const weightedArbs = [
{ arbitrary: nilArb, weight: 1, fallbackValue: { default: nilValue } },
{ arbitrary: arb, weight: freq - 1 },
];
const frequencyConstraints = {
withCrossShrink: true,
depthSize: constraints.depthSize,
maxDepth: constraints.maxDepth,
depthIdentifier: constraints.depthIdentifier,
};
return FrequencyArbitrary.from(weightedArbs, frequencyConstraints, 'fc.option');
}