How to change increment value in a scala generator?

178 views Asked by At

I'm trying to create a number that's inside of a range with scalacheck generators like:

Gen.chooseNum(min, max)

But it defaults to the increment value of 1 but I wanted it to increment with 0.5. What is the solution for this?

1

There are 1 answers

0
Cheng Lian On

You can generate integers that are multiples of 5 and then divide them by 10.

Gen.choose(min * 10, max * 10)
  .map(_ / 5 * 5)
  .map(_.toDouble / 10)