Choose[BigDecimal] Instance?

240 views
Skip to first unread message

Kevin Meredith

unread,
Nov 10, 2016, 12:06:27 PM11/10/16
to scalacheck
Given:

$cat build.sbt 
scalaVersion := "2.11.8"

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"

I created a Gen[Int] with a range from 0 to 100:

import org.scalacheck._

scala> Gen.choose[Int](0, 100)
res0: org.scalacheck.Gen[Int] = org.scalacheck.Gen$$anon$3@3f5d649a

scala> res0.sample
res1: Option[Int] = Some(93)

But it fails with BigDecimal.

scala> Gen.choose[BigDecimal](0, 100)
<console>:15: error: could not find implicit value for parameter c: org.scalacheck.Gen.Choose[BigDecimal]
       Gen.choose[BigDecimal](0, 100)
                             ^


Does it exist?

Dave Stevens

unread,
Nov 10, 2016, 12:18:28 PM11/10/16
to scala...@googlegroups.com
Try this, or some derivation of it.

Gen.choose(0d, 100d).map(BigDecimal.valueOf)
or
Gen.choose(0, 100).map(BigDecimal.valueOf)
> --
> You received this message because you are subscribed to the Google Groups
> "scalacheck" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalacheck+...@googlegroups.com.
> To post to this group, send email to scala...@googlegroups.com.
> Visit this group at https://groups.google.com/group/scalacheck.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages