scalacheck icon indicating copy to clipboard operation
scalacheck copied to clipboard

Add java.lang.Integer as Default Arbitrary

Open pete-proton opened this issue 4 years ago • 1 comments

I need to use java.lang.integer, as explained here & was advised by @DanielaSfregola to bring the issue up here.

Now I do it myself

  lazy val jIntGen = Arbitrary.arbitrary[Int].map(_.asInstanceOf[Integer])

but I wonder if it is a biggie to add that to the set of default arbitraries, so to speak. it does not look so bad here, but with nested objects it kind of gets messy.

I guess, it is logical to add other java wrappers like java.lang.Double, lava.lang.Long and etc. if this request makes sense. If it does, I can try to raise a PR myself.

thank you in advance for reviewing the request, Petr

pete-proton avatar Jan 30 '20 13:01 pete-proton

Stumbled upon this one. Note that Java boxed primitives can be null though, so you might want Arbitrary.arbitrary[Option[Int]].map(_.map(_.asInstanceOf[Integer].getOrElse(null))) to cover that edge case.

nevillelyh avatar Aug 03 '20 21:08 nevillelyh