本文整理汇总了Scala中org.scalatest.prop.Checkers类的典型用法代码示例。如果您正苦于以下问题:Scala Checkers类的具体用法?Scala Checkers怎么用?Scala Checkers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Checkers类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Converter1Test2
//设置package包名称以及导入依赖的类
package com.stulsoft.pscalacheck.myclasses
import org.scalacheck.Gen
import org.scalacheck.Prop.forAll
import org.scalatest.FlatSpec
import org.scalatest.prop.Checkers
class Converter1Test2 extends FlatSpec with Checkers {
behavior of "Converter1"
"toInt" should "produce length of names for all symbols" in {
// ScalaTest style
check((x: String) => Converter1(x).toInt == x.length)
}
it should "produce length for ASCII symbols" in {
// ScalaCheck style
val usAsciiStringGen = Gen.containerOf[Array, Char](Gen.choose[Char](0, 127)).map(_.mkString)
forAll(usAsciiStringGen) { x: String => Converter1(x).toInt == x.length }
}
}
开发者ID:ysden123,项目名称:poc,代码行数:22,代码来源:Converter1Test2.scala
示例17: CommandsResultsSyntaxSpec
//设置package包名称以及导入依赖的类
package ru.pavkin.todoist.api.core.model
import java.util.UUID
import org.scalatest.prop.Checkers
import org.scalatest.{FunSuite, Matchers}
import ru.pavkin.todoist.api.core.model.util.{ReversedAtSyntax, CommandResultHList, CombineCommands}
import shapeless.HNil
import shapeless.test.{typed, illTyped}
class CommandsResultsSyntaxSpec extends FunSuite
with Matchers
with Checkers
with CommandResultHList.Syntax
with ReversedAtSyntax {
def id = UUID.randomUUID()
val success = CommandResult(id, CommandSuccess)
val failure = CommandResult(id, CommandFailure(1, "error"))
val tempIdSuccess = TempIdCommandResult(id, TempIdSuccess(id, 666))
val tempIdFailure = TempIdCommandResult(id, TempIdFailure(2, "error"))
val multiSuccess = CommandResult(id, MultiItemCommandStatus(Map(1 -> CommandSuccess, 2 -> CommandSuccess)))
val partialFailure = CommandResult(
id, MultiItemCommandStatus(Map(1 -> CommandFailure(1, "error"), 2 -> CommandSuccess))
)
test("Typesafe resultFor should get the command under reversed index") {
val result = success :: tempIdFailure :: HNil
result.resultFor(_0) shouldBe tempIdFailure
typed[TempIdCommandResult](result.resultFor(_0))
result.resultFor(_1) shouldBe success
typed[CommandResult](result.resultFor(_1))
illTyped("""result.resultFor(_2)""")
}
test("Runtime resultFor should get the command with uuid") {
val result = success :: tempIdFailure :: HNil
result.resultFor(success.uuid) shouldBe Some(success)
typed[Option[TodoistCommandResult]](result.resultFor(success.uuid))
result.resultFor(tempIdFailure.uuid) shouldBe Some(tempIdFailure)
result.resultFor(failure.uuid) shouldBe None
}
test("single command result isSuccess is true only in case of success") {
success.isSuccess shouldBe true
tempIdSuccess.isSuccess shouldBe true
multiSuccess.isSuccess shouldBe true
failure.isSuccess shouldBe false
tempIdFailure.isSuccess shouldBe false
partialFailure.isSuccess shouldBe false
}
test("Multiple results are success if all commands succeed") {
(success :: tempIdSuccess :: multiSuccess :: HNil).isSuccess shouldBe true
(success :: tempIdSuccess :: failure :: HNil).isSuccess shouldBe false
(partialFailure :: success :: HNil).isSuccess shouldBe false
}
}
开发者ID:vpavkin,项目名称:scalist,代码行数:60,代码来源:CommandsResultsSyntaxSpec.scala
示例18: CombineCommandsSyntaxSpec
//设置package包名称以及导入依赖的类
package ru.pavkin.todoist.api.core.model
import java.util.UUID
import org.scalacheck.Arbitrary
import org.scalatest.prop.Checkers
import org.scalatest.{FunSuite, Matchers}
import ru.pavkin.todoist.api.core.model.util.CombineCommands
import ru.pavkin.todoist.api.core.tags.syntax._
import shapeless.HNil
import shapeless.test.illTyped
class CombineCommandsSyntaxSpec extends FunSuite with Matchers with Checkers with CombineCommands.Syntax {
implicit val gen = Arbitrary(org.scalacheck.Gen.uuid)
val c1 = AddProject("Project")
val c2 = AddLabel("Label")
val c3 = AddTask("Task", 1.projectId)
test("Commands combine in HList") {
c1 :+ c2 shouldBe c1 :: c2 :: HNil
}
test("HList :+ works with combined commands") {
c1 :+ c2 :+ c3 shouldBe c1 :: c2 :: c3 :: HNil
}
test("forIt creates temp_id dependant command") {
val uuid = UUID.randomUUID
val tempId = UUID.randomUUID
c1.forIt(AddTask("task", _, uuid = uuid, tempId = tempId.taskId)) shouldBe
AddTask[UUID]("task", c1.tempId, uuid = uuid, tempId = tempId.taskId)
}
test("andForIt creates temp_id dependant command and adds it to the parent") {
check { (uuid: UUID, tempId: UUID) =>
c1.andForIt(AddTask("task", _, uuid = uuid, tempId = tempId.taskId)) ==
(c1 :: AddTask[UUID]("task", c1.tempId, uuid = uuid, tempId = tempId.taskId) :: HNil)
}
}
test("andForItAll creates temp_id dependant commands and adds them to the parent") {
check { (uuid1: UUID, tempId1: UUID, uuid2: UUID, tempId2: UUID) =>
c1.andForItAll(id =>
AddTask("task", id, uuid = uuid1, tempId = tempId1.taskId) :+
AddTask("task2", id, uuid = uuid2, tempId = tempId2.taskId)
) ==
(c1 ::
AddTask[UUID]("task", c1.tempId, uuid = uuid1, tempId = tempId1.taskId) ::
AddTask[UUID]("task2", c1.tempId, uuid = uuid2, tempId = tempId2.taskId) ::
HNil)
}
}
test("Only Commands combine") {
illTyped("""12 :+ 13""")
illTyped(""" true :+ 2 """)
}
}
开发者ID:vpavkin,项目名称:scalist,代码行数:61,代码来源:CombineCommandsSyntaxSpec.scala
示例19: CommandResponseDecoderSpec
//设置package包名称以及导入依赖的类
package ru.pavkin.todoist.api.core.decoder
import cats.Id
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.test.illTyped
import shapeless.{::, HNil}
import scala.util.Try
class CommandResponseDecoderSpec extends FunSuite with Checkers {
val stingLengthParser = SingleCommandResponseDecoder.using[Id, Int, String, Boolean] {
(c: Int, s: String) => Try(s.length == c).getOrElse(false)
}
val toLongParser = SingleCommandResponseDecoder.using[Id, Double, String, Long] {
(c: Double, s: String) => Try(c.ceil.toLong).getOrElse(0L)
}
val identityCommandParser = SingleCommandResponseDecoder.using[Id, Int, String, String] {
(c: Int, s: String) => c.toString + s
}
val longEqualsToDoubleParser = SingleCommandResponseDecoder.using[Id, Double, Long, Boolean] {
(c: Double, s: Long) => c.ceil.toLong == s
}
test("CommandResponseDecoder") {
implicit val p1 = stingLengthParser
implicit val p2 = toLongParser
implicitly[MultipleCommandResponseDecoder.Aux[Id, Double :: Int :: HNil, String, Long :: Boolean :: HNil]]
implicitly[MultipleCommandResponseDecoder.Aux[Id, Int :: Double :: HNil, String, Boolean :: Long :: HNil]]
implicitly[MultipleCommandResponseDecoder.Aux[Id, Int :: HNil, String, Boolean :: HNil]]
illTyped("""implicitly[SingleCommandResponseDecoder[Id, Boolean, String]]""")
illTyped("""implicitly[MultipleCommandResponseDecoder[Id, String :: HNil, String]]""")
illTyped("""implicitly[MultipleCommandResponseDecoder[Id, Double :: String :: HNil, String]]""")
illTyped("""implicitly[MultipleCommandResponseDecoder[Id, String :: Double :: HNil, String]]""")
}
test("CommandResponseDecoder identity") {
check { (i: Int, a: String) => identityCommandParser.parse(i)(a) == i.toString + a }
}
test("CommandResponseDecoder combination") {
check { (i: Int, d: Double, r: String) =>
stingLengthParser
.combine(toLongParser)
.parse(d :: i :: HNil)(r) ==
toLongParser.parse(d)(r) :: stingLengthParser.parse(i)(r) :: HNil
}
}
test("CommandResponseDecoder composition") {
check { (i: Double, r: String) =>
toLongParser.compose(longEqualsToDoubleParser).parse(i)(r) ==
longEqualsToDoubleParser.parse(i)(toLongParser.parse(i)(r))
}
}
}
开发者ID:vpavkin,项目名称:scalist,代码行数:60,代码来源:CommandResponseDecoderSpec.scala
示例20: execute
//设置package包名称以及导入依赖的类
package ru.pavkin.todoist.api.core
import cats.Id
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import ru.pavkin.todoist.api.RawRequest
import ru.pavkin.todoist.api.utils.Produce
trait RequestDefinitionSpec extends FunSuite with Checkers {
type Req = String
type Base = Int
val requestFactory: RawRequest Produce Req = Produce(_.values.flatten.mkString)
val stringLenghtRequestExecutor: RequestExecutor.Aux[Req, Id, Base] = new RequestExecutor[Req, Id] {
type Res = Base
def execute(r: Req): Id[Res] = r.length
}
val toIntRequestExecutor: RequestExecutor.Aux[Req, Id, Base] = new RequestExecutor[Req, Id] {
type Res = Base
def execute(r: Req): Id[Res] = r.toInt
}
def identityRequestExecutor[T]: RequestExecutor.Aux[T, Id, T] = new RequestExecutor[T, Id] {
type Res = T
def execute(r: T): Id[T] = r
}
}
开发者ID:vpavkin,项目名称:scalist,代码行数:30,代码来源:RequestDefinitionSpec.scala
注:本文中的org.scalatest.prop.Checkers类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论