-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate random decimals with decimal points
- Loading branch information
Ronald Holshausen
committed
Sep 20, 2020
1 parent
62bdb1e
commit 6e0b293
Showing
2 changed files
with
40 additions
and
1 deletion.
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
23 changes: 23 additions & 0 deletions
23
.../src/test/groovy/au/com/dius/pact/core/model/generators/RandomDecimalGeneratorSpec.groovy
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,23 @@ | ||
package au.com.dius.pact.core.model.generators | ||
|
||
import spock.lang.Rollup | ||
import spock.lang.Specification | ||
|
||
class RandomDecimalGeneratorSpec extends Specification { | ||
|
||
@Rollup | ||
def 'generates a value with a decimal point and only a leading zero if the point is in the second position'() { | ||
given: | ||
def generator = new RandomDecimalGenerator(8) | ||
|
||
expect: | ||
with(generator.generate([:]).toString()) { | ||
it.length() == 9 | ||
it ==~ /^\d+\.\d+/ | ||
it[0] != '0' || (it[0] == '0' && it[1] == '.') | ||
} | ||
|
||
where: | ||
_samples << (1..100).step(1) | ||
} | ||
} |