Reputation: 1518
How can I write a generator for the second argument someBoundedInt which will generate an Int randomly between the values generated for minmaxBound?
val boundedIntProperty = forAll {
(minmaxBound: (Int,Int), someBoundedInt: Int) =>
minmaxBound._1 <= someBoundedInt && someBoundedInt <= minmaxBound._2
}
Upvotes: 2
Views: 370
Reputation: 1443
You can nest calls to forAll
like this:
val boundedIntProperty = forAll { (minBound: Int, maxBound: Int) =>
forAll( Gen.choose(minBound, maxBound) ) { someBoundedInt =>
...
}
}
Note that above, minBound
can be larger than maxBound
sometimes, which will make Gen.choose
fail (not produce a value). So you probably want to generate your bounds in a smarter way too.
Upvotes: 6