本文整理汇总了Scala中org.scalatest.Inspectors类的典型用法代码示例。如果您正苦于以下问题:Scala Inspectors类的具体用法?Scala Inspectors怎么用?Scala Inspectors使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Inspectors类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: SectionEmptyValuesMatchingSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model._
import uk.gov.hmrc.decisionservice.model.rules.{SectionCarryOver, SectionRule, SectionRuleSet}
import uk.gov.hmrc.decisionservice.ruleengine.SectionFactMatcher
import uk.gov.hmrc.play.test.UnitSpec
class SectionEmptyValuesMatchingSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
"section fact with empty values matcher" should {
"produce fact error when fact is missing answers for which there is no match and corresponding rule values are not all empty in any of the rules" in {
val fact = Map(
("question1" -> "yes"),
("question2" -> ""),
("question3" -> ""))
val rules = List(
SectionRule(List("yes","yes","yes"), SectionCarryOver("high" , true)),
SectionRule(List("yes","no" ,"no" ), SectionCarryOver("medium", true)),
SectionRule(List("no" ,"yes","" ), SectionCarryOver("low" , false))
)
val ruleSet = SectionRuleSet(List("question1", "question2", "question3"), rules)
val response = SectionFactMatcher.matchFacts(fact, ruleSet)
response.isLeft shouldBe true
response.leftMap { error =>
error shouldBe a [FactError]
}
}
"produce rules error when fact is missing answers for which there is no match but corresponding rule values are empty in at least one rule" in {
val fact = Map(
("question1" -> "yes"),
("question2" -> ""),
("question3" -> ""))
val rules = List(
SectionRule(List("yes","yes","yes"), SectionCarryOver("high" , true)),
SectionRule(List("yes","no" ,"" ), SectionCarryOver("medium", true)),
SectionRule(List("no" ,"" ,"" ), SectionCarryOver("low" , false))
)
val ruleSet = SectionRuleSet(List("question1", "question2", "question3"), rules)
val response = SectionFactMatcher.matchFacts(fact, ruleSet)
response.isLeft shouldBe true
response.leftMap { error =>
error shouldBe a [RulesFileError]
}
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:52,代码来源:SectionEmptyValuesMatchingSpec.scala
示例2: EmptyValuesValidatorSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model.rules.{SectionCarryOver, SectionRule}
import uk.gov.hmrc.decisionservice.model._
import uk.gov.hmrc.decisionservice.ruleengine.EmptyValuesValidator
import uk.gov.hmrc.play.test.UnitSpec
class EmptyValuesValidatorSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
object SectionEmptyValuesValidator extends EmptyValuesValidator {
type ValueType = String
type Rule = SectionRule
type RuleResult = SectionCarryOver
def valueEmpty(s: String) = s.isEmpty
}
"empty values validator" should {
"produce fact error if FactsEmptySet is a subset of MaximumRulesEmptySet" in {
val fact = Map(
("question1" -> "yes"),
("question2" -> ""),
("question3" -> ""))
val rules = List(
SectionRule(List("yes","yes","yes"), SectionCarryOver("high" , true)),
SectionRule(List("yes","no" ,"no" ), SectionCarryOver("medium", true)),
SectionRule(List("no" ,"yes","" ), SectionCarryOver("low" , false))
)
val error = SectionEmptyValuesValidator.noMatchError(fact,rules)
error shouldBe a [FactError]
}
"produce rules error if FactsEmptySet is a superset of MaximumRulesEmptySet" in {
val fact = Map(
("question1" -> "yes"),
("question2" -> ""),
("question3" -> ""))
val rules = List(
SectionRule(List("yes","yes","yes"), SectionCarryOver("high" , true)),
SectionRule(List("yes","no" ,"" ), SectionCarryOver("medium", true)),
SectionRule(List("no" ,"" ,"" ), SectionCarryOver("low" , false))
)
val error = SectionEmptyValuesValidator.noMatchError(fact,rules)
error shouldBe a [RulesFileError]
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:52,代码来源:EmptyValuesValidatorSpec.scala
示例3: MatrixRulesLoaderSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model.RulesFileLoadError
import uk.gov.hmrc.decisionservice.model.rules.SectionCarryOver
import uk.gov.hmrc.decisionservice.ruleengine.{MatrixFactMatcher, MatrixRulesLoader, RulesFileMetaData}
import uk.gov.hmrc.play.test.UnitSpec
class MatrixRulesLoaderSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
val csvFilePath = "/matrix.csv"
val csvFilePathError = "/matrix_error.csv"
val csvMetadata = RulesFileMetaData(2, 1, csvFilePath)
val csvMetadataError = RulesFileMetaData(2, 1, csvFilePathError)
"matrix rules loader" should {
"load matrix rules from a csv file" in {
val maybeRules = MatrixRulesLoader.load(csvMetadata)
maybeRules.isRight shouldBe true
maybeRules.map { ruleset =>
ruleset.rules should have size 3
ruleset.headings should have size 2
}
}
"return error if file is not found" in {
val maybeRules = MatrixRulesLoader.load(RulesFileMetaData(2, 1, csvFilePath + "xx"))
maybeRules.isLeft shouldBe true
maybeRules.leftMap { error =>
error shouldBe a [RulesFileLoadError]
}
}
"return error if file contains invalid data" in {
val maybeRules = MatrixRulesLoader.load(csvMetadataError)
maybeRules.isLeft shouldBe true
maybeRules.leftMap { error =>
error shouldBe a [RulesFileLoadError]
}
}
"provide valid input for an inference against fact" in {
val matrixFacts = Map(
("BusinessStructure" -> SectionCarryOver("high", true)), ("Substitute" -> SectionCarryOver("high" , false))
)
val maybeRules = MatrixRulesLoader.load(csvMetadata)
maybeRules.isRight shouldBe true
maybeRules.map { ruleset =>
ruleset.rules should have size 3
ruleset.headings should have size 2
val response = MatrixFactMatcher.matchFacts(matrixFacts, ruleset)
response.isRight shouldBe true
response.map { decision =>
decision.value should equal("out of IR35")
}
}
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:58,代码来源:MatrixRulesLoaderSpec.scala
示例4: MatrixEmptyValuesMatchingSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model._
import uk.gov.hmrc.decisionservice.model.rules.{MatrixDecision, MatrixRule, MatrixRuleSet, SectionCarryOver}
import uk.gov.hmrc.decisionservice.ruleengine.MatrixFactMatcher
import uk.gov.hmrc.play.test.UnitSpec
class MatrixEmptyValuesMatchingSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
"matrix fact with empty values matcher" should {
"produce fact error when fact is missing answers for which rule values are not empty" in {
val matrixFacts = Map(
("BusinessStructure" -> SectionCarryOver("high", true)),
("Substitute" -> SectionCarryOver("" , false)),
("FinancialRisk" -> SectionCarryOver("" , false))
)
val matrixRules = List(
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("high" , true ),SectionCarryOver("low" , true )), MatrixDecision("self employed")),
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("low" , false),SectionCarryOver("low" , true )), MatrixDecision("in IR35")),
MatrixRule(List(SectionCarryOver("medium", true ),SectionCarryOver("high", true ),SectionCarryOver("low" , true )), MatrixDecision("out of IR35"))
)
val matrixRuleSet = MatrixRuleSet(List("BusinessStructure", "Substitute", "FinancialRisk"), matrixRules)
val response = MatrixFactMatcher.matchFacts(matrixFacts, matrixRuleSet)
println(response)
response.isLeft shouldBe true
response.leftMap { error =>
error shouldBe a [FactError]
}
}
"produce rules error when fact is missing answers for which there is no match but corresponding rule values are empty in at least one rule" in {
val matrixFacts = Map(
("BusinessStructure" -> SectionCarryOver("high", true)),
("Substitute" -> SectionCarryOver("" , false)),
("FinancialRisk" -> SectionCarryOver("" , false))
)
val matrixRules = List(
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("high" , true ),SectionCarryOver("low" , true )), MatrixDecision("self employed")),
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("low" , false),SectionCarryOver("low" , true )), MatrixDecision("in IR35")),
MatrixRule(List(SectionCarryOver("medium", true ),SectionCarryOver("", true ),SectionCarryOver("" , true )), MatrixDecision("out of IR35"))
)
val matrixRuleSet = MatrixRuleSet(List("BusinessStructure", "Substitute", "FinancialRisk"), matrixRules)
val response = MatrixFactMatcher.matchFacts(matrixFacts, matrixRuleSet)
println(response)
response.isLeft shouldBe true
response.leftMap { error =>
error shouldBe a [RulesFileError]
}
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:56,代码来源:MatrixEmptyValuesMatchingSpec.scala
示例5: DecisionRequestSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import play.api.libs.json.{JsValue, Json}
import uk.gov.hmrc.decisionservice.model.api.{Section, QuestionSet}
import uk.gov.hmrc.play.test.UnitSpec
class DecisionRequestSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
val json =
"""
|{
| "version" : "1.0",
| "sections" : [ {
| "name" : "personal-service",
| "facts" : {
| "1" : true,
| "2" : false,
| "3" : true
| }
| } ]
|}
|
""".stripMargin
"decision request json" should {
"be correctly converted to Scala object" in {
val parsed = Json.parse(json)
val jsResult = Json.fromJson[QuestionSet](parsed)
jsResult.isSuccess shouldBe true
val obj = jsResult.get
obj.sections should have size 1
obj.sections(0).facts should have size 3
val m:Map[String,Boolean] = obj.sections(0).facts
val res = (1 to 3).flatMap(i => m.get(i.toString))
res should contain theSameElementsInOrderAs (List(true, false, true))
}
}
"decision request Scala object" should {
"be correctly converted to json object" in {
val personalServiceQuestions = Map("1" -> true, "2" -> false, "3" -> true)
val helperQuestions = Map("1" -> false, "2" -> false, "3" -> false)
val controlQuestions = Map("1" -> true, "2" -> true, "3" -> true)
val sections = List(
Section("personal-service", personalServiceQuestions),
Section("helper", helperQuestions),
Section("control", controlQuestions)
)
val decisionRequest = QuestionSet("1.0", sections)
val jsValue:JsValue = Json.toJson(decisionRequest)
val jsections = jsValue \\ "sections"
val jfacts = jsValue \\ "facts"
jsections should have size 1
jfacts should have size 3
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:62,代码来源:DecisionRequestSpec.scala
示例6: MatrixFactMatcherSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model._
import uk.gov.hmrc.decisionservice.model.rules.{MatrixDecision, MatrixRule, MatrixRuleSet, SectionCarryOver}
import uk.gov.hmrc.decisionservice.ruleengine.MatrixFactMatcher
import uk.gov.hmrc.play.test.UnitSpec
class MatrixFactMatcherSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
"matrix fact matcher" should {
"produce correct result for a sample matrix fact" in {
val matrixFacts = Map(
("BusinessStructure" -> SectionCarryOver("high", true)), ("Substitute" -> SectionCarryOver("high" , false))
)
val matrixRules = List(
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("low" , true )), MatrixDecision("in IR35")),
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("high", false)), MatrixDecision("out of IR35")),
MatrixRule(List(SectionCarryOver("medium", true ),SectionCarryOver("high", true )), MatrixDecision("in IR35"))
)
val matrixRuleSet = MatrixRuleSet(List("BusinessStructure", "Substitute"), matrixRules)
val response = MatrixFactMatcher.matchFacts(matrixFacts, matrixRuleSet)
response.isRight shouldBe true
response.map { decision =>
decision.value should equal("out of IR35")
}
}
"produce correct result for a partial fact" in {
val matrixFacts = Map(
("BusinessStructure" -> SectionCarryOver("high", true)),
("Substitute" -> SectionCarryOver("low" , false)),
("FinancialRisk" -> SectionCarryOver("" , false))
)
val matrixRules = List(
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("high" , true ),SectionCarryOver("" , true )), MatrixDecision("self employed")),
MatrixRule(List(SectionCarryOver("high" , true ),SectionCarryOver("low" , false),SectionCarryOver("" , true )), MatrixDecision("in IR35")),
MatrixRule(List(SectionCarryOver("medium", true ),SectionCarryOver("high", true ),SectionCarryOver("low" , true )), MatrixDecision("out of IR35"))
)
val matrixRuleSet = MatrixRuleSet(List("BusinessStructure", "Substitute", "FinancialRisk"), matrixRules)
val response = MatrixFactMatcher.matchFacts(matrixFacts, matrixRuleSet)
response.isRight shouldBe true
response.map { decision =>
decision.value should equal("in IR35")
}
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:54,代码来源:MatrixFactMatcherSpec.scala
示例7: SectionRulesLoaderSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.decisionservice
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.{BeforeAndAfterEach, Inspectors, LoneElement}
import uk.gov.hmrc.decisionservice.model.RulesFileLoadError
import uk.gov.hmrc.decisionservice.ruleengine.{RulesFileMetaData, SectionFactMatcher, SectionRulesLoader}
import uk.gov.hmrc.play.test.UnitSpec
class SectionRulesLoaderSpec extends UnitSpec with BeforeAndAfterEach with ScalaFutures with LoneElement with Inspectors with IntegrationPatience {
val csvFilePath = "/business_structure.csv"
val csvFilePathError = "/business_structure_error.csv"
val csvMetadata = RulesFileMetaData(3, 2, csvFilePath)
val csvMetadataError = RulesFileMetaData(3, 2, csvFilePathError)
"section rules loader" should {
"load section rules from a csv file" in {
val maybeRules = SectionRulesLoader.load(csvMetadata)
maybeRules.isRight shouldBe true
maybeRules.map { ruleset =>
ruleset.rules should have size 4
ruleset.headings should have size 3
}
}
"return error if file is not found" in {
val maybeRules = SectionRulesLoader.load(RulesFileMetaData(3, 2, csvFilePath + "xx"))
maybeRules.isLeft shouldBe true
maybeRules.leftMap { error =>
error shouldBe a [RulesFileLoadError]
}
}
"return error if file contains invalid data" in {
val maybeRules = SectionRulesLoader.load(csvMetadataError)
maybeRules.isLeft shouldBe true
maybeRules.leftMap { error =>
error shouldBe a [RulesFileLoadError]
}
}
"provide valid input for an inference against fact" in {
val fact = Map(
("Q1" -> "yes"),
("Q2" -> "no"),
("Q3" -> "yes"))
val maybeRules = SectionRulesLoader.load(csvMetadata)
maybeRules.isRight shouldBe true
maybeRules.map { ruleset =>
ruleset.rules should have size 4
ruleset.headings should have size 3
val response = SectionFactMatcher.matchFacts(fact, ruleset)
response.isRight shouldBe true
response.map { sectionResult =>
sectionResult.value should equal("low")
sectionResult.exit should equal(true)
}
}
}
}
}
开发者ID:Baisysoft,项目名称:off-payroll-decision-service,代码行数:59,代码来源:SectionRulesLoaderSpec.scala
示例8: LazyStartSpoutSpec
//设置package包名称以及导入依赖的类
package swave.core.impl.stages
import org.scalacheck.Gen
import org.scalatest.Inspectors
import swave.core._
final class LazyStartSpoutSpec extends SyncPipeSpec with Inspectors {
implicit val env = StreamEnv()
implicit val config = PropertyCheckConfiguration(minSuccessful = 100)
implicit val integerInput = Gen.chooseNum(0, 999)
"Spout.lazy" in check {
testSetup
.input[Int]
.output[String]
.prop
.from { (in, out) ?
Spout
.lazyStart(() ? in.spout)
.map(_.toString)
.drainTo(out.drain) shouldTerminate asScripted(in)
out.received shouldEqual in.produced.take(out.scriptedSize).map(_.toString)
}
}
}
开发者ID:sirthias,项目名称:swave,代码行数:29,代码来源:LazyStartSpoutSpec.scala
示例9: NoInvitationsPlatformISpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentinvitations.scenarios
import org.scalatest.{Inside, Inspectors}
import org.scalatest.concurrent.Eventually
import uk.gov.hmrc.agentinvitations.support._
import uk.gov.hmrc.domain.{AgentCode, Nino}
import uk.gov.hmrc.play.test.UnitSpec
class NoInvitationsPlatformISpec extends UnitSpec with MongoAppAndStubs with Inspectors with Inside with Eventually with Requests {
private implicit val arn = RandomArn()
private implicit val agentCode = AgentCode("LMNOP123456")
private val nino: Nino = nextNino
"Before the Agency has sent any invitations" in {
val agency = new AgencyRequests(this, arn, port)
val client = new ClientRequests(this, nino, port)
given().agentAdmin(arn, agentCode).isLoggedInWithSessionId().andIsSubscribedToAgentServices()
given().client(clientId = nino).isLoggedInWithSessionId()
info("the Agency sent invitations should be empty")
val agencyResponse = agency.sentInvitations()
agencyResponse.numberOfInvitations shouldBe 0
agencyResponse.links.invitations shouldBe 'empty
agencyResponse.links.selfLink shouldBe s"/agent-invitations/agencies/${arn.value}/invitations/sent"
agencyResponse.embedded.isEmpty shouldBe true
info("the Clients received invitations should be empty")
val clientResponse = client.getInvitations()
clientResponse.numberOfInvitations shouldBe 0
clientResponse.links.invitations shouldBe 'empty
clientResponse.links.selfLink shouldBe s"/agent-invitations/clients/ni/${nino.value}/invitations/received"
clientResponse.embedded.isEmpty shouldBe true
}
}
开发者ID:hmrc,项目名称:agent-invitations,代码行数:37,代码来源:NoInvitationsISpec.scala
示例10: GeometryEncodingSpec
//设置package包名称以及导入依赖的类
package org.apache.spark.sql.gt
import geotrellis.vector._
import org.apache.spark.rdd.RDD
import org.scalactic.Tolerance
import org.scalatest.{FunSpec, Inspectors, Matchers}
class GeometryEncodingSpec extends FunSpec
with Matchers with Inspectors with Tolerance
with TestEnvironment with TestData {
import GeometryEncodingSpec._
gtRegister(sqlContext)
describe("polygon encoding support") {
it("should not throw a runtime error") {
import sqlContext.implicits._
val polyA = Polygon(Line(Point(0,0), Point(1,0), Point(1,1), Point(0,1), Point(0,0)))
val polyB = Polygon(List(Point(10,10), Point(11,10), Point(11,11), Point(10,11), Point(10,10)))
val polyC = Polygon(List(Point(100,100), Point(101,100), Point(101,101), Point(100,101), Point(100,100)))
val left: RDD[Polygon] = sc.parallelize(Array(polyA, polyB, polyC))
val polygon = left.toDS
polygon.show(false)
assert(polygon.count() === 3)
val line1 = Line(Point(0,0), Point(5,5))
val line2 = Line(Point(13,0), Point(33,0))
val rightline: RDD[Feature[MultiLine, Category]] = sc.parallelize(Seq(Feature(MultiLine(line1, line2), Category(1, "some"))))
val right = rightline.toDS
right.show(false)
assert(right.count() === 1)
}
}
describe("multipolygon encoding support") {
it("should not throw a runtime error") {
import sqlContext.implicits._
val polyA = Polygon(Line(Point(0,0), Point(1,0), Point(1,1), Point(0,1), Point(0,0)))
val polyB = Polygon(List(Point(10,10), Point(11,10), Point(11,11), Point(10,11), Point(10,10)))
val polyC = Polygon(List(Point(100,100), Point(101,100), Point(101,101), Point(100,101), Point(100,100)))
val polyD = Polygon(List(Point(120,120), Point(121,120), Point(121,121), Point(120,121), Point(120,120)))
val polyE = Polygon(List(Point(130,130), Point(131,130), Point(131,131), Point(130,131), Point(130,130)))
val left: RDD[MultiPolygon] = sc.parallelize(Array(MultiPolygon(Array(polyA, polyB)),MultiPolygon(Array(polyC, polyD, polyE))))
val multipolygon = left.toDS
multipolygon.show(false)
assert(multipolygon.count() === 2)
assert(multipolygon.head.polygons.size === 2)
}
}
}
object GeometryEncodingSpec {
case class Category(id: Long, name: String)
}
开发者ID:s22s,项目名称:geotrellis-spark-sql,代码行数:62,代码来源:GeometryEncodingSpec.scala
示例11: UnitSpec
//设置package包名称以及导入依赖的类
package service
import org.mongodb.scala.bson.collection.immutable.Document
import org.scalatest.FunSuite
import org.scalatest.Inside
import org.scalatest.Inspectors
import org.scalatest.Matchers
import org.scalatest.OptionValues
abstract class UnitSpec extends FunSuite
with Matchers
with OptionValues
with Inside
with Inspectors
class MongoQueryParserTest extends UnitSpec {
trait Fixture {
val parser = new MongoQueryParser()
}
test("Parse query") {
new Fixture {
val query: String =
"""
|{
|"name" : "The Lord of The Rings",
|"author" : "J. R. R. Tolkien",
|"isHardcover" : true,
|"pages" : 1178,
|"price" : 13.60,
|"currency" : "GBP"
|}
""".stripMargin
val expected: String =
"""{
|"name" : "The Lord of The Rings",
|"author" : "J. R. R. Tolkien",
|"isHardcover" : true,
|"pages" : 1178,
|"price" : { "$numberDecimal" : "13.60" },
|"currency" : "GBP"
|}
""".stripMargin
val document: Document = parser.parse(query)
assert(normalize(document.toJson()) === normalize(expected))
}
}
private def normalize(s: String): String = s.split('\n').map(_.trim.filter(_ != ' ')).mkString
}
开发者ID:dougsleite,项目名称:oak,代码行数:57,代码来源:MongoQueryParserTest.scala
示例12: GroupSpec
//设置package包名称以及导入依赖的类
package com.github.tarao.namedcap
import org.scalatest.{FunSpec, Matchers, OptionValues, Inside, Inspectors}
class GroupSpec extends FunSpec with Matchers
with OptionValues with Inside with Inspectors
with Implicits {
describe("Constructor method") {
it("should give a specified name") {
val g1 = Group("foo", "[a-zA-Z0-9]+")
g1.name shouldBe "foo"
g1.pattern shouldBe "[a-zA-Z0-9]+"
g1.names shouldBe Seq("foo")
g1.allNames shouldBe Seq("foo")
val p1 = pattern"$g1:$g1"
val g2 = NestedGroup("bar", p1)
g2.name shouldBe "bar"
g2.pattern shouldBe "([a-zA-Z0-9]+):([a-zA-Z0-9]+)"
g2.names shouldBe Seq("bar")
g2.allNames shouldBe Seq("bar", "foo", "foo")
val p2 = pattern"$g2-$g2"
val g3 = NestedGroup("baz", p2)
g3.name shouldBe "baz"
g3.pattern shouldBe "(([a-zA-Z0-9]+):([a-zA-Z0-9]+))-(([a-zA-Z0-9]+):([a-zA-Z0-9]+))"
g3.names shouldBe Seq("baz")
g3.allNames shouldBe Seq("baz", "bar", "foo", "foo", "bar", "foo", "foo")
val g4 = UnnamedGroup(p1)
g4.name shouldBe "UnnamedGroup(${foo}:${foo})"
g4.pattern shouldBe "([a-zA-Z0-9]+):([a-zA-Z0-9]+)"
g4.names shouldBe Seq("foo", "foo")
g4.allNames shouldBe Seq("foo", "foo")
val g5 = UnnamedGroup(p2)
g5.name shouldBe "UnnamedGroup(${bar}-${bar})"
g5.pattern shouldBe "(([a-zA-Z0-9]+):([a-zA-Z0-9]+))-(([a-zA-Z0-9]+):([a-zA-Z0-9]+))"
g5.names shouldBe Seq("bar", "bar")
g5.allNames shouldBe Seq("bar", "foo", "foo", "bar", "foo", "foo")
}
}
}
开发者ID:tarao,项目名称:namedcap-scala,代码行数:45,代码来源:GroupSpec.scala
示例13: ProcessVerifyingListSpec
//设置package包名称以及导入依赖的类
package definiti.core.parser.project
import definiti.core.generators.antlr.VerificationContextGenerator
import org.scalatest.prop.PropertyChecks
import org.scalatest.{FlatSpec, Inspectors, Matchers}
class ProcessVerifyingListSpec extends FlatSpec with Matchers with PropertyChecks {
"DefinitiASTParser.processVerifyingList" should "return VerificationReference without message when not set" in {
forAll(VerificationContextGenerator.verifyingListContextWithoutMessage) { verifyingListContext =>
val result = DefinitiASTParser.processVerifyingList(verifyingListContext)
Inspectors.forAll(result.toList) { verificationReference =>
verificationReference.message should be(empty)
}
}
}
"DefinitiASTParser.processVerifyingList" should "return VerificationReference with message when set" in {
forAll(VerificationContextGenerator.verifyingListContextWithMessage) { verifyingListContext =>
val result = DefinitiASTParser.processVerifyingList(verifyingListContext)
Inspectors.forAll(result.toList) { verificationReference =>
verificationReference.message should be(defined)
}
}
}
}
开发者ID:definiti,项目名称:definiti-core,代码行数:28,代码来源:ProcessVerifyingListSpec.scala
示例14: SmoothieResponseTest
//设置package包名称以及导入依赖的类
package alexsmirnov.pbconsole
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.Inspectors
import alexsmirnov.pbconsole.gcode.SmoothieResponse
import alexsmirnov.pbconsole.gcode.StatusResponse
import alexsmirnov.pbconsole.gcode.ExtruderTemp
import alexsmirnov.pbconsole.gcode.ExtruderTarget
import alexsmirnov.pbconsole.gcode.ExtruderOutput
import alexsmirnov.pbconsole.gcode.BedTemp
import alexsmirnov.pbconsole.gcode.BedTarget
import alexsmirnov.pbconsole.gcode.BedOutput
class SmoothieResponseTest extends FlatSpec with Matchers with Inspectors {
"extruder temp response" should "generate status with temp" in {
val r = SmoothieResponse("ok T:180.0 /210.0 @128")
r shouldBe a[StatusResponse]
val values = r.asInstanceOf[StatusResponse].values
values should contain(ExtruderTemp(180.0f))
}
"extruder and bed temp response" should "generate status with temp for both" in {
val r = SmoothieResponse("ok T:180.0 /210.0 @128 B:50.0 /30.0 @0")
r shouldBe a[StatusResponse]
val values = r.asInstanceOf[StatusResponse].values
values should contain allOf(ExtruderTemp(180.0f),ExtruderTarget(210.0f),ExtruderOutput(128),BedTemp(50.0f),BedTarget(30.0f),BedOutput(0))
}
}
开发者ID:alexsmirnov,项目名称:printrbot-g2-console,代码行数:29,代码来源:SmoothieResponseTest.scala
示例15: PixelMapperTest
//设置package包名称以及导入依赖的类
package com.socialthingy.plusf.spectrum.display
import java.util
import org.scalatest.{FlatSpec, GivenWhenThen, Inspectors, Matchers}
import org.scalatest.prop.TableDrivenPropertyChecks
class PixelMapperTest extends FlatSpec with GivenWhenThen with Matchers with TableDrivenPropertyChecks with Inspectors {
val mappers = Table("mapper class", classOf[SafePixelMapper], classOf[UnsafePixelMapper])
forAll(mappers) { mapper =>
s"${mapper.getSimpleName}" should "correctly map the Spectrum display memory to a bitmap" in {
val memory = Array.ofDim[Int](0x10000)
Given("the display ink colour is black and the paper colour is white")
util.Arrays.fill(memory, 0x5800, 0x5b00, 56)
And("the pixels at the four corners of the screen are set")
memory(0x4000) = 0x80
memory(0x401f) = 0x01
memory(0x57e0) = 0x80
memory(0x57ff) = 0x01
When("the memory is mapped to a bitmap")
val bitmap = mapper.newInstance().getPixels(memory, false)
Then("the four corners of the bitmap are black pixels")
bitmap should have size 256 * 192
val black = SpectrumColour.dullColour(0)
val white = SpectrumColour.dullColour(7)
val blackPixels = List(0x0000, 0x00ff, 0xbf00, 0xbfff)
forEvery(blackPixels) { pixel => bitmap(pixel) shouldBe black }
And("all other pixels are white pixels")
val whitePixels = (0 until 0xc000) filterNot blackPixels.contains
forEvery(whitePixels) { pixel => bitmap(pixel) shouldBe white }
}
}
}
开发者ID:alangibson27,项目名称:plus-f,代码行数:42,代码来源:PixelMapperTest.scala
示例16: DisplayComponentTest
//设置package包名称以及导入依赖的类
package com.socialthingy.plusf.spectrum.ui
import java.util
import com.socialthingy.plusf.spectrum.display.{PixelMapper, SpectrumColour}
import org.scalatest.mock.MockitoSugar
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FlatSpec, GivenWhenThen, Inspectors, Matchers}
class DisplayComponentTest
extends FlatSpec
with GivenWhenThen with Matchers with TableDrivenPropertyChecks with Inspectors with MockitoSugar {
val displayComponents = Table(
"display component class",
classOf[SafeSwingDoubleSizeDisplay],
classOf[SwingDoubleSizeDisplay]
)
val black = SpectrumColour.dullColour(0)
val white = SpectrumColour.dullColour(7)
forAll(displayComponents) { displayComponent =>
s"${displayComponent.getSimpleName}" should "map source pixels to the target display correctly" in {
Given("a bitmap with black pixels at each corner and white pixels everywhere else")
val source = Array.ofDim[Int](0xc000)
util.Arrays.fill(source, white)
source(0x0000) = black
source(0x00ff) = black
source(0xbf00) = black
source(0xbfff) = black
When("the display is rendered")
val ctr = displayComponent.getConstructor(classOf[PixelMapper])
val display = ctr.newInstance(mock[PixelMapper])
display.scale(source)
Then("the pixels at each corner should be black and all other pixels should be white")
val blackPixels = List(
0x0000, 0x0001, 0x0200, // top left
0x01fe, 0x01ff, 0x03ff, // top right
0x2fc00, 0x2fe00, 0x2fe01, // bottom left
0x2fdff, 0x2fffe, 0x2ffff // bottom right
)
forEvery(blackPixels) { pixel => display.targetPixels(pixel) shouldBe black }
val whitePixels = (0 until 0x18000) filterNot blackPixels.contains
forEvery(whitePixels) { pixel => display.targetPixels(pixel) shouldBe white }
}
}
}
开发者ID:alangibson27,项目名称:plus-f,代码行数:53,代码来源:DisplayComponentTest.scala
注:本文中的org.scalatest.Inspectors类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论