本文整理汇总了Scala中org.scalacheck.Properties类的典型用法代码示例。如果您正苦于以下问题:Scala Properties类的具体用法?Scala Properties怎么用?Scala Properties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Properties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ServiceSpec
//设置package包名称以及导入依赖的类
package org.mdoc.rendering.service
import org.http4s.{ Request, Uri }
import org.http4s.dsl._
import org.http4s.headers.`Content-Type`
import org.http4s.util.CaseInsensitiveString
import org.mdoc.common.model.{ Document, Format }
import org.mdoc.common.model.jvm.FormatOps
import org.scalacheck.Prop._
import org.scalacheck.Properties
import scodec.bits.ByteVector
object ServiceSpec extends Properties("Service") {
property("docToResponse sets ContentType") = secure {
Format.values.forall { format =>
val doc = Document(format, ByteVector.view("".getBytes))
val response = Service.docToResponse(doc).run
response.headers.get(CaseInsensitiveString("content-type"))
.contains(`Content-Type`(FormatOps.toMediaType(format)))
}
}
property("showRequest") = forAll { (s: String) =>
Service.showRequest(Request(uri = Uri(path = s))) ?= s"GET $s"
}
property("route: /") = secure {
Service.route.run(Request()).run.status ?= NotFound
}
property("route: /render failure") = secure {
val req: Request = Request(uri = Uri(path = "/render"), method = POST)
val body = Service.route.run(req).run.body.runLast.run
.flatMap(_.decodeAscii.right.toOption).getOrElse("")
body ?= "Invalid JSON"
}
property("route: /render/pdf/test.pdf") = secure {
val req = Request(uri = Uri(path = "/render/pdf/test.pdf"))
Service.route.run(req).run.status ?= BadRequest
}
property("route: /version") = secure {
Service.route.run(Request(uri = Uri(path = "/version"))).run.status ?= Ok
}
}
示例2: BlazeSpec
//设置package包名称以及导入依赖的类
package org.mdoc.rendering.service
import eu.timepit.properly.Property.PropertySyntax
import org.scalacheck.Prop._
import org.scalacheck.Properties
object BlazeSpec extends Properties("Blaze") {
property("serverBuilder") = secure {
val props = Map("HTTP_HOST" -> "1.2.3.4", "HTTP_PORT" -> "1234")
Blaze.serverBuilder.runMock(props)
true
}
property("server") = secure {
val server = Blaze.server
true
}
}
示例3: StringSpecification
//设置package包名称以及导入依赖的类
package example
import org.scalacheck.Properties
import org.scalacheck.Prop.forAll
object StringSpecification extends Properties("String") {
property("startsWith") = forAll { (a: String, b: String) =>
(a+b).startsWith(a)
}
property("concatenate") = forAll { (a: String, b: String) =>
(a+b).length >= a.length && (a+b).length >= b.length
}
property("substring") = forAll { (a: String, b: String, c: String) =>
(a+b+c).substring(a.length, a.length+b.length) == b
}
//TODO see https://github.com/rickynils/scalacheck/blob/master/doc/UserGuide.md
}
示例4: CirceSpec
//设置package包名称以及导入依赖的类
package org.mdoc.common.model
import cats.data.Xor
import io.circe.{ Decoder, Encoder, Json }
import org.mdoc.common.model.circe._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import scodec.bits.ByteVector
object CirceSpec extends Properties("circe") {
property("Decoder[ByteVector] success") = secure {
Decoder[ByteVector].decodeJson(Json.string("SGVsbG8=")) ?=
Xor.right(ByteVector("Hello".getBytes))
}
property("Decoder[ByteVector] failure") = secure {
Decoder[ByteVector].decodeJson(Json.string("???")).isLeft
}
property("Encoder[ByteVector]") = secure {
Encoder[ByteVector].apply(ByteVector("Hello".getBytes)) ?=
Json.string("SGVsbG8=")
}
}
示例5: RenderingInputSpec
//设置package包名称以及导入依赖的类
package org.mdoc.common.model
import cats.data.Xor
import io.circe.generic.auto._
import io.circe.parse._
import io.circe.syntax._
import org.mdoc.common.model.Format.{ Html, Pdf }
import org.mdoc.common.model.RenderingEngine.LibreOffice
import org.mdoc.common.model.circe._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import scodec.bits.ByteVector
object RenderingInputSpec extends Properties("RenderingInput") {
{
val json = """
{"id":{"self":"42"},"config":{"outputFormat":{"Pdf":{}},"engine":{"LibreOffice":{}}},"doc":{"format":{"Html":{}},"body":"SGVsbG8sIFdvcmxkIQ=="}}
""".trim
val config = RenderingConfig(Pdf, LibreOffice)
val doc = Document(Html, ByteVector("Hello, World!".getBytes))
val input = RenderingInput(JobId("42"), config, doc)
property("JSON decode") = secure {
decode[RenderingInput](json) ?= Xor.right(input)
}
property("JSON encode") = secure {
input.asJson.noSpaces ?= json
}
}
}
示例6: SessionManagerBasicEncoderTest
//设置package包名称以及导入依赖的类
package com.softwaremill.session
import org.scalacheck.{Gen, Prop, Properties}
object SessionManagerBasicEncoderTest extends Properties("SessionManagerBasicEncoder") {
import Prop._
val secretGen = Gen.choose(64, 256).flatMap(size => Gen.listOfN(size, Gen.alphaNumChar).map(_.mkString))
property("encode+decode") = forAllNoShrink(secretGen) { (secret: String) =>
forAll { (encrypt: Boolean, useMaxAgeSeconds: Boolean, data: Map[String, String]) =>
val config = SessionConfig.default(secret)
.copy(sessionEncryptData = encrypt)
.copy(sessionMaxAgeSeconds = if (useMaxAgeSeconds) Some(3600L) else None)
val manager = new SessionManager[Map[String, String]](config).clientSessionManager
manager.decode(manager.encode(data)) == SessionResult.Decoded(data)
}
}
property("doesn't decode expired session") = forAllNoShrink(secretGen) { (secret: String) =>
forAll { (encrypt: Boolean, data: Map[String, String]) =>
val config = SessionConfig.default(secret)
.copy(sessionEncryptData = encrypt)
.copy(sessionMaxAgeSeconds = Some(20L)) // expires after 20s
val managerPast = new SessionManager[Map[String, String]](config) {
override def nowMillis = 8172L * 1000L
}.clientSessionManager
val managerFuture = new SessionManager[Map[String, String]](config) {
override def nowMillis = (8172L + 600L) * 1000L // 600s later
}.clientSessionManager
managerFuture.decode(managerPast.encode(data)) == SessionResult.Expired
}
}
}
示例7: NegateSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import singleton.TestUtils._
import shapeless.test.illTyped
class NegateSpec extends Properties("Negate") {
property("Nat argument") = wellTyped {
implicitly[Require[Negate[shapeless.Nat._1] == (-1)]]
}
property("Char argument") = wellTyped {
implicitly[Require[Negate['T'] == (-84)]]
}
property("Int argument") = wellTyped {
implicitly[Require[Negate[2] == (-2)]]
implicitly[Require[Negate[-2] == 2]]
}
property("Long argument") = wellTyped {
implicitly[Require[Negate[5L] == (-5L)]]
implicitly[Require[Negate[-5L] == 5L]]
}
property("Float argument") = wellTyped {
implicitly[Require[Negate[1.5f] == (-1.5f)]]
implicitly[Require[Negate[-1.5f] == 1.5f]]
}
property("Double argument") = wellTyped {
implicitly[Require[Negate[1.5] == (-1.5)]]
implicitly[Require[Negate[-1.5] == 1.5]]
}
property("Boolean argument") = {
illTyped("""implicitly[Negate[true]]""")
true
}
property("String argument") = {
illTyped("""implicitly[Negate["Something"]]""")
true
}
}
示例8: LessThanSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
class LessThanSpec extends Properties("LessThan") {
property("3.5F < 3.6F") = wellTyped {
def require[P1 <: XDouble, P2 <: XDouble](implicit op : Require[P1 < P2]) : op.Out{} = op.value
val r = require[3.5, 3.6]
}
property("!(5 < 4)") = wellTyped {
def require[P1 <: XDouble, P2 <: XDouble](implicit op : Require[P1 < P2]) : op.Out{} = op.value
illTyped(""" val r = require[3.6, 3.5] """)
}
}
示例9: MinSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import singleton.TestUtils._
class MinSpec extends Properties("Min") {
property("Nat, left is minimum") = verifyOp2Args[Min,shapeless.Nat._1, shapeless.Nat._2, 1]
property("Nat, right is minimum") = verifyOp2Args[Min,shapeless.Nat._3, shapeless.Nat._2, 2]
property("Nat, equal") = verifyOp2Args[Min,shapeless.Nat._3, shapeless.Nat._3, 3]
property("Int, left is minimum") = verifyOp2Args[Min,1, 2, 1]
property("Int, right is minimum") = verifyOp2Args[Min,3, 2, 2]
property("Int, equal") = verifyOp2Args[Min,3, 3, 3]
property("Long, left is minimum") = verifyOp2Args[Min,1L, 2L, 1L]
property("Long, right is minimum") = verifyOp2Args[Min,3L, 2L, 2L]
property("Long, equal") = verifyOp2Args[Min,3L, 3L, 3L]
property("Float, left is minimum") = verifyOp2Args[Min,1.0f, 2.0f, 1.0f]
property("Float, right is minimum") = verifyOp2Args[Min,3.0f, 2.0f, 2.0f]
property("Float, equal") = verifyOp2Args[Min,3.0f, 3.0f, 3.0f]
property("Double, left is minimum") = verifyOp2Args[Min,1.0, 2.0, 1.0]
property("Double, right is minimum") = verifyOp2Args[Min,3.0, 2.0, 2.0]
property("Double, equal") = verifyOp2Args[Min,3.0, 3.0, 3.0]
}
示例10: MaxSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import singleton.TestUtils._
class MaxSpec extends Properties("Max") {
property("Nat, right is maximum") = verifyOp2Args[Max,shapeless.Nat._1, shapeless.Nat._2, 2]
property("Nat, left is maximum") = verifyOp2Args[Max,shapeless.Nat._3, shapeless.Nat._2, 3]
property("Nat, equal") = verifyOp2Args[Max,shapeless.Nat._3, shapeless.Nat._3, 3]
property("Int, right is maximum") = verifyOp2Args[Max,1, 2, 2]
property("Int, left is maximum") = verifyOp2Args[Max,3, 2, 3]
property("Int, equal") = verifyOp2Args[Max,3, 3, 3]
property("Long, right is maximum") = verifyOp2Args[Max,1L, 2L, 2L]
property("Long, left is maximum") = verifyOp2Args[Max,3L, 2L, 3L]
property("Long, equal") = verifyOp2Args[Max,3L, 3L, 3L]
property("Float, right is maximum") = verifyOp2Args[Max,1.0f, 2.0f, 2.0f]
property("Float, left is maximum") = verifyOp2Args[Max,3.0f, 2.0f, 3.0f]
property("Float, equal") = verifyOp2Args[Max,3.0f, 3.0f, 3.0f]
property("Double, right is maximum") = verifyOp2Args[Max,1.0, 2.0, 2.0]
property("Double, left is maximum") = verifyOp2Args[Max,3.0, 2.0, 3.0]
property("Double, equal") = verifyOp2Args[Max,3.0, 3.0, 3.0]
}
示例11: ReverseSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import singleton.TestUtils._
class ReverseSpec extends Properties("Reverse") {
property("abc.reverse == cba") = wellTyped {
def reverse[P1 <: XString](implicit op : Reverse[P1]) : op.Out{} = op.value
val r : "cba" = reverse["abc"]
}
property("abc.reverse.reverse == abc") = wellTyped {
def reverse[P1 <: XString](implicit op : Reverse[Reverse[P1]]) : op.Out{} = op.value
val r : "abc" = reverse["abc"]
}
}
示例12: IdSpec
//设置package包名称以及导入依赖的类
package singleton.ops
import org.scalacheck.Properties
import singleton.TestUtils._
class IdSpec extends Properties("Id") {
property("Nat") = wellTyped {
def getNat(implicit op : SafeNat[Id[shapeless.Nat._1]]) : op.Out = op.value
val ret : shapeless.nat._1 = getNat
}
property("Char") = {
val ret : Char = implicitly[SafeChar[Id['\u0001']]]
ret == '\u0001'
}
property("Int") = {
val ret : Int = implicitly[SafeInt[Id[1]]]
ret == 1
}
property("Long") = {
val ret : Long = implicitly[SafeLong[Id[1L]]]
ret == 1L
}
property("Float") = {
val ret : Float = implicitly[SafeFloat[Id[1.0f]]]
ret == 1.0f
}
property("Double") = {
val ret : Double = implicitly[SafeDouble[Id[1.0]]]
ret == 1.0
}
property("String") = {
val ret : String = implicitly[SafeString[Id["Something"]]]
ret == "Something"
}
property("Boolean") = {
val ret : Boolean = implicitly[SafeBoolean[Id[true]]]
ret == true
}
}
示例13: CheckedLongSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedLongSpec extends Properties("Checked.Long") {
type CondSmallerThan50[T, P] = T < P
type MsgSmallerThan50[T, P] = "Failed Check"
type Param50 = 50L
type CheckedSmallerThan50[T] = Checked.Long[T, CondSmallerThan50, Param50, MsgSmallerThan50]
implicit object RuntimeChecked extends Checked.Runtime[Long, Long, CondSmallerThan50, MsgSmallerThan50] {
def cond(l : Long, p : Option[Long]) : scala.Boolean = l < 50L
def msg(l : Long, p : Option[Long]) : java.lang.String = s"Failed Check"
}
def smallerThan50[T](t : CheckedSmallerThan50[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
smallerThan50(40L)
smallerThan50(TwoFace.Long(40L))
illTyped("""smallerThan50(50L)""")
illTyped("""smallerThan50(TwoFace.Long(50L))""")
}
property("Run-time checks") = wellTyped {
smallerThan50(us(40L))
smallerThan50(TwoFace.Long(us(40L)))
illRun{smallerThan50(us(50L))}
illRun{smallerThan50(TwoFace.Long(us(50L)))}
}
}
示例14: CheckedStringSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedStringSpec extends Properties("Checked.String") {
type CondCheckedLengthSmallerThan5[T, P] = Length[T] < P
type MsgCheckedLengthSmallerThan5[T, P] = "Failed Check"
type Param = 5
type CheckedLengthSmallerThan5[T] = Checked.String[T, CondCheckedLengthSmallerThan5, Param, MsgCheckedLengthSmallerThan5]
implicit object RuntimeChecked extends Checked.Runtime[String, Int, CondCheckedLengthSmallerThan5, MsgCheckedLengthSmallerThan5] {
def cond(l : String, p : Option[Int]) : scala.Boolean = l.length < 5
def msg(l : String, p : Option[Int]) : java.lang.String = s"Failed Check"
}
def lengthSmallerThan5[T](t : CheckedLengthSmallerThan5[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
lengthSmallerThan5("Hi")
lengthSmallerThan5(TwoFace.String("Hi"))
illTyped("""smallerThan50("Hello")""")
illTyped("""smallerThan50(TwoFace.String("Hello"))""")
}
property("Run-time checks") = wellTyped {
lengthSmallerThan5(us("Hi"))
lengthSmallerThan5(TwoFace.String(us("Hi")))
illRun{lengthSmallerThan5(us("Hello"))}
illRun{lengthSmallerThan5(TwoFace.String(us("Hello")))}
}
}
示例15: CheckedIntSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedIntSpec extends Properties("Checked.Int") {
class FixedSizeVector[L] private (val length : TwoFace.Int[L]) {
def concat[L2](that : FixedSizeVector[L2]) = FixedSizeVector.protCreate(this.length + that.length)
override def toString = s"FixedSizeVector($length)"
def pretty(implicit rt: RunTime[L]) = if (rt) s"FixedSizeVector($length)" else s"FixedSizeVector[$length]"
}
object FixedSizeVector {
//Defining Checked Length Type
protected type CondCheckedLength[L, P] = L > 0
protected type ParamCheckedLength = 0
protected type MsgCheckedLength[L, P] = "Length must be positive (received value of " + ToString[L] + ")"
type CheckedLength[L] = Checked.Int[L, CondCheckedLength, ParamCheckedLength, MsgCheckedLength]
implicit object RuntimeCheckedLength extends Checked.Runtime[Int, Int, CondCheckedLength, MsgCheckedLength] {
def cond(l : Int, p : Option[Int]) : scala.Boolean = l > 0
def msg(l : Int, p : Option[Int]) : java.lang.String = s"Length must be positive (received value of $l)"
}
//Protected Constructor (performs unsafe run-time check, if compile-time check is not possible)
protected def protCreate[L](tfLength : TwoFace.Int[L]) : FixedSizeVector[L] =
new FixedSizeVector[L](tfLength)
//Public Constructors (perform compile-time check, if possible)
def apply[L](checkedLength : CheckedLength[L]) =
protCreate(checkedLength.unsafeCheck())
implicit def apply[L](implicit checkedLength : CheckedLength[L], di : DummyImplicit) =
protCreate(checkedLength.unsafeCheck())
}
property("Compile-time checks") = wellTyped {
val ctv5 : FixedSizeVector[5] = FixedSizeVector[5]
val ctv2 : FixedSizeVector[2] = FixedSizeVector(2)
val ctv7 : FixedSizeVector[7] = implicitly[FixedSizeVector[7]]
val ctv9 : FixedSizeVector[9] = ctv2 concat ctv7
illTyped("""FixedSizeVector(0)""")
}
property("Run-time checks") = wellTyped {
val ctv2 = FixedSizeVector(2)
val rtv2 = FixedSizeVector(us(2))
val rtv4 = rtv2 concat rtv2 //runtime concat runtime => runtime
val rtv6 = rtv4 concat ctv2 //runtime concat compile-time => runtime
illRun{FixedSizeVector(us(0))}
}
}