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


Scala GeneratorDrivenPropertyChecks类代码示例

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


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

示例1: ArbitraryJsonValiditySpec

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

import fixtures.generators._
import fixtures.{PetstoreAPI => P}
import helpers.CustomMatchers
import org.scalatest._
import org.scalatest.prop.{Checkers, GeneratorDrivenPropertyChecks}
import swaggerblocks.rendering.json._

class ArbitraryJsonValiditySpec
    extends WordSpec
    with Checkers
    with MustMatchers
    with CustomMatchers
    with GeneratorDrivenPropertyChecks
    with ParallelTestExecution {

  implicit override val generatorDrivenConfig = PropertyCheckConfiguration(
    sizeRange = 10,
    workers = 4
  )

  "A spec with generated ApiRoot" when {
    "using 'renderPretty'" must {
      "produce valid swagger json" in {
        forAll(genApiRoot) { apiRoot =>
          val json = renderPretty(apiRoot, List.empty, List.empty)

          json must beValidSwaggerJson
        }
      }
    }
  }

  "A spec with generated ApiPathDefinition" when {
    "using 'renderPretty'" must {
      "produce valid swagger json" in {
        forAll(genApiPathDefinition) { apiPathDefinition =>
          val json = renderPretty(P.petstoreRoot, List(apiPathDefinition), List.empty)

          json must beValidSwaggerJson
        }
      }
    }
  }

  "A spec with generated ApiSchemaDefinitions" when {
    "using 'renderPretty'" must {
      "preoduce valid swagger json" in {
        forAll(genSchemaDefs()) { apiSchemaDefinitions =>
          val json = renderPretty(P.petstoreRoot, List.empty, apiSchemaDefinitions)

          json must beValidSwaggerJson
        }
      }
    }
  }
} 
开发者ID:felixbr,项目名称:swagger-blocks-scala,代码行数:59,代码来源:ArbitraryJsonValiditySpec.scala

示例2: MessageExtractorSuite

//设置package包名称以及导入依赖的类
package com.hivehome.kafka.connect.sqs

import com.amazon.sqs.javamessaging.message.{SQSObjectMessage, SQSBytesMessage, SQSTextMessage}
import org.scalacheck.Gen
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}

class MessageExtractorSuite extends FunSuite with GeneratorDrivenPropertyChecks with Matchers {

  test("should extract text message") {
    forAll(Gen.alphaStr) { text =>
      val msg = new SQSTextMessage(text)

      val actual = MessageExtractor(msg)

      actual shouldEqual text
    }
  }

  test("should extract bytes message") {
    forAll(Gen.alphaStr) { text =>
      val msg = new SQSBytesMessage()
      msg.writeBytes(text.getBytes)

      val actual = MessageExtractor(msg)

      actual shouldEqual text
    }
  }

  test("should extract object message") {
    forAll(Gen.alphaStr) { text =>
      val msg = new SQSObjectMessage()
      msg.setObject(text)

      val actual = MessageExtractor(msg)

      actual shouldEqual text
    }
  }
} 
开发者ID:ConnectedHomes,项目名称:sqs-kafka-connect,代码行数:42,代码来源:MessageExtractorSuite.scala

示例3: RgbColorTest

//设置package包名称以及导入依赖的类
package kokellab.utils.core.addons

import org.scalacheck.Gen
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, TableDrivenPropertyChecks}
import org.scalatest.{Matchers, PropSpec}


class RgbColorTest extends PropSpec with GeneratorDrivenPropertyChecks with TableDrivenPropertyChecks with Matchers {

	val gen = Gen.listOfN(6, Gen.frequency((10, Gen.numChar), (6, Gen.oneOf('A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f')))) map (_.mkString)
	val things = Table("0000ff", "0000ff")

	property(s"toHex(fromHex)) should be the identity") {
		forAll(gen) { (hexColor: String) =>
			RgbColor.fromHex(hexColor).toHex should equal (hexColor.toLowerCase)
		}}

	val blendGen: Gen[(List[String], String)] = Gen.oneOf(
		(List("CC3366", "99FF00"), "B39933"),
		(List("ff0000", "0000ff", "ff00ff"), "aa00aa")
	)

	property(s"Colors should blend correctly") {
		forAll(blendGen) { case (colors: Seq[String], correct: String) =>
			if (colors.nonEmpty) {
				RgbColor.blend(colors map RgbColor.fromHex).toHex should equal (correct.toLowerCase)
			}
		}}


} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:32,代码来源:RgbColorTest.scala

示例4: TextUtilsTest

//设置package包名称以及导入依赖的类
package kokellab.utils.core.addons

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{Matchers, PropSpec}

class TextUtilsTest extends PropSpec with GeneratorDrivenPropertyChecks with Matchers {

	property("signByte can be out of range") {
		assertThrows[NumberFormatException] {
			TextUtils.signByte("270")
		}
	}

	property("pint can be out of range") {
		assertThrows[NumberFormatException] {
			TextUtils.signByte("270")
		}
		assertThrows[NumberFormatException] {
			TextUtils.signByte("-1")
		}
	}

	property("pint strips .0") {
		TextUtils.pint("1000.0") should equal (1000)
	}

	property("signByte strips .0") {
		TextUtils.signByte("200.0") should equal (200 - 128)
		TextUtils.signByte("0.0") should equal (0 - 128)
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:33,代码来源:TextUtilsTest.scala

示例5: BarcoderTest

//设置package包名称以及导入依赖的类
package kokellab.utils.misc

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}

import com.google.zxing.BarcodeFormat
import org.scalacheck.Gen
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import org.scalatest.{Matchers, PropSpec}

class BarcoderTest extends PropSpec with GeneratorDrivenPropertyChecks with Matchers {

		def fakeEncodeDecode(text: String, barcodeFormat: BarcodeFormat, dimensions: (Int, Int), imageFormat: String): String =
			if (text.isEmpty) text else encodeDecode(text.toUpperCase, barcodeFormat, dimensions, imageFormat)

		def genBoundedList[T](maxSize: Int, gen: Gen[T]): Gen[List[T]] =
			Gen.choose(0, maxSize) flatMap (size => Gen.listOfN(size, gen))

		def genBoundedString(maxSize: Int, gen: Gen[Char]): Gen[String] =
			Gen.choose(0, maxSize) flatMap (size => Gen.listOfN(size, gen) map (_.mkString))

		def encodeDecode(text: String, codeFormat: BarcodeFormat, dimensions: (Int, Int), imageFormat: String): String = {
			val barcoder = new Barcoder(codeFormat, imageFormat, dimensions._1, dimensions._2)
			val os = new ByteArrayOutputStream()
			barcoder.encode(text, os)
			val is = new ByteArrayInputStream(os.toByteArray)
			barcoder.decode(is)
		}

		val imageFormatGen = Gen.oneOf("png", "jpg", "gif")
		def test(barcodeFormat: BarcodeFormat, dimensionsGen: Gen[(Int, Int)], stringGen: Gen[String]) = {
			property(s"Decoding an encoded string should yield the original string for ${barcodeFormat.name} codes") {
				forAll(imageFormatGen, stringGen, dimensionsGen) { (imageFormat: String, text: String, dimensions: (Int, Int)) =>
					fakeEncodeDecode(text, barcodeFormat, dimensions, imageFormat) should equal (text.toUpperCase)
				}
			}
		}

		val rectangularGen: Gen[(Int, Int)] = for {
			width <- Gen.choose(20, 100)
			height <- Gen.choose(20, 100)
		} yield (width, height)

		val squareGen: Gen[(Int, Int)] = for {
			size <- Gen.choose(20, 100)
		} yield (size, size)

		val code39And93Gen: Gen[String] = genBoundedString(48, Gen.frequency((36, Gen.alphaNumChar), (7, Gen.oneOf('-', '.', '$', '/', '+', '%', ' '))))
		test(BarcodeFormat.CODE_39, rectangularGen, code39And93Gen)
		test(BarcodeFormat.CODE_93, rectangularGen, code39And93Gen)

		// TODO this fails due to https://github.com/zxing/zxing/issues/716
		// there's nothing I can do now
//		test(BarcodeFormat.CODE_128, rectangularGen, genBoundedString(48, Gen.choose[Char](0x20, 127)))

		// TODO QR codes break; also not my fault
//		test(BarcodeFormat.QR_CODE, squareGen, genBoundedString(4296, Gen.frequency((36, Gen.alphaNumChar), (8, Gen.oneOf('-', '.', '$', '/', '+', '%', ' ', ':')))))

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:59,代码来源:BarcoderTest.scala

示例6: gen

//设置package包名称以及导入依赖的类
package org.dsa.iot.scala

import scala.collection.JavaConverters._

import org.dsa.iot.dslink.node.value.Value
import org.dsa.iot.dslink.util.json.{ JsonArray, JsonObject }
import org.scalacheck.{ Gen, Arbitrary }
import org.scalatest.{ BeforeAndAfterAll, Matchers, Suite, WordSpecLike }
import org.scalatest.prop.GeneratorDrivenPropertyChecks


trait AbstractSpec extends Suite
    with WordSpecLike
    with Matchers
    with BeforeAndAfterAll
    with GeneratorDrivenPropertyChecks {

  import Arbitrary._

  object gen {
    val ids = Gen.identifier.map(_.take(10))
    val scalars = Gen.oneOf(arbitrary[Number], arbitrary[Boolean], arbitrary[String], arbitrary[Array[Byte]])
    val scalarLists = Gen.resize(10, Gen.listOf(scalars))
    val scalarJavaLists = scalarLists.map(_.asJava)
    val scalarMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, scalars)))
    val scalarJavaMaps = scalarMaps.map(_.asJava)
    val anyLists = Gen.resize(10, Gen.listOf(Gen.oneOf(scalars, scalarLists, scalarMaps)))
    val anyMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, Gen.oneOf(scalars, scalarLists, scalarMaps))))
    val any = Gen.oneOf(scalars, anyLists, anyMaps)
  }

  object valueGen {
    val bools = arbitrary[Boolean] map (new Value(_))

    val ints = arbitrary[Int] map (new Value(_))
    val longs = arbitrary[Long] map (new Value(_))
    val shorts = arbitrary[Short] map (new Value(_))
    val bytes = arbitrary[Byte] map (new Value(_))
    val doubles = arbitrary[Double] map (new Value(_))
    val floats = arbitrary[Float] map (new Value(_))
    val numbers = Gen.oneOf(ints, longs, shorts, bytes, doubles, floats)

    val strings = arbitrary[String] map (new Value(_))

    val binary = arbitrary[Array[Byte]] map (new Value(_))

    val scalarArrays = gen.scalarLists map (x => new JsonArray(x.asJava))

    val scalarMaps = gen.scalarMaps map (x => new JsonObject(x.asInstanceOf[Map[String, Object]].asJava))

    val arrays = scalarArrays map (new Value(_))

    val maps = scalarMaps map (new Value(_))
  }
} 
开发者ID:IOT-DSA,项目名称:sdk-dslink-scala,代码行数:56,代码来源:AbstractSpec.scala

示例7: AlgosTests

//设置package包名称以及导入依赖的类
package org.ergoplatform.settings

import org.ergoplatform.ErgoGenerators
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import org.scalatest.{Matchers, PropSpec}

class AlgosTests extends PropSpec
  with PropertyChecks
  with GeneratorDrivenPropertyChecks
  with Matchers
  with ErgoGenerators with scorex.testkit.SerializationTests {


  property("blockIdDifficulty should be > 0") {
    forAll(genBytesList(32)) { id: Array[Byte] =>
      assert(Algos.blockIdDifficulty(Algos.hash(id)) > 0)

    }
  }
} 
开发者ID:ergoplatform,项目名称:ergo,代码行数:21,代码来源:AlgosTests.scala

示例8: SerializationTests

//设置package包名称以及导入依赖的类
package org.ergoplatform.serialization

import org.ergoplatform.ErgoGenerators
import org.ergoplatform.modifiers.history._
import org.ergoplatform.modifiers.mempool.AnyoneCanSpendTransactionSerializer
import org.ergoplatform.modifiers.mempool.proposition.AnyoneCanSpendNoncedBoxSerializer
import org.ergoplatform.nodeView.history.ErgoSyncInfoSerializer
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import org.scalatest.{Matchers, PropSpec}

class SerializationTests extends PropSpec
  with PropertyChecks
  with GeneratorDrivenPropertyChecks
  with Matchers
  with ErgoGenerators with scorex.testkit.SerializationTests {

  property("HeaderWithoutInterlinks serialization") {

    val serializer = HeaderSerializer
    forAll(headerGen) { b: Header =>
      val recovered = serializer.parseBytes(serializer.bytesWithoutInterlinks(b)).get.copy(interlinks = b.interlinks)
      recovered shouldBe b
    }
  }

  property("AnyoneCanSpendBoxGen serialization") {
    checkSerializationRoundtrip(anyoneCanSpendBoxGen, AnyoneCanSpendNoncedBoxSerializer)
  }

  property("AnyoneCanSpendTransactionGen serialization") {
    checkSerializationRoundtrip(anyoneCanSpendTransactionGen, AnyoneCanSpendTransactionSerializer)
  }

  property("ErgoSyncInfo serialization") {
    checkSerializationRoundtrip(ergoSyncInfoGen, ErgoSyncInfoSerializer)
  }

  property("ErgoHeader serialization") {
    checkSerializationRoundtrip(headerGen, HeaderSerializer)
  }

  property("BlockTransactions serialization") {
    checkSerializationRoundtrip(blockTransactionsGen, BlockTransactionsSerializer)
  }

  property("ADProofs serialization") {
    checkSerializationRoundtrip(randomADProofsGen, ADProofSerializer)
  }

} 
开发者ID:ergoplatform,项目名称:ergo,代码行数:51,代码来源:SerializationTests.scala

示例9: ErgoMemPoolTest

//设置package包名称以及导入依赖的类
package org.ergoplatform.nodeView.mempool

import org.ergoplatform.ErgoGenerators
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import org.scalatest.{Matchers, PropSpec}

import scala.concurrent.Await
import scala.concurrent.duration._

class ErgoMemPoolTest extends PropSpec
  with PropertyChecks
  with GeneratorDrivenPropertyChecks
  with Matchers
  with ErgoGenerators {
  property("wait for the appearance of transactions") {
    forAll(blockTransactionsGen) { blockTransactions =>
      val memPool = ErgoMemPool.empty
      val ids = blockTransactions.txs.map(_.id)
      val transactionsFuture = memPool.waitForAll(ids)

      memPool.put(blockTransactions.txs)

      val transactionsFromMempool = Await.result(transactionsFuture, 5.seconds)
      transactionsFromMempool should contain theSameElementsAs blockTransactions.txs
      memPool.waitedForAssembly shouldBe 'empty
    }
  }
} 
开发者ID:ergoplatform,项目名称:ergo,代码行数:29,代码来源:ErgoMemPoolTest.scala

示例10: DigestStateSpecification

//设置package包名称以及导入依赖的类
package org.ergoplatform.nodeView.state

import org.ergoplatform.ErgoGenerators
import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import scorex.testkit.TestkitHelpers


class DigestStateSpecification extends PropSpec
  with PropertyChecks
  with GeneratorDrivenPropertyChecks
  with Matchers
  with ErgoGenerators
  with TestkitHelpers {

  property("validate() - valid block") {

  }

  property("validate() - invalid block") {
    forAll(invalidErgoFullBlockGen){b =>
      val state = new DigestState(Array.fill(32)(0:Byte))
      state.validate(b).isFailure shouldBe true
    }
  }

  property("applyModifier() - valid block") {

  }

  property("applyModifier() - invalid block") {
    forAll(invalidErgoFullBlockGen){b =>
      val state = new DigestState(Array.fill(32)(0:Byte))
      state.applyModifier(b).isFailure shouldBe true
    }
  }
} 
开发者ID:ergoplatform,项目名称:ergo,代码行数:38,代码来源:DigestStateSpecification.scala

示例11: 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

示例12: PhoneNumberTest

//设置package包名称以及导入依赖的类
package org.videlalvaro.phoneguide

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}
import org.videlalvaro.phoneguide.generators.Generators._



class PhoneNumberTest extends FunSuite with GeneratorDrivenPropertyChecks with Matchers {

  test("equals should be reflexive") {
    forAll { (phoneNumber: PhoneNumber) =>
      phoneNumber.equals(phoneNumber) should be (true)
    }
  }

  test("equals should be symmetric") {
    forAll { (phoneNumber: PhoneNumber) =>
      val phoneNumber2 = PhoneNumber.fromPhoneNumber(phoneNumber)
      phoneNumber.equals(phoneNumber2) should be (true)
      phoneNumber2.equals(phoneNumber) should be (true)
    }
  }

  test("equals should be transitive") {
    forAll { (phoneNumber: PhoneNumber) =>
      val phoneNumber2 = PhoneNumber.fromPhoneNumber(phoneNumber)
      val phoneNumber3 = PhoneNumber.fromPhoneNumber(phoneNumber2)
      phoneNumber.equals(phoneNumber2) should be (true)
      phoneNumber.equals(phoneNumber3) should be (true)
      phoneNumber2.equals(phoneNumber) should be (true)
      phoneNumber2.equals(phoneNumber3) should be (true)
      phoneNumber3.equals(phoneNumber) should be (true)
      phoneNumber3.equals(phoneNumber2) should be (true)
    }
  }

  test("equals should be consistent") {
    forAll { (phoneNumber: PhoneNumber) =>
      val phoneNumber2 = PhoneNumber.fromPhoneNumber(phoneNumber)
      phoneNumber.equals(phoneNumber2) should be (true)
      phoneNumber.equals(phoneNumber2) should be (true)
      phoneNumber2.equals(phoneNumber) should be (true)
      phoneNumber2.equals(phoneNumber) should be (true)
    }
  }

  test("equals should respect non-nullity") {
    forAll { (phoneNumber: PhoneNumber) =>
      phoneNumber.equals(null) should be (false)
    }
  }
} 
开发者ID:videlalvaro,项目名称:phone-guide,代码行数:54,代码来源:PhoneNumberTest.scala

示例13: EncoderDecoderTest

//设置package包名称以及导入依赖的类
package org.videlalvaro.phoneguide.netty

import io.netty.channel.embedded.EmbeddedChannel
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FunSuite, Matchers}
import org.videlalvaro.phoneguide.PhoneNumber
import org.videlalvaro.phoneguide.generators.Generators._

class EncoderDecoderTest extends FunSuite with GeneratorDrivenPropertyChecks with Matchers {
  test("netty encode/decode message") {
    forAll { (phoneNumber: PhoneNumber) =>
      val channel = new EmbeddedChannel(new MessageEncoder(), new MessageDecoder())

      channel.writeOutbound(phoneNumber)
      channel.writeInbound(channel.readOutbound())

      val readPhoneNumber = channel.readInbound();
      readPhoneNumber should not be (null)
      readPhoneNumber.equals(phoneNumber) should be (true)
      phoneNumber.equals(readPhoneNumber) should be (true)
    }
  }
} 
开发者ID:videlalvaro,项目名称:phone-guide,代码行数:24,代码来源:EncoderDecoderTest.scala

示例14: HttpRequestCanonicalizerSpec

//设置package包名称以及导入依赖的类
package io.toolsplus.atlassian.jwt

import io.toolsplus.atlassian.jwt.generators.core.JwtGen
import io.toolsplus.atlassian.jwt.generators.nimbus.NimbusGen
import org.scalatest.prop.GeneratorDrivenPropertyChecks

class HttpRequestCanonicalizerSpec
    extends TestSpec
    with GeneratorDrivenPropertyChecks
    with JwtGen
    with NimbusGen {

  "Using a HttpRequestCanonicalizer" when {

    "given a valid CanonicalHttpRequest" should {

      "compute the correct canonical request string" in forAll(
        canonicalHttpRequestGen) { request =>
        def partsOf(r: String) =
          r.split(HttpRequestCanonicalizer.CANONICAL_REQUEST_PART_SEPARATOR)
        val canonicalizedRequest =
          HttpRequestCanonicalizer.canonicalize(request)
        if (canonicalizedRequest.endsWith("&"))
          partsOf(canonicalizedRequest).length mustBe 2
      }

      "compute the correct canonical method string" in forAll(
        canonicalHttpRequestGen) { request =>
        val canonicalizedMethod =
          HttpRequestCanonicalizer.canonicalizeMethod(request)
        canonicalizedMethod mustBe canonicalizedMethod.toUpperCase
      }

      "compute the correct canonical uri string" in forAll(
        canonicalHttpRequestGen) { request =>
        val canonicalizedUri =
          HttpRequestCanonicalizer.canonicalizeUri(request)
        canonicalizedUri must startWith("/")
        if (canonicalizedUri.length > 1) canonicalizedUri must not endWith "/"
        canonicalizedUri must not contain HttpRequestCanonicalizer.CANONICAL_REQUEST_PART_SEPARATOR
      }

      "successfully compute canonical request hash" in forAll(
        canonicalHttpRequestGen) { request =>
        val canonicalRequestHash =
          HttpRequestCanonicalizer.computeCanonicalRequestHash(request)

      }

    }

  }

} 
开发者ID:toolsplus,项目名称:atlassian-jwt,代码行数:55,代码来源:HttpRequestCanonicalizerSpec.scala

示例15: RichLongSpec

//设置package包名称以及导入依赖的类
package swave.core.util

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FreeSpec, Matchers}

class RichLongSpec extends FreeSpec with Matchers with GeneratorDrivenPropertyChecks {

  "RichLong" - {
    val longMin = BigDecimal(Long.MinValue)
    val longMax = BigDecimal(Long.MaxValue)
    def bounded(d: BigDecimal) =
      if (d < longMin) Long.MinValue
      else if (d > longMax) Long.MaxValue
      else d.longValue()

    "?" in {
      forAll { (x: Long, y: Long) ?
        x ? y shouldEqual bounded(BigDecimal(x) + BigDecimal(y))
      }
    }

    "×" in {
      forAll { (x: Long, y: Long) ?
        (x × y) shouldEqual bounded(BigDecimal(x) * BigDecimal(y))
      }
    }
  }
} 
开发者ID:sirthias,项目名称:swave,代码行数:29,代码来源:RichLongSpec.scala


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