本文整理汇总了Scala中org.scalacheck.Arbitrary.arbitrary类的典型用法代码示例。如果您正苦于以下问题:Scala arbitrary类的具体用法?Scala arbitrary怎么用?Scala arbitrary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了arbitrary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: JVMZonedDateTimeTests
//设置package包名称以及导入依赖的类
package dtc.tests
import java.time.temporal.ChronoUnit
import java.time.{Duration, ZonedDateTime}
import cats.kernel.laws.OrderLaws
import dtc.Offset
import dtc.instances.zonedDateTime._
import dtc.laws.{DateTimeTests, ProviderTests, ZonedDateTimeTestData, ZonedDateTimeTests}
import dtc.syntax.timeZone._
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Arbitrary, Cogen, Gen}
import dtc.instances.providers.realZonedDateTimeProvider
class JVMZonedDateTimeTests extends DTCSuiteJVM {
implicit val arbT: Arbitrary[ZonedDateTime] = com.fortysevendeg.scalacheck.datetime.jdk8.ArbitraryJdk8.arbJdk8
implicit val cogenT: Cogen[ZonedDateTime] = Cogen(_.toEpochSecond)
val overflowSafePairGen: Gen[(ZonedDateTime, Duration)] = for {
dt <- arbitrary[ZonedDateTime]
dur <- arbitrary[Duration]
} yield (dt, dur)
def genDateFromPeriod(period: SameZoneOffsetPeriod): Gen[ZonedDateTime] =
genDateTimeFromSameOffsetPeriod(period).map(tpl => ZonedDateTime.of(tpl._1, tpl._2, tpl._3.zoneId))
val overflowSafePairGenWithinSameOffset: Gen[(ZonedDateTime, Duration)] = for {
period <- arbitrary[SameZoneOffsetPeriod]
dateTime <- genDateFromPeriod(period)
duration <- genDateFromPeriod(period)
.map(other => dateTime.until(other, ChronoUnit.NANOS))
.map(Duration.ofNanos)
} yield (dateTime, duration)
val genZonedTestDataSuite: Gen[ZonedDateTimeTestData[ZonedDateTime]] =
overflowSafePairGen.map {
case (date, duration) =>
val target = date.plus(duration)
ZonedDateTimeTestData(date, duration,
Offset(date.plus(duration).getOffset.getTotalSeconds), target.toLocalTime, target.toLocalDate)
}
checkAll("java.time.ZonedDateTime", DateTimeTests[ZonedDateTime](overflowSafePairGen).dateTime)
checkAll("java.time.ZonedDateTime", ZonedDateTimeTests[ZonedDateTime](
overflowSafePairGenWithinSameOffset,
genZonedTestDataSuite,
genYear,
genTimeZone
).zonedDateTime)
checkAll("java.time.ZonedDateTime", OrderLaws[ZonedDateTime].order)
checkAll("java.time.ZonedDateTime", OrderLaws[ZonedDateTime].partialOrder)
checkAll("java.time.ZonedDateTime", OrderLaws[ZonedDateTime].eqv)
checkAll("java.time.ZonedDateTime", ProviderTests[ZonedDateTime](genTimeZone).provider)
}
开发者ID:vpavkin,项目名称:dtc,代码行数:57,代码来源:ZonedDateTimeTests.scala
示例17: LRUEntriesGenerator
//设置package包名称以及导入依赖的类
package com.twitter.util
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.{Gen, Arbitrary}
object LRUEntriesGenerator {
def apply[V:Arbitrary]: Gen[List[(String,V)]] = {
val gen = for {
size <- Gen.choose(1,200)
uniqueKeys <- Gen.listOfN(size, Gen.identifier).map(_.toSet)
vals <- Gen.listOfN(uniqueKeys.size, arbitrary[V])
} yield uniqueKeys.toList.zip(vals)
gen suchThat (_.nonEmpty)
}
}
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:17,代码来源:LRUEntriesGenerator.scala
示例18: DiffTest
//设置package包名称以及导入依赖的类
package com.twitter.util
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalacheck.Arbitrary.arbitrary
import org.scalatest.prop.GeneratorDrivenPropertyChecks
@RunWith(classOf[JUnitRunner])
class DiffTest extends FunSuite with GeneratorDrivenPropertyChecks {
val f: Int => String = _.toString
test("Diffable.ofSet") {
forAll(arbitrary[Set[Int]], arbitrary[Set[Int]]) { (a, b) =>
assert(Diffable.diff(a, b).patch(a) == b)
}
forAll(arbitrary[Set[Int]], arbitrary[Set[Int]]) { (a, b) =>
val diff = Diffable.diff(a, b)
assert(diff.map(f).patch(a.map(f)) == b.map(f))
}
}
test("Diffable.ofSeq") {
forAll(arbitrary[Seq[Int]], arbitrary[Seq[Int]]) { (a, b) =>
assert(Diffable.diff(a, b).patch(a) == b)
}
forAll(arbitrary[Seq[Int]], arbitrary[Seq[Int]]) { (a, b) =>
val diff = Diffable.diff(a, b)
assert(diff.map(f).patch(a.map(f)) == b.map(f))
}
}
}
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:35,代码来源:DiffTest.scala
示例19: BloomFiltersSpec
//设置package包名称以及导入依赖的类
package tests.bloomfilter.mutable
import bloomfilter.CanGenerateHashFrom
import bloomfilter.mutable.BloomFilter
import org.scalacheck.Test.Parameters
import org.scalacheck.commands.Commands
import org.scalacheck.{Arbitrary, Gen, Prop, Properties}
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Prop.forAll
class BloomFiltersSpec extends Properties("BloomFilters") {
val maxNumElems = 10
def genListOfMaxTenElems[A](implicit aGen: Gen[A]): Gen[List[A]] =
Gen.posNum[Int] map (_ % maxNumElems) flatMap (i => Gen.listOfN(i, aGen))
property("union") =
forAll(genListOfMaxTenElems(arbitrary[Long]), genListOfMaxTenElems(arbitrary[Long])) {
(leftElements: List[Long], rightElements: List[Long]) =>
val leftBloomFilter = BloomFilter[Long](maxNumElems, 0.01)
leftElements foreach leftBloomFilter.add
val rightBloomFilter = BloomFilter[Long](maxNumElems, 0.01)
rightElements foreach rightBloomFilter.add
val unionBloomFilter = leftBloomFilter union rightBloomFilter
val result = (leftElements ++ rightElements) forall unionBloomFilter.mightContain
leftBloomFilter.dispose()
rightBloomFilter.dispose()
unionBloomFilter.dispose()
result
}
property("intersect") =
forAll(genListOfMaxTenElems(arbitrary[Long]), genListOfMaxTenElems(arbitrary[Long])) {
(leftElements: List[Long], rightElements: List[Long]) =>
val leftBloomFilter = BloomFilter[Long](maxNumElems, 0.01)
leftElements foreach leftBloomFilter.add
val rightBloomFilter = BloomFilter[Long](maxNumElems, 0.01)
rightElements foreach rightBloomFilter.add
val unionBloomFilter = leftBloomFilter intersect rightBloomFilter
val intersectElems = leftElements.toSet intersect rightElements.toSet
val result = intersectElems forall unionBloomFilter.mightContain
leftBloomFilter.dispose()
rightBloomFilter.dispose()
unionBloomFilter.dispose()
result
}
}
开发者ID:alexandrnikitin,项目名称:bloom-filter-scala,代码行数:49,代码来源:BloomFiltersSpec.scala
示例20: ODESystemGeneratorTest
//设置package包名称以及导入依赖的类
package acumen
package testutil
import scala.collection.mutable.{ Map => MutMap }
import org.scalacheck._
import org.scalacheck.Arbitrary.arbitrary
import org.scalacheck.Gen._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import org.scalacheck.Shrink._
import Gen._
import Shrink._
import Arbitrary.arbitrary
import org.scalacheck.Properties
import org.scalacheck.Prop._
import ODESystemGenerator._
import Generators._
object ODESystemGeneratorTest extends Properties("ODESystemGenerator") {
property("The LHS of an equation does not occur in its RHS.") =
forAllNoShrink(chooseNum[Int](2, 20)) { n =>
forAllNoShrink(genDistinctSetOfN(n, arbitrary[Dot])) { ds =>
forAllNoShrink(oneOf(ds.toList)) { lhs =>
forAll(genLinearODE(ds)(lhs)) { equation =>
!equation.rhs.toString.contains(equation.lhs.toString)
}
}
}
}
}
开发者ID:janduracz,项目名称:acumen-dev,代码行数:33,代码来源:ODESystemGeneratorTest.scala
注:本文中的org.scalacheck.Arbitrary.arbitrary类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论