Skip to content

Commit

Permalink
Add boolean type arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Jan 24, 2018
1 parent 9a3e94a commit fd323bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/check/arbitrary/BooleanArbitrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Arbitrary from './definition/Arbitrary'
import { integer } from './IntegerArbitrary'

function boolean(): Arbitrary<boolean> {
return integer(0, 1).map(v => v == 1);
}

export { boolean };
2 changes: 2 additions & 0 deletions src/fast-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { property } from './check/property/Property'
import Arbitrary from './check/arbitrary/definition/Arbitrary'
import Shrinkable from './check/arbitrary/definition/Shrinkable'
import { array } from './check/arbitrary/ArrayArbitrary'
import { boolean } from './check/arbitrary/BooleanArbitrary'
import { char, ascii, unicode, hexa, base64 } from './check/arbitrary/CharacterArbitrary'
import { constant } from './check/arbitrary/ConstantArbitrary'
import { float, double } from './check/arbitrary/FloatingPointArbitrary'
Expand All @@ -22,6 +23,7 @@ export {
// property definition
property,
// pre-built arbitraries
boolean, // boolean
float, double, // floating point types
integer, nat, // integer types
char, ascii, unicode, hexa, base64, // single character
Expand Down
19 changes: 19 additions & 0 deletions test/unit/check/arbitrary/BooleanArbitrary.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as assert from 'power-assert';
import * as fc from '../../../../lib/fast-check';

import { boolean } from '../../../../src/check/arbitrary/BooleanArbitrary';

import * as stubRng from '../../stubs/generators';

describe("BooleanArbitrary", () => {
describe('boolean', () => {
it('Should produce true and false uniformaly', () => fc.assert(
fc.property(fc.integer(), (seed) => {
const mrng = stubRng.mutable.counter(seed);
const g1 = boolean().generate(mrng).value;
const g2 = boolean().generate(mrng).value;
return (g1 === true && g2 === false) || (g1 === false && g2 === true);
})
));
});
});

0 comments on commit fd323bb

Please sign in to comment.