本文整理汇总了Scala中org.scalatest.BeforeAndAfterEach类的典型用法代码示例。如果您正苦于以下问题:Scala BeforeAndAfterEach类的具体用法?Scala BeforeAndAfterEach怎么用?Scala BeforeAndAfterEach使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BeforeAndAfterEach类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PlayWithFoodWithTestComponents
//设置package包名称以及导入依赖的类
package testhelpers
import config.ExampleComponents
import org.scalatest.BeforeAndAfterEach
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.components.OneServerPerTestWithComponents
import play.api.db.evolutions.Evolutions
import play.api.http.Status
import play.api.libs.ws.WSClient
import play.api.test.{DefaultAwaitTimeout, FutureAwaits, Helpers, TestServer}
import play.api.{Application, Configuration}
import slick.dbio.DBIO
trait PlayWithFoodWithServerBaseTest extends PlaySpec
with OneServerPerTestWithComponents
with DefaultFutureDuration
with DefaultExecutionContext
with Status
with DefaultAwaitTimeout
with FutureAwaits
with BeforeAndAfterEach {
class PlayWithFoodWithTestComponents extends ExampleComponents(context) {
override def configuration: Configuration = {
val testConfig = Configuration.from(TestUtils.config)
val config = super.configuration
val testConfigMerged = config ++ testConfig
config.toString
testConfigMerged
}
implicit lazy val testWsClient: WSClient = wsClient
}
override def components: PlayWithFoodWithTestComponents = new PlayWithFoodWithTestComponents
private def runServerAndCleanUpInMemDb(c: PlayWithFoodWithTestComponents) = {
runServerAndExecute(c.application) {
val dbapi = c.dbApi
Evolutions.cleanupEvolutions(dbapi.database("default"))
}
}
override protected def afterEach(): Unit = {
runServerAndCleanUpInMemDb(components)
}
protected def runServerAndExecute[T](app: Application)(blockWithComponents: => T): T = {
Helpers.running(TestServer(port, app))(blockWithComponents)
}
def runAndAwaitResult[T](action: DBIO[T])(implicit components: ExampleComponents): T = {
TestUtils.runAndAwaitResult(action)(components.actionRunner, duration)
}
}
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:58,代码来源:PlayWithFoodWithServerBaseTest.scala
示例2: PlayJsonSnapshotMatcherSpec
//设置package包名称以及导入依赖的类
package com.commodityvectors.snapshotmatchers.playJson
import java.io.File
import com.commodityvectors.snapshotmatchers.{SnapshotMatcher, SnapshotSerializer}
import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterEach, Matchers, fixture}
import play.api.libs.json.{Format, JsValue, Json}
import scala.util.Try
class PlayJsonSnapshotMatcherSpec extends fixture.WordSpec with Matchers with SnapshotMatcher with PlayJsonSnapshotMatcher with BeforeAndAfterEach {
case class Test(value: Int)
implicit lazy val jsonFormat: Format[Test] = Json.format[Test]
val snapshotFolder: String = "scalatest-snapshot-matcher-play-json/src/test/__snapshots__"
val currentSpecPath: String = s"$snapshotFolder/com/commodityvectors/snapshotmatchers/playJson/PlayJsonSnapshotMatcherSpec"
override def afterEach(): Unit = {
Try(FileUtils.deleteDirectory(new File(snapshotFolder)))
}
"PlayJsonSnapshotMatcherSpec" should {
"pretty print json" in { implicit test =>
val instance = Test(1)
SnapshotSerializer.serialize(Json.toJson(instance)) shouldEqual
s"""{
| "value" : 1
|}""".stripMargin
}
"generate json snapshot file" in { implicit test =>
val instance = Test(1)
Json.toJson(instance) should matchSnapshot[JsValue]("customId")
FileUtils.readFileToString(
new File(s"$currentSpecPath/customId.snap")
) shouldEqual
s"""{
| "value" : 1
|}""".stripMargin
}
"allow deserialization" in { implicit test =>
val instance = Test(1)
Json.toJson(instance) should matchSnapshot[JsValue]("anotherId")
"anotherId" should deserializeAs(instance)
}
}
}
开发者ID:commodityvectors,项目名称:scalatest-snapshot-matchers,代码行数:50,代码来源:PlayJsonSnapshotMatcherSpec.scala
示例3: AGWPEConnectorSpec
//设置package包名称以及导入依赖的类
package com.softwaremill.modemconnector.agwpe
import java.net.ServerSocket
import org.scalatest.{BeforeAndAfterEach, FlatSpec, Matchers}
class AGWPEConnectorSpec extends FlatSpec with Matchers with BeforeAndAfterEach {
var server: ServerSocket = _
override def beforeEach(): Unit = {
server = new ServerSocket(AGWPESettings.port)
}
override def afterEach(): Unit = {
server.close()
}
"An AGWPEConnector" should "be created with configuration settings as default" in {
//when
val connector: AGWPEConnector = new AGWPEConnector()
//then
connector.host shouldEqual "127.0.0.1"
connector.port shouldEqual 8000
connector.timeout shouldEqual 3000
}
"An AGWPEConnector" should "be created with configuration settings as constructor arguments" in {
//given
val host: String = "127.0.0.1"
val port: Int = 8000
val timeout: Int = 1000
//when
val connector: AGWPEConnector = new AGWPEConnector(host, port, timeout)
//then
connector.host shouldEqual host
connector.port shouldEqual port
connector.timeout shouldEqual timeout
}
}
示例4: ironMqClient
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.ironmq
import java.util.UUID
import com.typesafe.config.{Config, ConfigFactory}
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterEach, Notifying, Suite}
import scala.concurrent.ExecutionContext
import scala.util.hashing.MurmurHash3
trait IronMqFixture extends AkkaStreamFixture with BeforeAndAfterEach with ScalaFutures { _: Suite with Notifying =>
private implicit val ec = ExecutionContext.global
private var mutableIronMqClient = Option.empty[IronMqClient]
def ironMqClient: IronMqClient =
mutableIronMqClient.getOrElse(throw new IllegalStateException("The IronMqClient is not initialized"))
override protected def initConfig(): Config =
ConfigFactory.parseString(s"""akka.stream.alpakka.ironmq {
| credentials {
| project-id = "${MurmurHash3.stringHash(System.currentTimeMillis().toString)}"
| }
|}
""".stripMargin).withFallback(super.initConfig())
override protected def beforeEach(): Unit = {
super.beforeEach()
mutableIronMqClient = Option(IronMqClient(IronMqSettings(config.getConfig("akka.stream.alpakka.ironmq"))))
}
override protected def afterEach(): Unit = {
mutableIronMqClient = Option.empty
super.afterEach()
}
def givenQueue(name: Queue.Name): Queue = {
val created = ironMqClient.createQueue(name).futureValue
note(s"Queue created: ${created.name.value}", Some(created))
created
}
def givenQueue(): Queue =
givenQueue(Queue.Name(s"test-${UUID.randomUUID()}"))
}
示例5: actorSystemTerminateTimeout
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.ironmq
import akka.actor.ActorSystem
import org.scalatest.{BeforeAndAfterEach, Suite}
import scala.concurrent.Await
import scala.concurrent.duration._
trait AkkaFixture extends ConfigFixture with BeforeAndAfterEach { _: Suite =>
import AkkaFixture._
def actorSystemTerminateTimeout: Duration = DefaultActorSystemTerminateTimeout
private var mutableActorSystem = Option.empty[ActorSystem]
implicit def actorSystem: ActorSystem =
mutableActorSystem.getOrElse(throw new IllegalArgumentException("The ActorSystem is not initialized"))
override protected def beforeEach(): Unit = {
super.beforeEach()
mutableActorSystem = Option(ActorSystem(s"test-${System.currentTimeMillis()}", config))
}
override protected def afterEach(): Unit = {
Await.result(actorSystem.terminate(), actorSystemTerminateTimeout)
super.afterEach()
}
}
object AkkaFixture {
val DefaultActorSystemTerminateTimeout: Duration = 10.seconds
}
示例6: 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]
}
}
}
}
示例7: 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]
}
}
}
示例8: 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")
}
}
}
}
}
示例9: 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]
}
}
}
}
示例10: 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")
}
}
}
}
示例11: 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)
}
}
}
}
}
示例12: PublicTransportCombinationRepositoryDBSpec
//设置package包名称以及导入依赖的类
package mapdomain.repository.publictransport
import mapdomain.graph.Coordinate
import mapdomain.publictransport.{ PublicTransportCombination, PublicTransportCombinationPath }
import mapdomain.repository.BaseRepositoryDBSpec
import mapdomain.sidewalk.Ramp
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, FlatSpec, Matchers }
import scalikejdbc.config.DBs
import scala.math._
class PublicTransportCombinationRepositoryDBSpec extends FlatSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEach
with BaseRepositoryDBSpec {
val precision: Double = pow(10, -8)
override def beforeAll(): Unit = DBs.setupAll()
override def beforeEach(): Unit = deleteAll()
override def afterAll(): Unit = DBs.closeAll()
"PublicTransportCombinationPath Repository" should "create PublicTransportCombinationPaths correctly" in {
val ptcp1 = PublicTransportCombinationPathRepository.create(PublicTransportCombinationPath(1, 2, "test-walkPath-1"))
val ptcp2 = PublicTransportCombinationPathRepository.create(PublicTransportCombinationPath(3, 4, "test-walkPath-2"))
val ptcs = PublicTransportCombinationPathRepository.findAll
ptcs.size shouldBe 2
assertWalkPath(ptcp1)
assertWalkPath(ptcp2)
val ptcp = PublicTransportCombinationPathRepository.findByStopAndTravelInfo(50, 50)
ptcp.isDefined shouldBe false
}
def assertWalkPath(combinationPath: PublicTransportCombinationPath): Unit = {
val ptcp = PublicTransportCombinationPathRepository.findByStopAndTravelInfo(combinationPath.fromStopId, combinationPath.toTravelInfoId)
ptcp.isDefined shouldBe true
ptcp.get.fromStopId shouldBe combinationPath.fromStopId
ptcp.get.toTravelInfoId shouldBe combinationPath.toTravelInfoId
ptcp.get.walkPath shouldBe combinationPath.walkPath
}
}
示例13: TravelInfoRepositoryDBSpec
//设置package包名称以及导入依赖的类
package mapdomain.repository.publictransport
import mapdomain.graph.Coordinate
import mapdomain.publictransport.{ Path, StopUnsaved, TravelInfo, TravelInfoUnsaved }
import mapdomain.repository.BaseRepositoryDBSpec
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, FlatSpec, Matchers }
import scalikejdbc.config.DBs
import scala.math._
class TravelInfoRepositoryDBSpec extends FlatSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEach
with BaseRepositoryDBSpec {
val precision: Double = pow(10, -8)
override def beforeAll(): Unit = DBs.setupAll()
override def beforeEach(): Unit = deleteAll()
override def afterAll(): Unit = DBs.closeAll()
"Travel Info Repository" should "create travelInfo correctly" in {
val travelInfoUnsaved: TravelInfoUnsaved = TravelInfoUnsaved(
description = "Line 150", firstStopId = Some(1), lastStopId = Some(10),
branch = "A", name = "Linea 123", sentido = "Forward", `type` = "BUS")
var travelInfo: TravelInfo = TravelInfoRepository.create(travelInfoUnsaved)
val path: Path = PathRepository.create("some coordinates")
val firstStop = StopRepository.create(
StopUnsaved(Coordinate(10l, 11l), sequence = 1, pathId = path.id,
travelInfoId = travelInfo.id, isAccessible = false))
val lastStop = StopRepository.create(
StopUnsaved(Coordinate(12l, 13l), sequence = 2, pathId = path.id,
travelInfoId = travelInfo.id, isAccessible = true))
travelInfo = travelInfo.copy(firstStopId = firstStop.id, lastStopId = lastStop.id)
TravelInfoRepository.save(travelInfo)
travelInfo = TravelInfoRepository.find(travelInfo.id).get
travelInfo.description shouldBe travelInfoUnsaved.description
travelInfo.branch shouldBe travelInfoUnsaved.branch
travelInfo.`type` shouldBe travelInfoUnsaved.`type`
travelInfo.name shouldBe travelInfoUnsaved.name
travelInfo.sentido shouldBe travelInfoUnsaved.sentido
travelInfo.firstStopId shouldBe firstStop.id
travelInfo.lastStopId shouldBe lastStop.id
TravelInfoRepository.deleteAll
}
}
示例14: AkkademyDbSpec
//设置package包名称以及导入依赖的类
package com.akkademy
import akka.util.Timeout
import org.scalatest.{BeforeAndAfterEach, FunSpecLike, Matchers}
import akka.actor.ActorSystem
import com.akkademy.messages.SetRequest
import akka.testkit.TestActorRef
import scala.concurrent.duration._
class AkkademyDbSpec extends FunSpecLike with Matchers with BeforeAndAfterEach
{
implicit val system = ActorSystem()
describe("akkademyDB")
{
describe("given SetRequest")
{
it ("should place key/value into map")
{
val actorRef = TestActorRef(new AkkademyDB)
actorRef ! SetRequest("key2","value2")
val akkademyDb = actorRef.underlyingActor
akkademyDb.map.get("key2") should equal(Some("value2"))
}
}
}
}
示例15: NeuronTest
//设置package包名称以及导入依赖的类
package se.andrisak.backprop.algo
import org.mockito.Mockito.when
import org.scalatest.mock.MockitoSugar
import org.scalatest.{BeforeAndAfterEach, FunSuite, Matchers}
import scala.util.Random
class NeuronTest extends FunSuite with BeforeAndAfterEach with Matchers with MockitoSugar {
val NEURON_NAME = "neuron"
val NEURON_NAME2 = "neuron2"
val RANDOM_VALUE = 0.53
val random = mock[Random]
when(random.nextDouble()).thenReturn(RANDOM_VALUE)
val neuron = new Neuron(NEURON_NAME, random)
test("input should be stored and be cleared") {
val input = 0.543
neuron.addInput(input)
neuron.getInput should equal (input)
neuron.clearInput()
neuron.getInput should equal (0)
}
test("neurons should be connected with a ForwardLink") {
val neuron2 = new Neuron(NEURON_NAME2, random)
neuron.connectToNeuronsInLayer(List(neuron2))
val link = neuron.getLinkTo(neuron2)
link.to should equal(neuron2)
link.weight should equal(RANDOM_VALUE)
link should equal(neuron.getNextLayerLinks.head)
}
test("neurons should be connected with a ReverseLink") {
val neuron2 = new Neuron(NEURON_NAME2, random)
neuron.connectToNeuronsInPreviousLayer(List(neuron2))
neuron.getPreviousLayerNeurons.head should equal(neuron2)
}
test("test the sigmoid computation") {
neuron.output should equal(0.5)
}
}