Skip to content

Allow optional seed to be passed sampleOne #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ sampleOne([ gen.int, gen.alphaNumChar ])
**Parameters**

```
sample(generator[, size])
sample(generator[, size [, seed]])
```

* `generator`: Any *ValueGenerator* object.

* `size`: The size of the value to produce. Default: `30`.

* `seed`: The seed to use for the random number generator. Default: *<Random>*


**Returns**

A single value from `generator`.
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:dependencies [
[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.293"]
[org.clojure/test.check "0.9.0"]]
[org.clojure/test.check "0.10.0-alpha3"]]

:plugins [
[lein-cljsbuild "1.1.5"]]
Expand Down
8 changes: 6 additions & 2 deletions src/testcheck.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,12 @@
(to-array (gen/sample (->gen generator) (or num-samples 10)))))

(defexport sampleOne (fn
[generator size]
(gen/generate (->gen generator) (or size 30))))
([generator]
(gen/generate (->gen generator) 30))
([generator size]
(gen/generate (->gen generator) size))
([generator size seed]
(gen/generate (->gen generator) (or size 30) seed))))



Expand Down
6 changes: 6 additions & 0 deletions test/gen-builders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe('gen builders', () => {
expect(val).toBe(55)
})

it('samples one with a given seed', () => {
const a = sampleOne(gen.int, 1, 1);
const b = sampleOne(gen.int, 1, 1);
expect(a).toBe(b)
})

it('generates an exact value', () => {
const vals = sample(gen.return('wow'), 100)
expect(vals.length).toBe(100)
Expand Down
2 changes: 1 addition & 1 deletion type-definitions/testcheck.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function sample<T>(gen: ValueGenerator<T>, numValues?: number): Array<T>;
*
* By default, values of size 30 are produced.
*/
export function sampleOne<T>(gen: ValueGenerator<T>, size?: number): T;
export function sampleOne<T>(gen: ValueGenerator<T>, size?: number, seed?: number): T;



Expand Down
2 changes: 1 addition & 1 deletion type-definitions/testcheck.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ declare export function sample<T>(gen: ValueGenerator<T>, numValues?: number): A
*
* By default, values of size 30 are produced.
*/
declare export function sampleOne<T>(gen: ValueGenerator<T>, size?: number): T;
declare export function sampleOne<T>(gen: ValueGenerator<T>, size?: number, seed?: number): T;



Expand Down