本文整理汇总了Scala中org.scalacheck.Properties类的典型用法代码示例。如果您正苦于以下问题:Scala Properties类的具体用法?Scala Properties怎么用?Scala Properties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Properties类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
}
开发者ID:m-doc,项目名称:rendering-service,代码行数:49,代码来源:ServiceSpec.scala
示例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
}
}
开发者ID:m-doc,项目名称:rendering-service,代码行数:20,代码来源:BlazeSpec.scala
示例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
}
开发者ID:rysh,项目名称:my-scala-playground,代码行数:22,代码来源:StringSpecification.scala
示例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=")
}
}
开发者ID:m-doc,项目名称:common-model,代码行数:26,代码来源:CirceSpec.scala
示例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
}
}
}
开发者ID:m-doc,项目名称:common-model,代码行数:34,代码来源:RenderingInputSpec.scala
示例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
}
}
}
开发者ID:adamw,项目名称:testpr,代码行数:38,代码来源:SessionManagerBasicEncoderTest.scala
示例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
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:46,代码来源:NegateSpec.scala
示例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] """)
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:18,代码来源:LessThanSpec.scala
示例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]
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:23,代码来源:MinSpec.scala
示例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]
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:23,代码来源:MaxSpec.scala
示例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"]
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:17,代码来源:ReverseSpec.scala
示例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
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:40,代码来源:IdSpec.scala
示例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)))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedLongSpec.scala
示例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")))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedStringSpec.scala
示例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))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:54,代码来源:CheckedIntSpec.scala
示例16: CheckedDoubleSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedDoubleSpec extends Properties("Checked.Double") {
type CondSmallerThan50[T, P] = T < P
type MsgSmallerThan50[T, P] = "Failed Check"
type Param50 = 50.0
type CheckedSmallerThan50[T] = Checked.Double[T, CondSmallerThan50, Param50, MsgSmallerThan50]
implicit object RuntimeChecked extends Checked.Runtime[Double, Double, CondSmallerThan50, MsgSmallerThan50] {
def cond(l : Double, p : Option[Double]) : scala.Boolean = l < 50.0
def msg(l : Double, p : Option[Double]) : java.lang.String = s"Failed Check"
}
def smallerThan50[T](t : CheckedSmallerThan50[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
smallerThan50(40.0)
smallerThan50(TwoFace.Double(40.0))
illTyped("""smallerThan50(50.0)""")
illTyped("""smallerThan50(TwoFace.Double(50.0))""")
}
property("Run-time checks") = wellTyped {
smallerThan50(us(40.0))
smallerThan50(TwoFace.Double(us(40.0)))
illRun{smallerThan50(us(50.0))}
illRun{smallerThan50(TwoFace.Double(us(50.0)))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedDoubleSpec.scala
示例17: CheckedFloatSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedFloatSpec extends Properties("Checked.Float") {
type CondSmallerThan50[T, P] = T < P
type MsgSmallerThan50[T, P] = "Failed Check"
type Param50 = 50.0f
type CheckedSmallerThan50[T] = Checked.Float[T, CondSmallerThan50, Param50, MsgSmallerThan50]
implicit object RuntimeChecked extends Checked.Runtime[Float, Float, CondSmallerThan50, MsgSmallerThan50] {
def cond(l : Float, p : Option[Float]) : scala.Boolean = l < 50.0f
def msg(l : Float, p : Option[Float]) : java.lang.String = s"Failed Check"
}
def smallerThan50[T](t : CheckedSmallerThan50[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
smallerThan50(40.0f)
smallerThan50(TwoFace.Float(40.0f))
illTyped("""smallerThan50(50.0f)""")
illTyped("""smallerThan50(TwoFace.Float(50.0f))""")
}
property("Run-time checks") = wellTyped {
smallerThan50(us(40.0f))
smallerThan50(TwoFace.Float(us(40.0f)))
illRun{smallerThan50(us(50.0f))}
illRun{smallerThan50(TwoFace.Float(us(50.0f)))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedFloatSpec.scala
示例18: CheckedCharSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedCharSpec extends Properties("Checked.Char") {
type CondSmallerThan50[T, P] = T < P
type MsgSmallerThan50[T, P] = "Failed Check"
type Param50 = '\u0032'
type CheckedSmallerThan50[T] = Checked.Char[T, CondSmallerThan50, Param50, MsgSmallerThan50]
implicit object RuntimeChecked extends Checked.Runtime[Char, Char, CondSmallerThan50, MsgSmallerThan50] {
def cond(l : Char, p : Option[Char]) : scala.Boolean = l < '\u0032'
def msg(l : Char, p : Option[Char]) : java.lang.String = s"Failed Check"
}
def smallerThan50[T](t : CheckedSmallerThan50[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
smallerThan50('\u0020')
smallerThan50(TwoFace.Char('\u0020'))
illTyped("""smallerThan50('\u0032')""")
illTyped("""smallerThan50(TwoFace.Char('\u0032'))""")
}
property("Run-time checks") = wellTyped {
smallerThan50(us('\u0020'))
smallerThan50(TwoFace.Char(us('\u0020')))
illRun{smallerThan50(us('\u0032'))}
illRun{smallerThan50(TwoFace.Char(us('\u0032')))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedCharSpec.scala
示例19: CheckedBooleanSpec
//设置package包名称以及导入依赖的类
package singleton.twoface
import org.scalacheck.Properties
import shapeless.test.illTyped
import singleton.TestUtils._
import singleton.ops._
class CheckedBooleanSpec extends Properties("Checked.Boolean") {
type CondTrue[T, P] = T == P
type MsgTrue[T, P] = "Failed Check"
type Param = true
type CheckedTrue[T] = Checked.Boolean[T, CondTrue, Param, MsgTrue]
implicit object RuntimeChecked extends Checked.Runtime[Boolean, Boolean, CondTrue, MsgTrue] {
def cond(l : Boolean, p : Option[Boolean]) : scala.Boolean = l
def msg(l : Boolean, p : Option[Boolean]) : java.lang.String = s"Failed Check"
}
def condTrue[T](t : CheckedTrue[T]) : Unit = {t.unsafeCheck()}
property("Compile-time checks") = wellTyped {
condTrue(true)
condTrue(TwoFace.Boolean(true))
illTyped("""smallerThan50(false)""")
illTyped("""smallerThan50(TwoFace.Boolean(false))""")
}
property("Run-time checks") = wellTyped {
condTrue(us(true))
condTrue(TwoFace.Boolean(us(true)))
illRun{condTrue(us(false))}
illRun{condTrue(TwoFace.Boolean(us(false)))}
}
}
开发者ID:fthomas,项目名称:singleton-ops,代码行数:35,代码来源:CheckedBooleanSpec.scala
示例20: DependencyParserProps
//设置package包名称以及导入依赖的类
package net.ssanj.dabble
import org.scalacheck.Properties
import org.scalacheck.{Prop, Gen}
import org.scalacheck.Gen.{posNum, negNum}
import scalaz._
import scalaz.std.list._
object DependencyParserProps extends Properties("DependencyParser") with DabbleProps {
property("returns a valid dependency from a valid input") =
Prop.forAll(genDependency) { inputs: Seq[String] =>
val \/-(Seq(dep)) = DependencyParser.parseDependencies(inputs)
dep match {
case ScalaVersionSupplied(org, name, version, None) =>
Seq(org, "%" , name, "%", version) == inputs
case ScalaVersionSupplied(org, name, version, Some(config)) =>
Seq(org, "%" , name, "%", version, "%", config) == inputs
case ScalaVersionDerived (org, name, version, None) =>
Seq(org, "%%", name, "%", version) == inputs
case ScalaVersionDerived (org, name, version, Some(config)) =>
Seq(org, "%%", name, "%", version, "%", config) == inputs
}
}
property("returns a valid list of dependencies from a valid list of inputs")=
Prop.forAll(genDependencyList) { inputs: Seq[String] =>
val \/-(deps) = DependencyParser.parseDependencies(inputs)
val outputs = intersperse(deps.map {
case ScalaVersionSupplied(org, name, version, None) =>
Seq(org, "%" , name, "%", version)
case ScalaVersionSupplied(org, name, version, Some(config)) =>
Seq(org, "%" , name, "%", version, "%", config)
case ScalaVersionDerived (org, name, version, None) =>
Seq(org, "%%", name, "%", version)
case ScalaVersionDerived (org, name, version, Some(config)) =>
Seq(org, "%%", name, "%", version, "%", config)
}.toList, Seq("+")).flatten
inputs == outputs
}
property("returns an empty list of dependencies if the input is invalid") =
Prop.forAll(emptyInput) { inputs: Seq[String] =>
val -\/(error) = DependencyParser.parseDependencies(inputs)
error == s"unable to derive dependencies from: $inputs"
}
}
开发者ID:ssanj,项目名称:dabble,代码行数:49,代码来源:DependencyParserProps.scala
注:本文中的org.scalacheck.Properties类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论