开发者

Help with ScalaCheck

开发者 https://www.devze.com 2023-04-08 22:33 出处:网络
I\'d like to use ScalaTest\'s Checkers trait to use ScalaCheck from ScalaTest cases. A simple case I\'m playing with is:

I'd like to use ScalaTest's Checkers trait to use ScalaCheck from ScalaTest cases.

A simple case I'm playing with is:

 test("can create local date UTC from millis") {
     check(localDate.toTimestampUTC.toLocalDateUTC == localDate)
 }

I need to create a arbitrary LocalDate, so I tried this:

object ArbitraryValues {
    implicit def abc(): Arbitrary[LocalDate] = Arbitrary(Gen.choose(new LocalDate(0L), new LocalDate(Long.MaxValue)))
}

It doesn't compile, saying,

error: could not find implicit value for parameter c: org.scalacheck.Choose[org.joda.time.LocalDate] implicit val abc: Arbitrary[LocalDate] = Arbitrary(Gen.choose(new LocalDate(0L), new LocalDate(Long.MaxValue)))

and

开发者_Go百科

error: not found: value localDate check(localDate.toTimestampUTC.toLocalDateUTC == localDate)


Ok figured it out through trial and error. My working code looks like this:

object ArbitraryValues {
    implicit val abc: Arbitrary[LocalDate] = Arbitrary(Gen.choose(0L, Long.MaxValue).map(new LocalDate(_)))
}

test("can create local date UTC from millis -and- vice versa") { check((localDate: LocalDate) =>
    localDate.toTimestampUTC.toLocalDateUTC == localDate)
}

I had to change the way I was creating the Arbitrary[LocalDate], and then update my syntax for the check.

0

精彩评论

暂无评论...
验证码 换一张
取 消