Skip to content

Commit

Permalink
Add noShrink on Arbitrary base class
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Feb 3, 2018
1 parent b42e538 commit 70c2094
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/check/arbitrary/definition/Arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export default abstract class Arbitrary<T> {
}
return new MappedArbitrary(this, mapper);
}
noShrink(): Arbitrary<T> {
class NoShrinkArbitrary extends Arbitrary<T> {
constructor(readonly arb: Arbitrary<T>) {
super();
}
generate(mrng: MutableRandomGenerator): Shrinkable<T> {
return new Shrinkable(this.arb.generate(mrng).value);
}
}
return new NoShrinkArbitrary(this);
}
}

abstract class ArbitraryWithShrink<T> extends Arbitrary<T> {
Expand Down
10 changes: 10 additions & 0 deletions test/unit/check/arbitrary/definition/Arbitrary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ describe("Arbitrary", () => {
})
));
});
describe('noShrink', () => {
it('Should remove the ability to shrink the arbitrary', () => fc.assert(
fc.property(fc.integer(), (seed) => {
const mrng = stubRng.mutable.fastincrease(seed);
const shrinkable = new ForwardArbitrary().noShrink().generate(mrng);
assert.deepStrictEqual([...shrinkable.shrink()], []);
return true;
})
));
});
});

0 comments on commit 70c2094

Please sign in to comment.