当前位置: 首页>>代码示例>>Scala>>正文


Scala arbitrary类代码示例

本文整理汇总了Scala中org.scalacheck.Arbitrary.arbitrary的典型用法代码示例。如果您正苦于以下问题:Scala arbitrary类的具体用法?Scala arbitrary怎么用?Scala arbitrary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了arbitrary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: MessagesSpec

//设置package包名称以及导入依赖的类
package roc
package postgresql

import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen}
import org.specs2._

final class MessagesSpec extends Specification with ScalaCheck { def is = s2"""

  PasswordMessage
    should MD5 encrypt a password with given salt           $pmEncrypt
                                                                            """

  val pmEncrypt = forAll { (user: String, pm: PasswordMessage, salt: Array[Byte]) =>
    val md = MessageDigest.getInstance("MD5")
    md.update((pm.password+ user).getBytes(StandardCharsets.UTF_8))
    val unsaltedHexStr = md.digest().map(x => "%02x".format(x.byteValue)).foldLeft("")(_ + _)
    val saltedBytes = unsaltedHexStr.getBytes ++ salt
    md.reset()
    md.update(saltedBytes)
    val passwd = md.digest().map(x => "%02x".format(x.byteValue)).foldLeft("md5")(_ + _)
    passwd must_== PasswordMessage.encryptMD5Passwd(user, pm.password, salt)
  }
  
  lazy val genByte: Gen[Byte] = arbitrary[Byte]
  lazy val genSalt: Gen[Array[Byte]] = Gen.containerOfN[Array, Byte](4, genByte)
  lazy val genPasswordMessage: Gen[PasswordMessage] = for {
    password    <-  arbitrary[String]
  } yield new PasswordMessage(password)
  implicit lazy val implicitPasswordMessage: Arbitrary[PasswordMessage] = 
    Arbitrary(genPasswordMessage)
} 
开发者ID:finagle,项目名称:roc,代码行数:36,代码来源:MessageSpec.scala

示例2: ResultsSpec

//设置package包名称以及导入依赖的类
package roc
package postgresql

import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Gen}
import org.specs2._
import org.specs2.mock.Mockito
import org.specs2.specification.core._
import roc.postgresql.failures.ElementNotFoundFailure

final class ResultsSpec extends Specification with ScalaCheck with Mockito { def is = s2"""

  Row
    get(column) must throw ElementNotFound failure for unknown column name  $columnNotFound
                                                                           """
  
  val columnNotFound = forAll { sym: Symbol =>
    val row = new Row(List.empty[Element])
    row.get(sym) must throwA[ElementNotFoundFailure]
  }

  lazy val genSymbol: Gen[Symbol] = for {
    str <-  arbitrary[String]
  } yield Symbol(str)
  implicit lazy val arbitrarySymbol: Arbitrary[Symbol] =
    Arbitrary(genSymbol)
} 
开发者ID:finagle,项目名称:roc,代码行数:29,代码来源:ResultsSpec.scala

示例3: 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]]
} 
开发者ID:julien-truffaut,项目名称:newts,代码行数:51,代码来源:NewtsSuite.scala

示例4: Generators

//设置package包名称以及导入依赖的类
package better.testing.palindrome

import Generators._
import org.scalacheck._
import org.scalacheck.Prop.forAll
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.prop.PropertyChecks
import org.scalatest.PropSpec

object Generators {
  val palindromeGen: Gen[String] = for {
    s <- arbitrary[String]
  } yield s
}

object PalindromeCheck extends Properties("Palindrome") with PalindromeCheckers {
  property("checkReverse") = forAll(palindromeGen) { s =>
    checkReverse(s)
  }
}

class PalindromeSpecifications extends PropSpec with PropertyChecks with PalindromeCheckers {
  import org.scalatest._
  import Matchers._

  property("checkReverse") { forAll(palindromeGen) { s =>
    checkReverse(s) shouldBe true
  }}
} 
开发者ID:Mharlin,项目名称:better-testing-workshop,代码行数:30,代码来源:PalindromeCheck.scala

示例5: Generators

//设置package包名称以及导入依赖的类
package better.testing.palindrome

import Generators._
import org.scalacheck._
import org.scalacheck.Prop.forAll
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.prop.PropertyChecks
import org.scalatest.PropSpec

object Generators {

  val palindromeGen: Gen[String] = for {
    base <- arbitrary[String]
    middle <- Gen.option(arbitrary[Char])
  } yield base + middle.getOrElse("") + base.reverse

  val maybePalindromeGen: Gen[String] = Gen.oneOf(palindromeGen,arbitrary[String])

}

object PalindromeCheck extends Properties("Palindrome") with PalindromeCheckers {
  property("checkReverse") = forAll(palindromeGen) { s =>
    checkReverse(s)
  }

  property("checkIndices") = forAll(maybePalindromeGen) { s =>
    checkIndices(s) == checkReverse(s)
  }
}

class PalindromeSpecifications extends PropSpec with PropertyChecks with PalindromeCheckers {
  import org.scalatest._
  import Matchers._

  property("checkReverse") { forAll(palindromeGen) { s =>
    checkReverse(s) shouldBe true
  }}

  property("checkIndices") { forAll(palindromeGen) { s =>
    checkIndices(s) shouldBe true
  }}

  property("checkIndices returns false when not palindrome") { forAll(maybePalindromeGen) { s =>
    checkIndices(s) shouldBe checkReverse(s)
  }}
} 
开发者ID:Mharlin,项目名称:better-testing-workshop,代码行数:47,代码来源:PalindromeCheck.scala

示例6: Generators

//设置package包名称以及导入依赖的类
package com.github.hgiddens.ausms

import org.scalacheck.{ Arbitrary, Gen }
import org.scalacheck.Arbitrary.arbitrary
import scalaz.Scalaz._

object Generators {
  implicit def arbMessage: Arbitrary[Message] =
    Arbitrary(for {
      content <- arbitrary[String]
      message <- Gen.fromOption(Message.fromString(content))
    } yield message)

  implicit def arbMessageId: Arbitrary[MessageId] =
    Arbitrary(Gen.resultOf(MessageId.apply _))

  implicit def arbPhoneNumber: Arbitrary[PhoneNumber] =
    Arbitrary(for {
      digits <- Gen.listOfN(8, Gen.choose(0, 9))
      number = s"04${digits.mkString}"
      phoneNumber <- Gen.fromOption(PhoneNumber.fromString(number))
    } yield phoneNumber)
} 
开发者ID:hgiddens,项目名称:au-sms,代码行数:24,代码来源:Generators.scala

示例7: NullToggleMapTest

//设置package包名称以及导入依赖的类
package com.twitter.finagle.toggle

import org.junit.runner.RunWith
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.GeneratorDrivenPropertyChecks

@RunWith(classOf[JUnitRunner])
class NullToggleMapTest extends FunSuite
  with GeneratorDrivenPropertyChecks {

  private val IntGen = arbitrary[Int]

  test("apply") {
    val toggle = NullToggleMap("hi")
    forAll(IntGen) { i =>
      assert(!toggle.isDefinedAt(i))
    }
  }

  test("iterator") {
    assert(NullToggleMap.iterator.isEmpty)
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:27,代码来源:NullToggleMapTest.scala

示例8: TagsSyntaxSpec

//设置package包名称以及导入依赖的类
package ru.pavkin.todoist.api.core.model

import java.util.UUID

import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Gen
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}
import ru.pavkin.todoist.api.core.tags
import ru.pavkin.todoist.api.core.tags._
import shapeless.tag
import shapeless.test.illTyped

class TagsSyntaxSpec extends FunSuite
  with Matchers
  with GeneratorDrivenPropertyChecks
  with tags.Syntax {

  test("tags conversions work for resource ids") {
    forAll(arbitrary[Int]) { (i: Int) =>
      i.projectId shouldBe tag[ProjectId](i)
      i.labelId shouldBe tag[LabelId](i)
      i.userId shouldBe tag[UserId](i)
      i.taskId shouldBe tag[TaskId](i)
    }
    forAll(Gen.uuid) { (i: UUID) =>
      i.projectId shouldBe tag[ProjectId](i)
      i.labelId shouldBe tag[LabelId](i)
      i.userId shouldBe tag[UserId](i)
      i.taskId shouldBe tag[TaskId](i)
    }
  }

  test("tags conversions don't work for other types") {
    illTyped(""" "a".projectId """)
    illTyped(""" "a".labelId """)
    illTyped(""" true.taskId """)
    illTyped(""" 100L.userId""")
  }
} 
开发者ID:vpavkin,项目名称:scalist,代码行数:41,代码来源:TagsSyntaxSpec.scala

示例9: ECDSASignatureSpec

//设置package包名称以及导入依赖的类
package io.iohk.ethereum.crypto

import akka.util.ByteString
import io.iohk.ethereum.nodebuilder.SecureRandomBuilder
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, Matchers}
import org.spongycastle.crypto.params.ECPublicKeyParameters
import org.spongycastle.util.encoders.Hex

class ECDSASignatureSpec extends FlatSpec with Matchers with PropertyChecks with SecureRandomBuilder {
  "ECDSASignature" should "recover public key correctly for go ethereum transaction" in {
    val bytesToSign = Hex.decode("5a1465f4683bf2c18fc72c0789239c0f52b3ceac666ca9551cf265a11abe912c")
    val signatureRandom = ByteString(Hex.decode("f3af65a23fbf207b933d3c962381aa50e0ac19649c59c1af1655e592a8d95401"))
    val signature = ByteString(Hex.decode("53629a403579f5ce57bcbefba2616b1c6156d308ddcd37372c94943fdabeda97"))
    val pointSign = 28

    val sig = ECDSASignature(BigInt(1, signatureRandom.toArray[Byte]), BigInt(1, signature.toArray[Byte]), pointSign.toByte)

    sig.publicKey(bytesToSign).isEmpty shouldBe false
  }

  it should "fail on case from transaction 74c45d0cf2332cc021bebdfee6b1c1da0b58e8f4154537adb79b025f722920a4" in {
    val bytesToSign = Hex.decode("2bb3925f178aa22c11435c61899e134fb7b1227016274b5f7b9d85c4469130ba")
    val signatureRandom = ByteString(Hex.decode("fbe3df0cf030655d817a89936850d1cc00c07c35d3b21be73cfe9a730ea8b753"))
    val signature = ByteString(Hex.decode("62d73b6a92ac23ff514315fad795bbac6d485481d356329d71467e93c87dfa42"))
    val pointSign = 0x1f

    val sig = ECDSASignature(BigInt(1, signatureRandom.toArray[Byte]), BigInt(1, signature.toArray[Byte]), pointSign.toByte)

    sig.publicKey(bytesToSign).isEmpty shouldBe true
  }

  it should "sign message and recover public key" in {
    forAll(arbitrary[Array[Byte]], Arbitrary.arbitrary[Unit].map(_ => generateKeyPair(secureRandom))) {
      (message, keys) =>

        val pubKey = keys.getPublic.asInstanceOf[ECPublicKeyParameters].getQ
        val msg = kec256(message)

        val signature = ECDSASignature.sign(msg, keys)
        val recPubKey = signature.publicKey(msg)

        val result = recPubKey.map(a => ECDSASignature.uncompressedIndicator +: a).map(curve.getCurve.decodePoint).map(_.getEncoded(true)).map(ByteString(_))
        val expected = Some(pubKey.getEncoded(true)).map(ByteString(_))

        result shouldBe expected
    }
  }
} 
开发者ID:input-output-hk,项目名称:etc-client,代码行数:52,代码来源:ECDSASignatureSpec.scala

示例10: PalindromCheckerSpec

//设置package包名称以及导入依赖的类
import org.scalacheck._
import org.scalacheck.Prop.forAll
import org.scalacheck.Arbitrary.arbitrary

object PalindromCheckerSpec extends Properties("palindromes") {

  val palindromeGen: Gen[String] = for {
    base <- Gen.alphaStr
    middle <- Gen.option(arbitrary[Char])
  } yield base + middle.getOrElse("") + base.reverse

  val maybePalindrome = Gen.oneOf(palindromeGen, arbitrary[String])

  property("checkReverse coincides with generator") =
    forAll(palindromeGen) { palindrome =>
      PalindromeChecker.checkReverse(palindrome)
    }

  property("naive check Indices") =
    forAll(maybePalindrome) { maybe =>
      PalindromeChecker.checkReverse(maybe) == PalindromeChecker.checkIndices(maybe)
    }
} 
开发者ID:hasumedic,项目名称:scalacheck-101,代码行数:24,代码来源:PalindromCheckerSpec.scala

示例11: FreqTableSpecification

//设置package包名称以及导入依赖的类
package geekie.pgm

import org.scalacheck.Properties
import org.scalacheck.Gen
import org.scalacheck.Prop
import org.scalacheck.Arbitrary.arbitrary

import scala.util.Random

object FreqTableSpecification extends Properties("FreqTable") {

  def nodeList3 = List("nA", "nB", "nC")

  def genFreq = Gen.listOfN(8, Gen.choose(0L, 10000L))

  property("Addition") = Prop.forAll(genFreq, genFreq) {
    (v, w) =>
      val res = v zip w map { case (a, b) => a + b }

      val ftA = FreqTable(nodeList3, v)
      val ftB = FreqTable(nodeList3, w)
      val ftC = ftA + ftB

      ftA + ftB == ftC && ftC.nodes == nodeList3
  }

  property("Build from boolean") = Prop.forAll(Gen.listOfN(3, arbitrary[Boolean])) {
    (byte: Seq[Boolean]) =>
      val sel = (0 /: byte) { (acc, b) => 2 * acc + (if (b) 1 else 0) }
      val expected = List.fill(8)(0L).updated(sel, 1L)

      val ftA = FreqTable.fromBoolean(nodeList3, byte)
      val ftB = FreqTable(nodeList3, expected)

      ftA == ftB
  }

  property("Marginalization") = Prop.forAll(genFreq) {
    (ll) =>
      val ft = FreqTable(nodeList3, ll)
      val ta = ft.marginalize("nA").counts == List(ll(0) + ll(4), ll(1) + ll(5), ll(2) + ll(6), ll(3) + ll(7))
      val tb = ft.marginalize("nB").counts == List(ll(0) + ll(2), ll(1) + ll(3), ll(4) + ll(6), ll(5) + ll(7))
      val tc = ft.marginalize("nC").counts == List(ll(0) + ll(1), ll(2) + ll(3), ll(4) + ll(5), ll(6) + ll(7))
      val total = (ft /: Random.shuffle(nodeList3)) { (t, n) => t.marginalize(n) }
      val td = total.counts(0) == ll.sum
      ta && tb && tc && td
  }
} 
开发者ID:projetoeureka,项目名称:geekie-bayes,代码行数:49,代码来源:FreqTableSpecification.scala

示例12: MomentLocalDateTimeTests

//设置package包名称以及导入依赖的类
package dtc.tests

import java.time.{LocalDate, LocalTime}

import cats.kernel.laws.OrderLaws
import dtc.instances.moment._
import dtc.js.MomentLocalDateTime
import dtc.laws.{DateTimeTests, LocalDateTimeTests, ProviderTests}
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary.arbitrary
import dtc.instances.moment.providers.realMomentLocalDateTimeProvider

class MomentLocalDateTimeTests extends DTCSuiteJS {

  implicit val arbT: Arbitrary[MomentLocalDateTime] = Arbitrary(for {
    date <- arbitrary[LocalDate]
    time <- arbitrary[LocalTime]
  } yield MomentLocalDateTime.of(date, time))

  implicit val cogenT = cogenMomentDateTime[MomentLocalDateTime]

  val pairGen = overflowSafePairGen.map(t => (MomentLocalDateTime.of(t._1, t._2), t._3))
  val ldtTests = LocalDateTimeTests[MomentLocalDateTime](
    pairGen,
    genJSValidYear
  )
  checkAll("MomentLocalDateTimeTests", DateTimeTests[MomentLocalDateTime](pairGen).dateTime)
  checkAll("MomentLocalDateTimeTests", ldtTests.localDateTime)
  // see: https://github.com/moment/moment/issues/3029
  // checkAll("MomentLocalDateTimeTests", ldtTests.localDateTime)
  checkAll("MomentLocalDateTimeTests", OrderLaws[MomentLocalDateTime].order)
  checkAll("MomentLocalDateTimeTests", OrderLaws[MomentLocalDateTime].partialOrder)
  checkAll("MomentLocalDateTimeTests", OrderLaws[MomentLocalDateTime].eqv)

  checkAll("MomentLocalDateTimeTests", ProviderTests[MomentLocalDateTime](genTimeZone).provider)
} 
开发者ID:vpavkin,项目名称:dtc,代码行数:37,代码来源:MomentLocalDateTimeTests.scala

示例13: MomentZonedDateTimeTests

//设置package包名称以及导入依赖的类
package dtc.tests

import java.time.{Duration, LocalDate, LocalTime}

import cats.kernel.laws.OrderLaws
import dtc.TimeZoneId
import dtc.instances.moment._
import dtc.js.MomentZonedDateTime
import dtc.laws.{DateTimeTests, ProviderTests, ZonedDateTimeTestData, ZonedDateTimeTests}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Cogen, Gen}
import dtc.instances.moment.providers.realMomentZonedDateTimeProvider

class MomentZonedDateTimeTests extends DTCSuiteJS {

  implicit val arbT: Arbitrary[MomentZonedDateTime] = Arbitrary(for {
    date <- arbitrary[LocalDate]
    time <- arbitrary[LocalTime]
    zone <- arbitrary[TimeZoneId]
  } yield MomentZonedDateTime.of(date, time, zone))

  implicit val cogenT: Cogen[MomentZonedDateTime] = cogenMomentDateTime[MomentZonedDateTime]

  val pairGen: Gen[(MomentZonedDateTime, Duration)] = for {
    zone <- arbitrary[TimeZoneId]
    pair <- overflowSafePairGen
  } yield (MomentZonedDateTime.of(pair._1, pair._2, zone), pair._3)

  def genDateFromPeriod(period: SameZoneOffsetPeriod): Gen[MomentZonedDateTime] =
    genDateTimeFromSameOffsetPeriod(period).map(tpl => MomentZonedDateTime.of(tpl._1, tpl._2, tpl._3))

  val overflowSafePairGenWithinSameOffset: Gen[(MomentZonedDateTime, Duration)] = for {
    period <- arbitrary[SameZoneOffsetPeriod]
    dateTime <- genDateFromPeriod(period)
    duration <- genDateFromPeriod(period)
      .map(other => dateTime.millisecondsUntil(other))
      .map(Duration.ofMillis)
  } yield (dateTime, duration)


  val genZonedTestDataSuite: Gen[ZonedDateTimeTestData[MomentZonedDateTime]] =
    pairGen.map {
      case (date, duration) =>
        val target = date.plus(duration)
        ZonedDateTimeTestData(date, duration, target.offset, target.toLocalTime, target.toLocalDate)
    }

  checkAll("MomentZonedDateTime", DateTimeTests[MomentZonedDateTime](pairGen).dateTime)
  checkAll("MomentZonedDateTime", ZonedDateTimeTests[MomentZonedDateTime](
    overflowSafePairGenWithinSameOffset,
    genZonedTestDataSuite,
    genJSValidYear,
    genTimeZone
  ).zonedDateTime)
  checkAll("MomentZonedDateTime", OrderLaws[MomentZonedDateTime].order)
  checkAll("MomentZonedDateTime", OrderLaws[MomentZonedDateTime].partialOrder)
  checkAll("MomentZonedDateTime", OrderLaws[MomentZonedDateTime].eqv)

  checkAll("MomentZonedDateTime", ProviderTests[MomentZonedDateTime](genTimeZone).provider)
} 
开发者ID:vpavkin,项目名称:dtc,代码行数:61,代码来源:MomentZonedDateTimeTests.scala

示例14: JSDateTests

//设置package包名称以及导入依赖的类
package dtc.tests

import java.time.{LocalDate, LocalTime}

import cats.kernel.laws.OrderLaws
import dtc.instances.jsDate._
import dtc.js.JSDate
import dtc.laws.{DateTimeTests, LocalDateTimeTests, ProviderTests}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import dtc.instances.providers.realJSDateProvider

class JSDateTests extends DTCSuiteJS {

  implicit val cogenT: Cogen[JSDate] = Cogen(_.jsGetTime.toLong)

  implicit val arbT: Arbitrary[JSDate] = Arbitrary(for {
    date <- arbitrary[LocalDate]
    time <- arbitrary[LocalTime]
  } yield JSDate.of(date, time))

  val pairGen = overflowSafePairGen.map(t => (JSDate.of(t._1, t._2), t._3))
  val ldtTests = LocalDateTimeTests[JSDate](
    pairGen, genJSValidYear
  )

  checkAll("JSDate", DateTimeTests[JSDate](pairGen).dateTime)
  checkAll("JSDate", ldtTests.localDateTime)
  checkAll("JSDate", ldtTests.monthUntilFractionHandling)
  checkAll("JSDate", OrderLaws[JSDate].order)
  checkAll("JSDate", OrderLaws[JSDate].partialOrder)
  checkAll("JSDate", OrderLaws[JSDate].eqv)

  checkAll("JSDate", ProviderTests[JSDate](genTimeZone).provider)
} 
开发者ID:vpavkin,项目名称:dtc,代码行数:36,代码来源:JSDateTests.scala

示例15: JVMLocalDateTimeTests

//设置package包名称以及导入依赖的类
package dtc.tests

import java.time.{Duration, LocalDateTime, ZoneOffset}

import cats.kernel.laws.OrderLaws
import com.fortysevendeg.scalacheck.datetime.jdk8.ArbitraryJdk8._
import dtc.instances.localDateTime._
import dtc.laws.{DateTimeTests, LocalDateTimeTests, ProviderTests}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import dtc.instances.providers.realLocalDateTimeProvider

class JVMLocalDateTimeTests extends DTCSuiteJVM {

  implicit val arbT: Arbitrary[LocalDateTime] = Arbitrary(genZonedDateTime.map(_.toLocalDateTime))
  implicit val cogenT: Cogen[LocalDateTime] = Cogen(_.toEpochSecond(ZoneOffset.UTC))

  val overflowSafePairGen = for {
    dt <- arbitrary[LocalDateTime]
    dur <- arbitrary[Duration]
  } yield (dt, dur)

  val ldtTests = LocalDateTimeTests[LocalDateTime](overflowSafePairGen, genYear)
  checkAll("java.time.LocalDateTime", DateTimeTests[LocalDateTime](overflowSafePairGen).dateTime)
  checkAll("java.time.LocalDateTime", ldtTests.localDateTime)
  checkAll("java.time.LocalDateTime", ldtTests.monthUntilFractionHandling)
  checkAll("java.time.LocalDateTime", OrderLaws[LocalDateTime].order)
  checkAll("java.time.LocalDateTime", OrderLaws[LocalDateTime].partialOrder)
  checkAll("java.time.LocalDateTime", OrderLaws[LocalDateTime].eqv)

  checkAll("java.time.LocalDateTime", ProviderTests[LocalDateTime](genTimeZone).provider)
} 
开发者ID:vpavkin,项目名称:dtc,代码行数:33,代码来源:LocalDateTimeTests.scala


注:本文中的org.scalacheck.Arbitrary.arbitrary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。