|
Scala example source code file (TimeTestJVM.scala)
The TimeTestJVM.scala Scala example source codepackage scalaz.std.java import scalaz.{SpecLite, Apply} import java.time._ import org.scalacheck._ import scalaz.syntax.functor._ import scalaz.scalacheck.ScalaCheckBinding._ import scalaz.scalacheck.ScalazProperties import scalaz.scalacheck.ScalazProperties._ import scalaz.std.java.time._ import scala.collection.convert.decorateAsScala._ import TimeTest._ object TimeTestJVM extends SpecLite { private[this] def arb[A](implicit A: Arbitrary[A]): Arbitrary[A] = A private[this] val smallIntArb = Arbitrary(Gen.choose(1, 100000)) implicit val LocalDateTimeArbitrary: Arbitrary[LocalDateTime] = Arbitrary(Apply[Gen].apply7( Gen.choose(Year.MIN_VALUE, Year.MAX_VALUE), Gen.choose(1, 12), Gen.choose(1, 28), Gen.choose(0, 23), Gen.choose(0, 59), Gen.choose(0, 59), Gen.choose(0, 999999999) )(LocalDateTime.of(_, _, _, _, _, _, _))) implicit val InstantArbitrary: Arbitrary[Instant] = arb[Long].map { Instant.ofEpochMilli(_)} implicit val zonedOffsetArbitrary: Arbitrary[ZoneOffset] = Arbitrary( Apply[Gen].apply3(Gen.choose(0, 17), Gen.choose(0, 59), Gen.choose(0, 59))( ZoneOffset.ofHoursMinutesSeconds ) ) implicit val zoneIdArbitrary: Arbitrary[ZoneId] = Arbitrary( Gen.oneOf(ZoneId.getAvailableZoneIds.asScala.map(ZoneId.of)(collection.breakOut)) ) implicit val offsetDateTimeArbitrary: Arbitrary[OffsetDateTime] = Apply[Arbitrary].apply2(arb[LocalDateTime], arb[ZoneOffset])( OffsetDateTime.of(_, _) ) implicit val offsetTimeArbitrary: Arbitrary[OffsetTime] = Apply[Arbitrary].apply2(arb[LocalTime], arb[ZoneOffset])( OffsetTime.of(_, _) ) implicit val zonedDateTimeArbitrary: Arbitrary[ZonedDateTime] = Apply[Arbitrary].apply2(arb[LocalDateTime], arb[ZoneId])( ZonedDateTime.of(_, _) ) checkAll("DayOfWeek", ScalazProperties.enum.laws[DayOfWeek]) checkAll("Instant", order.laws[Instant]) checkAll("LocalDateTime", order.laws[LocalDateTime]) checkAll("OffsetDateTime", order.laws[OffsetDateTime]) checkAll("OffsetTime", order.laws[OffsetTime]) checkAll("ZonedDateTime", order.laws[ZonedDateTime]) checkAll("ZoneOffset", order.laws[ZoneOffset]) } Other Scala examples (source code examples)Here is a short list of links related to this Scala TimeTestJVM.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.