本文整理汇总了Scala中org.scalatest.junit.JUnitRunner类的典型用法代码示例。如果您正苦于以下问题:Scala JUnitRunner类的具体用法?Scala JUnitRunner怎么用?Scala JUnitRunner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JUnitRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: URIUtilsSpec
//设置package包名称以及导入依赖的类
package com.pygmalios.reactiveinflux.impl
import java.net.URI
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class URIUtilsSpec extends FlatSpec {
behavior of "appendPath"
it should "strip /" in {
assert(URIUtils.appendPath(new URI("http://x/"), "/a").toString == "http://x/a")
}
behavior of "queryToString"
it should "create empty query string" in {
assert(URIUtils.queryToString() == "")
}
it should "create query string with single item" in {
assert(URIUtils.queryToString("a" -> "b") == "?a=b")
}
it should "create query string with two items" in {
assert(URIUtils.queryToString("a" -> "b", "c" -> "d") == "?a=b&c=d")
}
}
示例2: PascalSuite
//设置package包名称以及导入依赖的类
package recfun
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class PascalSuite extends FunSuite {
import Main.pascal
test("pascal: col=0,row=2") {
assert(pascal(0,2) === 1)
}
test("pascal: col=1,row=2") {
assert(pascal(1,2) === 2)
}
test("pascal: col=1,row=3") {
assert(pascal(1,3) === 3)
}
}
示例3: CountChangeSuite
//设置package包名称以及导入依赖的类
package recfun
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class CountChangeSuite extends FunSuite {
import Main.countChange
test("countChange: example given in instructions") {
assert(countChange(4,List(1,2)) === 3)
}
test("countChange: sorted CHF") {
assert(countChange(300,List(5,10,20,50,100,200,500)) === 1022)
}
test("countChange: no pennies") {
assert(countChange(301,List(5,10,20,50,100,200,500)) === 0)
}
test("countChange: unsorted CHF") {
assert(countChange(300,List(500,5,50,100,20,200,10)) === 1022)
}
}
示例4: CountChangeSuite
//设置package包名称以及导入依赖的类
package recfun
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, ShouldMatchers}
@RunWith(classOf[JUnitRunner])
class CountChangeSuite extends FunSuite with ShouldMatchers {
import Week1.countChange
test("countChange: example given in instructions") {
countChange(4, List(1, 2)) should be(3)
}
test("countChange: sorted CHF") {
countChange(300, List(5, 10, 20, 50, 100, 200, 500)) should be(1022)
}
test("countChange: no pennies") {
countChange(301, List(5, 10, 20, 50, 100, 200, 500)) should be(0)
}
test("countChange: unsorted CHF") {
countChange(300, List(500, 5, 50, 100, 20, 200, 10)) should be(1022)
}
}
示例5: BalanceSuite
//设置package包名称以及导入依赖的类
package functions
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class BalanceSuite extends FunSuite {
import Main.balance
test("balance: '(if (zero? x) max (/ 1 x))' is balanced") {
assert(balance("(if (zero? x) max (/ 1 x))".toList))
}
test("balance: 'I told him ...' is balanced") {
assert(balance("I told him (that it's not (yet) done).\n(But he wasn't listening)".toList))
}
test("balance: ':-)' is unbalanced") {
assert(!balance(":-)".toList))
}
test("balance: counting is not enough") {
assert(!balance("())(".toList))
}
}
示例6: ChannelCollisionCheckerTest
//设置package包名称以及导入依赖的类
package net.xylophones.frogger
import net.xylophones.frogger.test.FroggerTestSugar
import org.junit.runner.RunWith
import org.scalatest.{BeforeAndAfterEach, FunSuite, Matchers}
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class ChannelCollisionCheckerTest extends FunSuite with Matchers with FroggerTestSugar with BeforeAndAfterEach {
test("ChannelCollisionChecker detects when landing on a cell") {
val tiledImage = createTiledImage(10, 10)
val sprite = createSprite(5, 5)
val channel = new Channel(Array(Array(Tile(0, 0, CellType.Landable))), 0, tiledImage)
val chPosition = Vector(10, 10)
val sPosition = Vector(10, 10)
val result = ChannelCollisionChecker.isLanding(channel, chPosition, sprite, sPosition)
result shouldBe true
}
test("ChannelCollisionChecker detects deadly collisions") {
val tiledImage = createTiledImage(16, 16)
val sprite = createSprite(8, 8)
val channel = new Channel(Array(Array(Tile(0, 0, CellType.Deadly))), 0, tiledImage)
val chPosition = Vector(10, 10)
val sPosition = Vector(10, 10)
val result = ChannelCollisionChecker.isDeadlyCollision(channel, chPosition, sprite, sPosition)
result shouldBe true
}
}
示例7: 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"))
}
}
示例8: ExtractionTest
//设置package包名称以及导入依赖的类
package observatory
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class ExtractionTest extends FunSuite {
test("locateTemperature should work with given year") {
val temp = Extraction.locateTemperatures(1986, "/stations.csv", "/1986.csv")
assert(temp.size == 2429828)
}
test("locationYearlyAverageRecords should work with given year") {
val temp = Extraction.locateTemperatures(1986, "/stations.csv", "/1986.csv")
val avg = Extraction.locationYearlyAverageRecords(temp)
assert(avg.size == 8755)
}
}
示例9: ParallelParenthesesBalancingSuite
//设置package包名称以及导入依赖的类
package reductions
import java.util.concurrent._
import scala.collection._
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import common._
import ParallelParenthesesBalancing._
@RunWith(classOf[JUnitRunner])
class ParallelParenthesesBalancingSuite extends FunSuite {
test("balance should work for empty string") {
def check(input: String, expected: Boolean) =
assert(balance(input.toArray) == expected,
s"balance($input) should be $expected")
check("", true)
}
test("balance should work for string of length 1") {
def check(input: String, expected: Boolean) =
assert(balance(input.toArray) == expected,
s"balance($input) should be $expected")
check("(", false)
check(")", false)
check(".", true)
}
test("balance should work for string of length 2") {
def check(input: String, expected: Boolean) =
assert(balance(input.toArray) == expected,
s"balance($input) should be $expected")
check("()", true)
check(")(", false)
check("((", false)
check("))", false)
check(".)", false)
check(".(", false)
check("(.", false)
check(").", false)
}
test("parallel balance should work for string of any length") {
assert(!parBalance(")(".toArray, 1))
assert(parBalance("()".toArray, 1))
assert(parBalance("((()))".toArray, 1))
}
}
示例10: BagSpecs
//设置package包名称以及导入依赖的类
package de.htwg.se.SevenSteps.model.bag.basicImpl
import org.junit.runner.RunWith
import org.scalatest.Matchers._
import org.scalatest._
import org.scalatest.junit.JUnitRunner
import scala.collection.mutable.ListBuffer
@RunWith(classOf[JUnitRunner])
class BagSpecs extends WordSpec {
def getBag: Bag = Bag(Vector(), Vector("a", "b"))
"A Bag" should {
"have a insert function" in {
val bag = getBag
bag.insert('a')
bag.insert('b')
bag.insert('c')
bag.bag should be(ListBuffer("a", "b", "c"))
}
"have a reset function" in {
val bag = getBag
bag.insert('a')
bag.reset.bag should be(ListBuffer())
}
"have a draw function" in {
val bag = getBag
bag.insert('a')
bag.get() should be(Some('a'))
bag.get() should be(None)
}
"can fillUp with the colors" in {
val bag = getBag
bag.fillup()
}
"can get the stone number" in {
val bag = getBag
bag.getStoneNumber should be(0)
bag.insert('a')
bag.getStoneNumber should be(1)
}
"have a toXML functions" in {
val bag = getBag
bag.insert('a')
bag.insert('b')
bag.insert('c')
bag.toXML().toString() should be("<alles a='<blub bag2=\"a\"></blub><blub bag2=\"b\"></blub><blub" +
" bag2=\"c\"></blub>' b='<bag col=\"a\"></bag><bag col=\"b\"></bag>'></alles>")
}
}
}
示例11: CellSpec
//设置package包名称以及导入依赖的类
package de.htwg.se.SevenSteps.model.grid.basicImpl
import org.junit.runner.RunWith
import org.scalatest.Matchers._
import org.scalatest._
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class CellSpec extends WordSpec {
"A Cell" should {
val cell = Cell('a', 2)
"have a color" in {
cell.color should be('a')
}
"have a height" in {
cell.height should be(2)
}
"generate a string in the form" in {
cell.toString should be("a 2")
}
"have a toXML function in the form" in {
cell.toXML().toString() should be("<cell colorCell=\"a\" height=\"2\"></cell>")
}
}
}
示例12: RoundCompleteCountdownUpdaterTest
//设置package包名称以及导入依赖的类
package net.xylophones.planetoid.game.logic
import net.xylophones.planetoid.game.logic.ModelTestObjectMother._
import net.xylophones.planetoid.game.model.{GamePhysics, GameEvent, RoundCountdownTimer, GameModel}
import org.junit.runner.RunWith
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{Matchers, FunSuite}
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class RoundCompleteCountdownUpdaterTest extends FunSuite with Matchers with MockitoSugar {
val currentTimeSource = mock[CurrentTimeSource]
val underTest = new RoundCompleteCountdownUpdater(currentTimeSource)
test("counter gets decremented when exists") {
// given
val model = GameModel(createDummyPlanet(), createDummyPlayers(), roundEndTimer = Some(RoundCountdownTimer(0, 1000, 600)))
when(currentTimeSource.currentTime()).thenReturn(1599)
// when
val result = underTest.update(resultFromModel(model), new GamePhysics(), null)
// then
result.model.roundEndTimer.get.remainingTimeMs shouldBe 1
}
}
示例13: GameCollisionUpdaterTest
//设置package包名称以及导入依赖的类
package net.xylophones.planetoid.game.logic
import net.xylophones.planetoid.game.maths.Vector3D
import net.xylophones.planetoid.game.model._
import net.xylophones.planetoid.game.logic.ModelTestObjectMother._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, Matchers}
import net.xylophones.planetoid.game.logic.ModelTestObjectMother._
@RunWith(classOf[JUnitRunner])
class GameCollisionUpdaterTest extends FunSuite with Matchers {
val underTest = new GameCollisionUpdater(new CollisionCalculator)
test("collision between player1 and planet is detected") {
val player1 = Player(createRocketAt(Vector3D(1000, 1000, 0)), numLives = 1)
val player2 = Player(createRocketAt(Vector3D(10, 10, 0)), numLives = 1)
val physics = new GamePhysics()
val model = GameModel(createDummyPlanet(), Players(player1, player2))
// when
val result = underTest.update(resultFromModel(model), physics, Vector.empty)
// then
val newModel = result.model
val events = result.events
newModel.players.p1 shouldBe player1
newModel.players.p2 shouldBe player2
events should not contain (GameEvent.Player2LoseLife)
events should not contain (GameEvent.Player1LoseLife)
events should not contain (GameEvent.PlayerLoseLife)
}
}
示例14: ConfigParserTest
//设置package包名称以及导入依赖的类
package cz.alenkacz.db.postgresscala
import java.util.concurrent.TimeUnit
import com.github.mauricio.async.db.Configuration
import com.github.mauricio.async.db.pool.PoolConfiguration
import com.typesafe.config.ConfigFactory
import cz.alenkacz.db.postgresscala.ConfigParser.PostgresConfiguration
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FlatSpec, Matchers}
import scala.concurrent.duration._
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class ConfigParserTest extends FlatSpec with Matchers {
private val config = ConfigFactory.load("parser-test.conf")
"Postgres configuration" should "be loaded from connection string" in {
val actual = ConfigParser.parse(config.getConfig("connection-string"))
val expected = PostgresConfiguration(Configuration("admin", "localhost", 5432, Some("admin"), Some("test_db")), Duration(5, TimeUnit.SECONDS), None)
actual should be(expected)
}
it should "throw exception when connection string is missing" in {
assertThrows[InvalidConfigurationException](ConfigParser.parse(config.getConfig("missing-connection-string")))
}
it should "parse full config" in {
val actual = ConfigParser.parse(config.getConfig("full-config"))
val expected = PostgresConfiguration(Configuration("admin", "localhost", 5432, Some("admin"), Some("test_db"), maximumMessageSize = 167, connectTimeout = 888 seconds, testTimeout = 777 seconds, queryTimeout = Some(666 seconds)), Duration(5, TimeUnit.SECONDS), Some(PoolConfiguration(3, 5000, 10)))
actual should be(expected)
}
it should "not return pooled connection by default" in {
val actual = ConfigParser.parse(config.getConfig("without-pooling"))
actual.poolConfiguration should be(None)
}
}
示例15: SqlStringInterpolatorTest
//设置package包名称以及导入依赖的类
package cz.alenkacz.db.postgresscala
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FlatSpec, Matchers}
import cz.alenkacz.db.postgresscala._
@RunWith(classOf[JUnitRunner])
class SqlStringInterpolatorTest extends FlatSpec with Matchers {
"Interpolated sql string" should "be correcly parsed" in {
val a = "value"
val actual = sql"SELECT * FROM table WHERE a=$value"
actual should be(new SqlQuery("SELECT * FROM table WHERE a=?", Seq(value)))
}
it should "interpolate also queries with list as parameter" in {
val value = List("a", "b")
val actual = sql"SELECT * FROM table WHERE a IN ($value)"
actual should be(new SqlQuery("SELECT * FROM table WHERE a IN (?, ?)", Seq("a", "b")))
}
it should "interpolate also queries with empty list as parameter" in {
val value = List.empty
val actual = sql"INSERT INTO table (a) VALUES ($value)"
actual should be(new SqlQuery("INSERT INTO table (a) VALUES (?)", Seq("{}")))
}
}