-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Bijnagte/seed-random
resolves #16 control seed for random generators
- Loading branch information
Showing
41 changed files
with
560 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,7 @@ include::combine.adoc[] | |
|
||
include::cardinality.adoc[] | ||
|
||
include::output.adoc[] | ||
|
||
include::development.adoc[] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
== Output | ||
Some times you need to control the output of a generator. | ||
|
||
=== Seeding random generation | ||
|
||
For random generators it can be useful to control the seed for random generation. | ||
This will cause a consistent sequence of values to be generated by an equivalent generator. | ||
|
||
[source,groovy] | ||
---- | ||
include::{testDir}/spock/genesis/SamplesSpec.groovy[tags=seed,indent=0] | ||
---- | ||
|
||
Setting the seed to different values will vary the output but will always produce the same sequence. | ||
[source,groovy] | ||
---- | ||
include::{testDir}/spock/genesis/SamplesSpec.groovy[tags=differentseed,indent=0] | ||
---- | ||
|
||
=== Using `with` | ||
|
||
You can use `with` if you would like to set some property of the | ||
generated value. | ||
|
||
IMPORTANT: `with` is different from the default groovy implementation! It always returns a new generator. | ||
|
||
[source,groovy] | ||
---- | ||
include::{testDir}/spock/genesis/SamplesSpec.groovy[tags=datewith,indent=0] | ||
---- | ||
|
||
=== Transforming with `map` | ||
|
||
Sometimes output needs to be converted to another type. the `map` method works | ||
like groovy's `collect` but will return a new generator that lazily performs the | ||
transformation. An example would be calling the `toString()` method. | ||
|
||
[source,groovy] | ||
---- | ||
include::{testDir}/spock/genesis/SamplesSpec.groovy[tags=transform,indent=0] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.