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


Scala Checkers类代码示例

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


在下文中一共展示了Checkers类的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: SyntaxSpec

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

import org.scalacheck.Shapeless._
import org.scalaexercises.Test
import org.scalatest.prop.Checkers
import org.scalatest.refspec.RefSpec
import shapeless.HNil

class SyntaxSpec extends RefSpec with Checkers {

  import Test._
  import fetchlib.FetchTutorialHelper._
  import fetchlib.SyntaxSection._

  def `Implicit Syntax`: Unit =
    check(testSuccess(implicitSyntax _, 42 :: HNil))

  def `Error Syntax`: Unit =
    check(testSuccess(errorSyntax _, true :: HNil))

  def `runA Syntax`: Unit =
    check(testSuccess(runA _, 1 :: HNil))

  def `runE Syntax`: Unit =
    check(testSuccess(runE _, true :: HNil))

  def `runF Syntax`: Unit =
    check(testSuccess(runF _, 1 :: true :: HNil))

  def `Pure Syntax`: Unit =
    check(testSuccess(companionPure _, 42 :: HNil))

  def `Join Syntax`: Unit =
    check(testSuccess(companionJoin _, (Post(1, 2, "An article"), User(2, "@two")) :: HNil))

  def `Sequence Syntax`: Unit = {
    check(
      testSuccess(
        companionSequence _,
        List(User(1, "@one"), User(2, "@two"), User(3, "@three")) :: HNil))
  }

  def `Traverse Syntax`: Unit = {
    check(
      testSuccess(
        companionTraverse _,
        List(User(1, "@one"), User(2, "@two"), User(3, "@three")) :: HNil))
  }

} 
开发者ID:scala-exercises,项目名称:exercises-fetch,代码行数:51,代码来源:SyntaxSpec.scala

示例3: UsageSpec

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

import fetchlib.FetchTutorialHelper.{postDatabase, userDatabase}
import org.scalacheck.Shapeless._
import org.scalaexercises.Test.testSuccess
import org.scalatest.prop.Checkers
import org.scalatest.refspec.RefSpec
import shapeless.HNil

class UsageSpec extends RefSpec with Checkers {

  def `Creating And Running`: Unit =
    check(testSuccess(UsageSection.creatingAndRunning _, userDatabase(1) :: HNil))

  def `Sequencing Strategy`: Unit =
    check(testSuccess(UsageSection.sequencing _, (userDatabase(1), userDatabase(2)) :: HNil))

  def `Batching Strategy`: Unit =
    check(testSuccess(UsageSection.batching _, (userDatabase(1), userDatabase(2)) :: HNil))

  def `Deduplication Strategy`: Unit =
    check(testSuccess(UsageSection.deduplication _, (userDatabase(1), userDatabase(1)) :: HNil))

  def `Caching Strategy`: Unit =
    check(testSuccess(UsageSection.caching _, (userDatabase(1), userDatabase(1)) :: HNil))

  def `Combining Data`: Unit =
    check(testSuccess(UsageSection.combiningData _, (postDatabase(1), "applicative") :: HNil))

  def `Combining Concurrency`: Unit =
    check(testSuccess(UsageSection.concurrency _, (postDatabase(1), userDatabase(2)) :: HNil))

  def `Combinators sequence`: Unit = {
    check(
      testSuccess(
        UsageSection.sequence _,
        List(userDatabase(1), userDatabase(2), userDatabase(3)) :: HNil))
  }

  def `Combinators traverse`: Unit = {
    check(
      testSuccess(
        UsageSection.traverse _,
        List(userDatabase(1), userDatabase(2), userDatabase(3)) :: HNil))
  }

} 
开发者ID:scala-exercises,项目名称:exercises-fetch,代码行数:48,代码来源:UsageSpec.scala

示例4: CachingSpec

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

import fetchlib.FetchTutorialHelper.userDatabase
import org.scalacheck.Shapeless._
import org.scalaexercises.Test.testSuccess
import org.scalatest.prop.Checkers
import org.scalatest.refspec.RefSpec
import shapeless.HNil

class CachingSpec extends RefSpec with Checkers {

  def `Cache Prepopulating`: Unit =
    check(testSuccess(CachingSection.prepopulating _, 1 :: "@one" :: HNil))

  def `Cache Partial Hits`: Unit =
    check(testSuccess(CachingSection.cachePartialHits _, "@one" :: "@dialelo" :: HNil))

  def `Cache Replay`: Unit =
    check(testSuccess(CachingSection.replaying _, 1 :: 0 :: HNil))

  def `Cache Custom`: Unit =
    check(testSuccess(CachingSection.customCache _, 2 :: HNil))
} 
开发者ID:scala-exercises,项目名称:exercises-fetch,代码行数:24,代码来源:CachingSpec.scala

示例5: QuickCheckBinomialHeap

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

import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._

import org.scalatest.exceptions.TestFailedException

object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap

@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
  def checkBogus(p: Prop) {
    var ok = false
    try {
      check(p)
    } catch {
      case e: TestFailedException =>
        ok = true
    }
    assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
  }

  test("Binomial heap satisfies properties.") {
    check(new QuickCheckHeap with quickcheck.test.BinomialHeap)
  }

  test("Bogus (1) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with quickcheck.test.Bogus1BinomialHeap)
  }

  test("Bogus (2) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with quickcheck.test.Bogus2BinomialHeap)
  }

  test("Bogus (3) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with quickcheck.test.Bogus3BinomialHeap)
  }

  test("Bogus (4) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with quickcheck.test.Bogus4BinomialHeap)
  }

  test("Bogus (5) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with quickcheck.test.Bogus5BinomialHeap)
  }
} 
开发者ID:vincenzobaz,项目名称:Functional-Programming-in-Scala,代码行数:53,代码来源:QuickCheckSuite.scala

示例6: VisualizationTest

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


import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers
import observatory.Visualization._
import observatory.Extraction._

@RunWith(classOf[JUnitRunner])
class VisualizationTest extends FunSuite with Checkers {

  test("should interpolate color correctly") {
    val c = interpolateColor(List((0.0, Color(255, 0, 0)), (2.147483647E9, Color(0, 0, 255))), 5.3687091175E8)

    assert(c.red === 191)
    assert(c.green === 0)
    assert(c.blue === 64)
  }

  test("exceeding the greatest value of a color scale should return the color associated with the greatest value") {
    val c = interpolateColor(List((-1.0,Color(255, 0, 0)), (15.39640384017234, Color(0,0,255))), 25.39640384017234)

    assert(c.red === 0)
    assert(c.green === 0)
    assert(c.blue === 255)
  }

  test("should predicate temperature correctly") {
    val t1 = predictTemperature(List((Location(0, 0), 10), (Location(-45, 90), 40)), Location(0, 0.001))
    val t2 = predictTemperature(List((Location(0, 0), 10), (Location(-45, 90), 40)), Location(-45, 90.001))
    val t3 = predictTemperature(List((Location(0, 0), 10), (Location(-45, 90), 40)), Location(-45, 90))

    println(t1)
    println(t2)

    assert(t3 === 40)
  }

  test("should output a image by given year correctly") {
    val colors: List[(Double, Color)] = List((60.0, Color(255, 255, 255)), (32.0, Color(255, 0, 0)), (12.0, Color(255, 255, 0)),
                                             (0, Color(0, 255, 255)), (-15.0, Color(0, 0, 255)), (-27.0, Color(255, 0, 255)),
                                             (-50.0, Color(33, 0, 107)), (-60.0, Color(0, 0, 0)))
    val locations = locationYearlyAverageRecords(locateTemperatures(1986, "/stations.csv", "/1986.csv"))
    //val locations = List((Location(0, 0), 10d), (Location(-45, 90), 40d))
    val img = visualize(locations, colors)
    img.output(new java.io.File("output.png"))
  }
} 
开发者ID:syhan,项目名称:coursera,代码行数:51,代码来源:VisualizationTest.scala

示例7: NativeExampleSuite

//设置package包名称以及导入依赖的类
package com.highperformancespark.examples.ffi

import com.holdenkarau.spark.testing._
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.Prop.forAll
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import org.scalatest.Matchers._

class NativeExampleSuite extends FunSuite
    with SharedSparkContext with Checkers with RDDComparisons {

  test("local sum") {
    val input = Array(1, 2, 3)
    val sumMagic = new SumJNI()
    val result = sumMagic.sum(input)
    val expected = 6
    assert(result === expected)
  }

  test("super simple test") {
    val input = sc.parallelize(List(("hi", Array(1, 2, 3))))
    val result = NativeExample.jniSum(input).collect()
    val expected = List(("hi", 6))
    assert(result === expected)
  }

  test("native call should find sum correctly") {
    val property = forAll(
      RDDGenerator.genRDD[(String, Array[Int])](sc)(
        Arbitrary.arbitrary[(String, Array[Int])])) {
      rdd =>
        val expected = rdd.mapValues(_.sum)
        val result = NativeExample.jniSum(rdd)
        compareRDDWithOrder(expected, result).isEmpty
    }
    check(property)
  }

  test("JNA support") {
    val input = Array(1, 2, 3)
    assert(6 === SumJNA.sum(input, input.size))
  }

  test("JNA Fortran support") {
    val input = Array(1, 2, 3)
    assert(6 === SumFJNA.easySum(input.size, input))
  }
} 
开发者ID:gourimahapatra,项目名称:high-performance-spark,代码行数:50,代码来源:NativeExample.scala

示例8: AvroSpec

//设置package包名称以及导入依赖的类
package com.lukecycon.avro

import org.scalatest.FreeSpec
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._

class AvroSpec extends FreeSpec with Checkers {

  def roundTrip[T: AvroFormat](v: T, comp: Boolean = false) =
    Avro.read(Avro.write(v, comp), comp)

  def checkPrimative[T: Arbitrary: AvroFormat](name: String) =
    s"Avro roundTrip should be identity for $name" - {
      "uncompressed" in {
        check { i: T =>
          roundTrip(i) == Right(i)
        }
      }

      "compressed" in {
        check { i: T =>
          roundTrip(i, true) == Right(i)
        }
      }
    }

  checkPrimative[Boolean]("Boolean")
  checkPrimative[Int]("Int")
  checkPrimative[Long]("Long")
  checkPrimative[Float]("Float")
  checkPrimative[Double]("Double")
  checkPrimative[Seq[Byte]]("bytes")
  checkPrimative[String]("Sstring")
  checkPrimative[Option[Int]]("Option[_]")
  checkPrimative[Either[Int, String]]("Either[_]")
  checkPrimative[List[Int]]("List[_]")
  checkPrimative[Map[String, Int]]("Map[String, _]")
} 
开发者ID:themattchan,项目名称:Skaro,代码行数:41,代码来源:AvroSpec.scala

示例9: QuickCheckBinomialHeap

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

import org.scalatest.FunSuite

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop
import org.scalacheck.Prop._

import org.scalatest.exceptions.TestFailedException

object QuickCheckBinomialHeap extends QuickCheckHeap with BinomialHeap

@RunWith(classOf[JUnitRunner])
class QuickCheckSuite extends FunSuite with Checkers {
  def checkBogus(p: Prop) {
    var ok = false
    try {
      check(p)
    } catch {
      case e: TestFailedException =>
        ok = true
    }
    assert(ok, "A bogus heap should NOT satisfy all properties. Try to find the bug!")
  }

  test("Binomial heap satisfies properties.") {
    check(new QuickCheckHeap with BinomialHeap)
  }

  test("Bogus (1) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus1BinomialHeap)
  }

  test("Bogus (2) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus2BinomialHeap)
  }

  test("Bogus (3) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus3BinomialHeap)
  }

  test("Bogus (4) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus4BinomialHeap)
  }

  test("Bogus (5) binomial heap does not satisfy properties.") {
    checkBogus(new QuickCheckHeap with Bogus5BinomialHeap)
  }
} 
开发者ID:zearom32,项目名称:Courses,代码行数:54,代码来源:QuickCheckSuite.scala

示例10: RootApiSpec

//设置package包名称以及导入依赖的类
package com.aluxian.susucatbot.controllers

import com.twitter.finagle.http.Status
import io.finch._
import org.scalatest.prop.Checkers
import org.scalatest.{FlatSpec, Matchers}

class RootApiSpec extends FlatSpec with Matchers with Checkers {

  behavior of "root endpoint"

  it should "return 'ok'" in {
    val input = Input.get("/")
    val res = RootCtrl.root(input)
    res.output.map(_.status) === Some(Status.Ok)
    res.value.isDefined === true
    res.value.get shouldBe "ok"
  }

} 
开发者ID:aluxian,项目名称:SusuCatBot,代码行数:21,代码来源:RootApiSpec.scala

示例11: SparqlSpec

//设置package包名称以及导入依赖的类
package com.graphula.sparql

import org.scalatest.fixture.FlatSpec
import org.scalatest.fixture.UnitFixture
import org.scalatest.prop.Checkers
import org.apache.jena.graph.NodeFactory
import org.apache.jena.graph.Triple
import org.apache.jena.query.QueryFactory
import org.apache.jena.query.QueryExecutionFactory
import collection.JavaConversions._
import com.graphula.SparqlFixture

class SparqlSpec extends FlatSpec with Checkers with UnitFixture {

  "Sparql" should "answer a basic graph pattern" in new SparqlFixture {
    val prefix = "http://"
    val s = NodeFactory.createURI(s"${prefix}s")
    val p = NodeFactory.createURI(s"${prefix}p")
    val o = NodeFactory.createURI(s"${prefix}o")
    sparql.add(new Triple(s, p, o))
    sparql.add(new Triple(o, p, o))
    val queryString = """ | PREFIX p: <http://>
                | SELECT ?X ?Y
                | WHERE {
                |  ?X p:p ?Y .
                |  ?Y p:p p:o .
                |}""".stripMargin
    val results = sparql.execute(queryString)
    val resultMaps = results.map { r =>
      r.varNames.map { variable =>
        variable -> r.get(variable).toString
      }.toMap
    }.toSet
    assert(resultMaps == Set(
      Map("X" -> s"${prefix}s", "Y" -> s"${prefix}o"),
      Map("X" -> s"${prefix}o", "Y" -> s"${prefix}o")))
  }

  it should "answer a graph pattern that contains a failing existence check" in new SparqlFixture {
    val prefix = "http://"
    val s = NodeFactory.createURI(s"${prefix}s")
    val p = NodeFactory.createURI(s"${prefix}p")
    val o = NodeFactory.createURI(s"${prefix}o")
    sparql.add(new Triple(s, p, o))
    val queryString = """ | PREFIX p: <http://>
                | SELECT ?X ?Y
                | WHERE {
                |  ?X p:p ?Y .
                |  ?Y p:p p:o .
                |}""".stripMargin
    val results = sparql.execute(queryString)
    val resultMaps = results.map { r =>
      r.varNames.map { variable =>
        variable -> r.get(variable).toString
      }.toMap
    }.toSet
    assert(resultMaps == Set.empty)
  }

} 
开发者ID:codacy-badger,项目名称:graphula,代码行数:61,代码来源:SparqlSpec.scala

示例12: ScalacheckDatetimeSpec

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

import org.scalacheck.Shapeless._
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class ScalacheckDatetimeSpec extends FunSuite with Checkers {

  test("simple usage") {

    check(
      Test.testSuccess(
        ScalacheckDatetimeSection.usage _,
        true :: HNil
      )
    )
  }

  test("granularity") {

    check(
      Test.testSuccess(
        ScalacheckDatetimeSection.granularity _,
        1 :: 0 :: 0 :: 0 :: 0 :: HNil
      )
    )
  }

  test("ranges") {

    check(
      Test.testSuccess(
        ScalacheckDatetimeSection.ranges _,
        2016 :: HNil
      )
    )
  }

  test("granularity and ranges together") {

    check(
      Test.testSuccess(
        ScalacheckDatetimeSection.granularityAndRanges _,
        2016 :: 0 :: 0 :: 0 :: 0 :: HNil
      )
    )
  }

} 
开发者ID:scala-exercises,项目名称:exercises-scalacheck,代码行数:51,代码来源:ScalacheckDatetimeSpec.scala

示例13: ArbitrarySpec

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

import org.scalacheck.Shapeless._
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class ArbitrarySpec extends FunSuite with Checkers {

  test("implicit arbitrary char") {

    check(
      Test.testSuccess(
        ArbitrarySection.implicitArbitraryChar _,
        Seq('A', 'E', 'I', 'O', 'U') :: HNil
      )
    )
  }

  test("implicit arbitrary case class") {

    check(
      Test.testSuccess(
        ArbitrarySection.implicitArbitraryCaseClass _,
        false :: HNil
      )
    )
  }

  test("arbitrary on gen") {

    check(
      Test.testSuccess(
        ArbitrarySection.useArbitraryOnGen _,
        8 :: HNil
      )
    )
  }

} 
开发者ID:scala-exercises,项目名称:exercises-scalacheck,代码行数:41,代码来源:ArbitrarySpec.scala

示例14: PropertiesSpec

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

import org.scalacheck.Shapeless._
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class PropertiesSpec extends FunSuite with Checkers {

  test("always ends with the second string") {

    check(
      Test.testSuccess(
        PropertiesSection.universallyQuantifiedPropertiesString _,
        true :: HNil
      )
    )
  }

  test("all numbers are generated between the desired interval") {

    check(
      Test.testSuccess(
        PropertiesSection.universallyQuantifiedPropertiesGen _,
        true :: HNil
      )
    )
  }

  test("all generated numbers are even") {

    check(
      Test.testSuccess(
        PropertiesSection.conditionalProperties _,
        0 :: HNil
      )
    )
  }

  test("only the second condition is true") {

    check(
      Test.testSuccess(
        PropertiesSection.combiningProperties _,
        false :: true :: HNil
      )
    )
  }

  test("the zero specification only works for 0") {

    check(
      Test.testSuccess(
        PropertiesSection.groupingProperties _,
        0 :: 0 :: 0 :: HNil
      )
    )
  }

} 
开发者ID:scala-exercises,项目名称:exercises-scalacheck,代码行数:61,代码来源:PropertiesSpec.scala

示例15: WindowedMaxTest

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

import org.junit.runner.RunWith
import org.scalacheck.Gen
import org.scalacheck.Prop.forAll
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import org.scalatest.prop.Checkers

@RunWith(classOf[JUnitRunner])
class WindowedMaxTest extends FunSuite with Checkers {
  test("return max") {
    check {
      forAll { ary: Array[Long] =>
        forAll(Gen.posNum[Int]) { window: Int =>
          val w = new WindowedMax(window)
          for (v <- ary) w.add(v)

          val expected =
            if (ary.isEmpty) Long.MinValue
            else if (window > ary.length) ary.max
            else ary.takeRight(window).max

          expected == w.get
        }
      }
    }
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:30,代码来源:WindowedMaxTest.scala


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