Initial commit
This commit is contained in:
commit
b3a51a4115
10336 changed files with 2381973 additions and 0 deletions
38
node_modules/fast-check/lib/esm/arbitrary/_internals/AdapterArbitrary.js
generated
vendored
Normal file
38
node_modules/fast-check/lib/esm/arbitrary/_internals/AdapterArbitrary.js
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { Arbitrary } from '../../check/arbitrary/definition/Arbitrary.js';
|
||||
import { Value } from '../../check/arbitrary/definition/Value.js';
|
||||
import { Stream } from '../../stream/Stream.js';
|
||||
const AdaptedValue = Symbol('adapted-value');
|
||||
function toAdapterValue(rawValue, adapter) {
|
||||
const adapted = adapter(rawValue.value_);
|
||||
if (!adapted.adapted) {
|
||||
return rawValue;
|
||||
}
|
||||
return new Value(adapted.value, AdaptedValue);
|
||||
}
|
||||
class AdapterArbitrary extends Arbitrary {
|
||||
constructor(sourceArb, adapter) {
|
||||
super();
|
||||
this.sourceArb = sourceArb;
|
||||
this.adapter = adapter;
|
||||
this.adaptValue = (rawValue) => toAdapterValue(rawValue, adapter);
|
||||
}
|
||||
generate(mrng, biasFactor) {
|
||||
const rawValue = this.sourceArb.generate(mrng, biasFactor);
|
||||
return this.adaptValue(rawValue);
|
||||
}
|
||||
canShrinkWithoutContext(value) {
|
||||
return this.sourceArb.canShrinkWithoutContext(value) && !this.adapter(value).adapted;
|
||||
}
|
||||
shrink(value, context) {
|
||||
if (context === AdaptedValue) {
|
||||
if (!this.sourceArb.canShrinkWithoutContext(value)) {
|
||||
return Stream.nil();
|
||||
}
|
||||
return this.sourceArb.shrink(value, undefined).map(this.adaptValue);
|
||||
}
|
||||
return this.sourceArb.shrink(value, context).map(this.adaptValue);
|
||||
}
|
||||
}
|
||||
export function adapter(sourceArb, adapter) {
|
||||
return new AdapterArbitrary(sourceArb, adapter);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue