本文整理汇总了Scala中org.scalatest.FunSuite类的典型用法代码示例。如果您正苦于以下问题:Scala FunSuite类的具体用法?Scala FunSuite怎么用?Scala FunSuite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FunSuite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MissionTimeSuite
//设置package包名称以及导入依赖的类
package utils
import org.scalatest.FunSuite
class MissionTimeSuite extends FunSuite {
test("MissionTime.addMinutes") {
assert(MissionTime(1, 6, 1).addMinutes(15) === MissionTime(1, 6, 16))
assert(MissionTime(1, 6, 23).addMinutes(-10) === MissionTime(1, 6, 13))
}
test("MissionTime.addMinutes if carry") {
assert(MissionTime(1, 6, 59).addMinutes(3) === MissionTime(1, 7, 2))
assert(MissionTime(1, 7, 3).addMinutes(-5) === MissionTime(1, 6, 58))
}
test("MissionTime.addMinutes if over hour") {
assert(MissionTime(1, 23, 44).addMinutes(25) === MissionTime(2, 0, 9))
assert(MissionTime(2, 0, 15).addMinutes(-18) === MissionTime(1, 23, 57))
}
test("MissionTime.fromString") {
assert(MissionTime.fromString("1-06:15") === Some(MissionTime(1, 6, 15)))
}
}
示例2: ColumnsTest
//设置package包名称以及导入依赖的类
package com.drakeconsulting.big_data_maker
import org.scalatest.FunSuite
import com.holdenkarau.spark.testing.SharedSparkContext
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.types.{StructField, StringType, LongType, DoubleType}
class ColumnsTest extends FunSuite with SharedSparkContext {
val numLoops = 100
test("test StringConstant") {
val s1 = new StringConstant("f1", "abc")
assert("abc" === s1.getValue(1))
assert(StructField("f1", StringType, false) == s1.getStructField)
}
test("test RandomLong") {
val s1 = new RandomLong("f1", 666666L)
for (x <- 1 to numLoops) {
assert(s1.getValue(1) >= 0)
assert(s1.getValue(1) <= 666666L)
}
assert(StructField("f1", LongType, false) == s1.getStructField)
}
test("test RandomDouble") {
val s1 = new RandomDouble("f1", 666666.00)
for (x <- 1 to numLoops) {
assert(s1.getValue(1) >= 0)
assert(s1.getValue(1) <= 666666.00)
}
assert(StructField("f1", DoubleType, false) == s1.getStructField)
}
test("test Categorical") {
val list = List("a", "b", "c", "d")
val s1 = new Categorical("f1", list)
for (x <- 1 to numLoops) {
val v = s1.getValue(1)
assert(list.exists(key => v.contains(key)))
}
assert(StructField("f1", StringType, false) == s1.getStructField)
}
}
示例3: BigDataMakerTest
//设置package包名称以及导入依赖的类
package com.drakeconsulting.big_data_maker
import org.scalatest.FunSuite
import com.holdenkarau.spark.testing.SharedSparkContext
import org.apache.spark.sql.SQLContext
class BigDataMakerTest extends FunSuite with SharedSparkContext {
test("first") {
val sqlContext = new SQLContext(sc)
val bd = new BigData(sqlContext, "/tmp/b", 5, 100)
bd.addColumn(new StringConstant("f1", "abc"))
bd.addColumn(new StringConstant("f2", "def"))
val df = bd._createDataFrame
df.show
assert(500 === df.count)
assert(2 === df.columns.length)
}
test("col names") {
val sqlContext = new SQLContext(sc)
val bd = new BigData(sqlContext, "/tmp/b", 5, 100)
bd.addColumn(new StringConstant("f1", "abc"))
bd.addColumn(new StringConstant("", "def"))
assert("f1" === bd.cols(0).name)
assert("f_1" === bd.cols(1).name)
}
}
示例4: MappedNamespaceContextTest
//设置package包名称以及导入依赖的类
package fr.ramiro.scala.dom
import javax.xml.XMLConstants
import org.scalatest.FunSuite
import scala.collection.JavaConverters.asScalaIteratorConverter
class MappedNamespaceContextTest extends FunSuite {
test("get prefix and get namespaceURI") {
val customUri = "www.ramiro.fr"
val customPrefix = "ramiro"
val namespaceContext = new MappedNamespaceContext(Map(customPrefix -> customUri))
assert(namespaceContext.getNamespaceURI(customPrefix) === customUri)
assert(namespaceContext.getNamespaceURI(XMLConstants.XML_NS_PREFIX) === XMLConstants.XML_NS_URI)
assert(namespaceContext.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE) === XMLConstants.XMLNS_ATTRIBUTE_NS_URI)
assert(namespaceContext.getPrefix(customUri) === customPrefix)
assert(namespaceContext.getPrefix(XMLConstants.XML_NS_URI) === XMLConstants.XML_NS_PREFIX)
assert(namespaceContext.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) === XMLConstants.XMLNS_ATTRIBUTE)
assert(namespaceContext.getPrefixes(customUri).asScala.toList === List(customPrefix))
assert(namespaceContext.getPrefixes(XMLConstants.XML_NS_URI).asScala.toList === List(XMLConstants.XML_NS_PREFIX))
assert(namespaceContext.getPrefixes(XMLConstants.XMLNS_ATTRIBUTE_NS_URI).asScala.toList === List(XMLConstants.XMLNS_ATTRIBUTE))
}
test("getNamespaceURI with null") {
intercept[IllegalArgumentException] {
new MappedNamespaceContext(Map.empty).getNamespaceURI(null)
}
}
test("getPrefix with null") {
intercept[IllegalArgumentException] {
new MappedNamespaceContext(Map.empty).getPrefix(null)
}
}
test("getPrefixes with null") {
intercept[IllegalArgumentException] {
new MappedNamespaceContext(Map.empty).getPrefixes(null)
}
}
}
示例5: 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)
}
}
示例6: RepositoryTest
//设置package包名称以及导入依赖的类
package com.hxm.earlgrey.jobs
import org.scalatest.{BeforeAndAfter, FunSuite}
import org.mongodb.scala.Document
class RepositoryTest extends FunSuite with BeforeAndAfter {
val repository = Repository()
val jobId = "scalaTestId"
before {
repository.deleteJob(jobId)
}
test("job insert and query") {
val doc = Document("_id" -> jobId, "type" -> Job.Type.FlowQuery, "name" -> "scalatest", "status" -> Job.Status.Created)
val job = new Job(doc)
repository.insertJob(job)
val j = repository.findJob(jobId)
assert(j.isDefined)
assert(j.get.doc.getString("_id") == jobId)
}
}
示例7: PositionPackageTest
//设置package包名称以及导入依赖的类
package factories.position
import domain.position.PositionPackage
import org.joda.time.DateTime
import org.scalatest.FunSuite
class PositionPackageTest extends FunSuite {
test("testCreatePositionFunding") {
val des = new PositionPackageFactory;
val date = new DateTime(2016, 4, 2, 1, 20, 2, 0);
val values = Map("positionId" -> "1",
"positionPackageId" -> "1",
"gradeId" -> "1",
"notchId" -> "1",
"state" -> "testState"
);
val posdes = des.createPositionPackageFactory(values, date);
assert(posdes == PositionPackage(positionId = "1",
positionPackageId = "1",
gradeId = "1",
notchId = "1",
state = "testState",
date = new DateTime(2016, 4, 2, 1, 20, 2, 0)));
}
}
示例8: PositionTest
//设置package包名称以及导入依赖的类
package factories.position
import domain.position.Position
import org.joda.time.DateTime
import org.scalatest.FunSuite
class PositionTest extends FunSuite{
test("testCreatePosition")P
val des = new PositionFactory;
val date = new DateTime(2016, 10, 11, 5, 20, 0, 0);
val values = Map("positionId" -> "1",
"organisationId" -> "1",
"code" -> "123",
"title" -> "testPosition",
"jobId" -> "1",
"positionTypeId" -> "1",
"description" -> "test Position",
"supervisorId" -> "2",
"state" -> "testState");
val posdes = des.createPosition(values, date);
assert(posdes == Position(positionId = "1",
positionTypeId = "1",
organisationId = "1",
code = "123",
title = "testPosition",
jobId = "1",
description = "test Position",
supervisorId = "2",
state = "testState",
date = new DateTime(2016, 10, 11, 5, 20, 0, 0));
}
示例9: SQSSourceConnectorSuite
//设置package包名称以及导入依赖的类
package com.hivehome.kafka.connect.sqs
import org.scalatest.{FunSuite, Matchers}
import scala.collection.JavaConverters._
class SQSSourceConnectorSuite extends FunSuite with Matchers {
val connector = new SQSSourceConnector()
val props = Map[String, String](
Conf.SourceSqsQueue -> "in",
Conf.DestinationKafkaTopic -> "out"
).asJava
test("should return task class") {
connector.taskClass shouldEqual classOf[SQSSourceTask]
}
test("should return config def") {
connector.config shouldEqual Conf.ConfigDef
}
test("should return successfully from start") {
connector.start(props)
}
test("should create task configs") {
connector.start(props)
val maxTasks = 10
val taskConfigs = connector.taskConfigs(maxTasks).asScala
taskConfigs should have size maxTasks
taskConfigs foreach { taskConfig =>
taskConfig shouldEqual props
}
}
}
示例10: ConfSuite
//设置package包名称以及导入依赖的类
package com.hivehome.kafka.connect.sqs
import org.apache.kafka.connect.errors.ConnectException
import org.scalatest.OptionValues._
import org.scalatest.TryValues._
import org.scalatest.{FunSuite, Matchers}
class ConfSuite extends FunSuite with Matchers {
private val UsEast = "us-east-1"
private val EuWest = "eu-west-1"
val mandatoryProps = Map[String, String](
Conf.SourceSqsQueue -> "in",
Conf.DestinationKafkaTopic -> "out"
)
val optionalProps = Map[String, String](
Conf.AwsKey -> "key",
Conf.AwsSecret -> "secret",
Conf.AwsRegion -> UsEast
)
val allProps = mandatoryProps ++ optionalProps
test("should parse all configurations from a map") {
val tryConf = Conf.parse(allProps)
val conf = tryConf.success.value
conf.queueName.value shouldEqual "in"
conf.topicName.value shouldEqual "out"
conf.awsRegion shouldEqual UsEast
conf.awsKey.value shouldEqual "key"
conf.awsSecret.value shouldEqual "secret"
}
test("should parse mandatory configurations from a map") {
val tryConf = Conf.parse(mandatoryProps)
val conf = tryConf.success.value
conf.queueName.value shouldEqual "in"
conf.topicName.value shouldEqual "out"
conf.awsRegion shouldEqual EuWest
}
test("should fail when mandatory config is missing") {
val tryConf = Conf.parse(Map())
tryConf.failure.exception.getClass shouldBe classOf[ConnectException]
}
}
示例11: E2ESpec
//设置package包名称以及导入依赖的类
package com.hivehome.kafka.connect.sqs
import java.time.Instant
import org.scalatest.{FunSuite, Matchers}
import org.slf4j.LoggerFactory
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class E2ESpec extends FunSuite with Matchers with SQSSupport {
val logger = LoggerFactory.getLogger(getClass.getName)
private val KafkaTopic: String = "connect-test"
override val queueName = "test-sqs" // kafka connect should be setup with this SQS
queueUrl = sqs.getQueueUrl(queueName).getQueueUrl
private val props = Map(
"bootstrap.servers" -> sys.env.getOrElse("KAFKA", "localhost:9092"),
"schema.registry.url" -> sys.env.getOrElse("SCHEMA_REGISTRY", "http://localhost:8081"))
val consumer = KafkaAvroConsumer[String, String](props, topicName = KafkaTopic)
// Test is ignored because it does not run without dependent services
ignore("should route message SQS -> Kafka") {
Future {
// sleep is required so that the message to SQS
// is sent after the consumer is listening on the kafka topic
Thread.sleep(500)
logger.debug("sending message..")
sendMessage(Instant.now().toString)
logger.debug("sent message..")
}
val msgs = consumer.poll(1, accept = _ => true)
msgs should have size 1
}
}
示例12: HuffmanSuite
//设置package包名称以及导入依赖的类
package patmat
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, ShouldMatchers}
import patmat.Huffman._
@RunWith(classOf[JUnitRunner])
class HuffmanSuite extends FunSuite with ShouldMatchers {
trait TestTrees {
val t1 = Fork(Leaf('a',2), Leaf('b',3), List('a','b'), 5)
val t2 = Fork(Fork(Leaf('a',2), Leaf('b',3), List('a','b'), 5), Leaf('d',4), List('a','b','d'), 9)
}
test("weight of a larger tree") {
new TestTrees {
weight(t1) should be(5)
}
}
test("chars of a larger tree") {
new TestTrees {
chars(t2) should be(List('a', 'b', 'd'))
}
}
test("string2chars(\"hello, world\")") {
string2Chars("hello, world") should be(List('h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'))
}
test("makeOrderedLeafList for some frequency table") {
makeOrderedLeafList(List(('t', 2), ('e', 1), ('x', 3))) should be(List(Leaf('e', 1), Leaf('t', 2), Leaf('x', 3)))
}
test("combine of some leaf list") {
val leaflist = List(Leaf('e', 1), Leaf('t', 2), Leaf('x', 4))
combine(leaflist) should be(List(Fork(Leaf('e', 1), Leaf('t', 2), List('e', 't'), 3), Leaf('x', 4)))
}
test("decode and encode a very short text should be identity") {
val fc = Huffman.frenchCode
decode(fc, encode(fc)("letsmakeitmorecomplicated".toList)) should be("letsmakeitmorecomplicated".toList)
}
}
示例13: 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 Week1.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)
}
}
示例14: BalanceSuite
//设置package包名称以及导入依赖的类
package recfun
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class BalanceSuite extends FunSuite {
import Week1.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))
}
}
示例15: 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)
}
}