regularjohn
regularjohn

Reputation: 1

How to change increment value in a scala generator?

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?

Upvotes: 0

Views: 190

Answers (1)

Cheng Lian
Cheng Lian

Reputation: 693

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)

Upvotes: 0

Related Questions