本文整理汇总了Scala中org.typelevel.discipline.scalatest.Discipline类的典型用法代码示例。如果您正苦于以下问题:Scala Discipline类的具体用法?Scala Discipline怎么用?Scala Discipline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Discipline类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: arbNewtype
//设置package包名称以及导入依赖的类
package newts
import cats.instances.AllInstances
import newts.syntax.AllSyntax
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}
import org.typelevel.discipline.scalatest.Discipline
trait NewtsSuite extends FunSuite
with Matchers
with GeneratorDrivenPropertyChecks
with Discipline
with AllSyntax
with AllInstances
with cats.syntax.AllSyntax
with ArbitraryInstances
trait ArbitraryInstances {
def arbNewtype[S, A: Arbitrary](implicit newtype: Newtype.Aux[S, A]): Arbitrary[S] =
Arbitrary(arbitrary[A].map(newtype.wrap))
def cogenNewtype[S, A: Cogen](implicit newtype: Newtype.Aux[S, A]): Cogen[S] =
Cogen[A].contramap(newtype.unwrap)
implicit val allArbitrary: Arbitrary[All] = arbNewtype[All, Boolean]
implicit val anyArbitrary: Arbitrary[Any] = arbNewtype[Any, Boolean]
implicit def multArbitrary[A:Arbitrary]: Arbitrary[Mult[A]] = arbNewtype[Mult[A], A]
implicit def dualArbitrary[A: Arbitrary]: Arbitrary[Dual[A]] = arbNewtype[Dual[A], A]
implicit def firstArbitrary[A: Arbitrary]: Arbitrary[First[A]] = arbNewtype[First[A], A]
implicit def lastArbitrary[A: Arbitrary]: Arbitrary[Last[A]] = arbNewtype[Last[A], A]
implicit def firstOptionArbitrary[A: Arbitrary]: Arbitrary[FirstOption[A]] = arbNewtype[FirstOption[A], Option[A]]
implicit def lastOptionArbitrary[A: Arbitrary]: Arbitrary[LastOption[A]] = arbNewtype[LastOption[A], Option[A]]
implicit def minArbitrary[A: Arbitrary]: Arbitrary[Min[A]] = arbNewtype[Min[A], A]
implicit def maxArbitrary[A: Arbitrary]: Arbitrary[Max[A]] = arbNewtype[Max[A], A]
implicit def zipListArbitrary[A: Arbitrary]: Arbitrary[ZipList[A]] = arbNewtype[ZipList[A], List[A]]
implicit val allCogen: Cogen[All] = cogenNewtype[All, Boolean]
implicit val anyCogen: Cogen[Any] = cogenNewtype[Any, Boolean]
implicit def multCogen[A: Cogen]: Cogen[Mult[A]] = cogenNewtype[Mult[A], A]
implicit def dualCogen[A: Cogen]: Cogen[Dual[A]] = cogenNewtype[Dual[A], A]
implicit def firstCogen[A: Cogen]: Cogen[First[A]] = cogenNewtype[First[A], A]
implicit def lastCogen[A: Cogen]: Cogen[Last[A]] = cogenNewtype[Last[A], A]
implicit def firstOptionCogen[A: Cogen]: Cogen[FirstOption[A]] = cogenNewtype[FirstOption[A], Option[A]]
implicit def lastOptionCogen[A: Cogen] : Cogen[LastOption[A]] = cogenNewtype[LastOption[A], Option[A]]
implicit def minOptionCogen[A: Cogen] : Cogen[Min[A]] = cogenNewtype[Min[A], A]
implicit def maxOptionCogen[A: Cogen] : Cogen[Max[A]] = cogenNewtype[Max[A], A]
implicit def zipListCogen[A: Cogen]: Cogen[ZipList[A]] = cogenNewtype[ZipList[A], List[A]]
}
示例2: FormatInstancesSpec
//设置package包名称以及导入依赖的类
package com.iravid.playjsoncats
import org.scalatest.FunSuite
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.typelevel.discipline.scalatest.Discipline
import cats.laws.discipline._
import cats.kernel.instances.all._
import play.api.libs.json.{ Format, Writes, Reads }
class FormatInstancesSpec extends FunSuite with Discipline with GeneratorDrivenPropertyChecks with FormatInstances {
import Arbitraries._
checkAll("Format", InvariantTests[Format].invariant[String, String, String])
}
class ReadsInstancesSpec extends FunSuite with Discipline with GeneratorDrivenPropertyChecks with ReadsInstances {
import Arbitraries._
checkAll("Reads", FunctorTests[Reads].functor[String, String, String])
checkAll("Reads", ApplicativeTests[Reads].applicative[String, String, String])
checkAll("Reads", MonadTests[Reads].monad[String, String, String])
}
class WritesInstancesSpec extends FunSuite with Discipline with GeneratorDrivenPropertyChecks with WritesInstances {
import Arbitraries._
checkAll("Reads", ContravariantTests[Writes].contravariant[String, String, String])
}
示例3: genDateTimeFromSameOffsetPeriod
//设置package包名称以及导入依赖的类
package dtc.tests
import java.time.temporal.ChronoField
import java.time.temporal.ChronoUnit._
import java.time.{Duration, LocalDate, LocalTime}
import dtc.TimeZoneId
import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuiteLike, Matchers}
import org.typelevel.discipline.scalatest.Discipline
trait DTCSuite extends FunSuiteLike
with Matchers
with GeneratorDrivenPropertyChecks
with Discipline {
override implicit val generatorDrivenConfig: PropertyCheckConfiguration = PropertyCheckConfiguration(
minSuccessful = 100
)
private val nanoOfDayRange = ChronoField.NANO_OF_DAY.range()
val genLocalTime: Gen[LocalTime] =
Gen.choose(nanoOfDayRange.getMinimum, nanoOfDayRange.getMaximum).map(LocalTime.ofNanoOfDay)
implicit val arbLocalTime: Arbitrary[LocalTime] = Arbitrary(genLocalTime)
val genDuration: Gen[Duration] =
Gen.choose(Long.MinValue / 1000, Long.MaxValue / 1000)
.map(l => Duration.of(l, MILLIS))
implicit val arbDuration = Arbitrary(genDuration)
def genDateTimeFromSameOffsetPeriod(period: SameZoneOffsetPeriod): Gen[(LocalDate, LocalTime, TimeZoneId)] = for {
date <- Gen.choose(period.startDate.toEpochDay + 1L, period.endDate.toEpochDay - 1L).map(LocalDate.ofEpochDay)
timeBounds <- Gen.const(
if (date == period.startDate && date == period.endDate) (period.startTime, period.endTime)
else if (date == period.startDate) (period.startTime, LocalTime.MAX)
else if (date == period.endDate) (LocalTime.MAX, period.endTime)
else (LocalTime.MIN, LocalTime.MAX)
)
time <- Gen.choose(timeBounds._1.toNanoOfDay, timeBounds._2.toNanoOfDay).map(LocalTime.ofNanoOfDay)
} yield (date, time, period.zone)
}