• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TableDrivenPropertyChecks类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.scalatest.prop.TableDrivenPropertyChecks的典型用法代码示例。如果您正苦于以下问题:Scala TableDrivenPropertyChecks类的具体用法?Scala TableDrivenPropertyChecks怎么用?Scala TableDrivenPropertyChecks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TableDrivenPropertyChecks类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: DomainStructureTest

//设置package包名称以及导入依赖的类
package org.dele.text.lapa.patterns

import DomainStructure._
import org.scalatest.ShouldMatchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class DomainStructureTest extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {

  import org.dele.text.lapa.TestHelper._
  @Test
  def t1 = {
    val ds = domainStructure.children
    ds.size shouldBe(3)
  }

  @Test
  def t2 = {
    val d = engDomainMgr.queryDomainId("cyber-attack", "entity-list-connector-words")
    d shouldBe(Option("_root_"))
  }

  @Test
  def t3 = {
    val ds = load(domainTree, List("cyber-attack"))
    ds.children.size shouldBe 2
    ds.children.exists(_.id == "cyber-attack") shouldBe false

    val ds2 = load(domainTree, List("military-maneuver", "-online-attack"))
    ds2.children.size shouldBe 2
    ds2.children.exists(_.id == "-online-attack") shouldBe false
  }

} 
开发者ID:new2scala,项目名称:text-util,代码行数:37,代码来源:DomainStructureTest.scala


示例2: PtnNodeTest

//设置package包名称以及导入依赖的类
package org.dele.text.lapa.patterns

import org.scalatest._
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class PtnNodeTest extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {
  import TLangPattern._

  val EmptyParamArray = Array[Array[String]]()

  def TwoDimArray(p1:String*):Array[Array[String]] = p1.map(Array(_)).toArray

  val parseTestData = Table(
    ("content", "entries", "params"),
    ("list1 list2", List("list1", "list2"), List(EmptyParamArray, EmptyParamArray)),
    ("A_B(l1|l2) A_of_B(m1|m2)", List("A_B", "A_of_B"), List(TwoDimArray("l1", "l2"), TwoDimArray("m1", "m2"))),
    ("list1 A_B(m1|m2)", List("list1", "A_B"), List(EmptyParamArray, TwoDimArray("m1", "m2")))
  )

  @Test
  def testParseContent = {
    forAll(parseTestData) { (content, entries, params) =>
      val r = parseNodeContent(content)
      r.map(_._1) shouldBe entries
      val actualParams = r.map(_._2)
      val params2 = params.map(_.map(_.toIndexedSeq).toIndexedSeq)
      val actualParam2 = actualParams.map(_.paras.map(_.toIndexedSeq).toIndexedSeq)
      actualParam2 shouldBe(params2)
    }
  }
} 
开发者ID:new2scala,项目名称:text-util,代码行数:35,代码来源:PtnNodeTest.scala


示例3: MatcherFuncTests

//设置package包名称以及导入依赖的类
package org.dele.text.maen.utils

import org.dele.text.maen.matchers.MatcherTmpl.MatcherFuncDef
import org.scalatest._
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class MatcherFuncTests extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {

  val mfdef1 = "mf1($1|$2)"
  val mfdef2 = "mf1($2|$1)"
  val mfdef32 = "mf2(x|$2)"
  val mfdef3 = "mf1($2|const|$1)"
  val td = Table(
    ("defis", "input", "result"),
    (Array(mfdef1), Array(Array("a"), Array("b")), Array(Array(Array("a"), Array("b")))),
    //(mfdef1, Array("a", "b/c"), Array[Array[String]](Array("a"), Array("b", "c"))),
    //(mfdef2, Array("a/b", "c/d"), Array[Array[String]](Array("c", "d"), Array("a", "b"))),
    //(mfdef1, Array("9\\/11/8\\/14", "9/11"), Array[Array[String]](Array("9/11", "8/14"), Array("9", "11"))),
    //(mfdef1, Array("9\\/11 / 8\\/14", "9 / 11"), Array[Array[String]](Array("9/11", "8/14"), Array("9", "11"))),
    (Array(mfdef3), Array(Array("a", "b"), Array("c","d")), Array(Array(Array("c", "d"), Array("const"), Array("a", "b")))),
    (Array(mfdef3, mfdef32), Array(Array("a", "b"), Array("c","d")), Array(Array(Array("c", "d"), Array("const"), Array("a", "b")), Array(Array("x"), Array("c", "d")))),
    (Array(mfdef2), Array(Array("a"), Array("b")), Array(Array(Array("b"), Array("a"))))
  )
  @Test
  def t1 = {
    forAll(td) { (defis, input, result) =>
      val mf = new MatcherFuncDef("id1", defis)
      val rng = (0 until mf.templateCount)
      val params = rng.map(mf.getParams(_, input))
      rng.foreach(idx => params(idx) shouldBe result(idx))
    }

  }
} 
开发者ID:new2scala,项目名称:text-util,代码行数:38,代码来源:MatcherFuncTests.scala


示例4: StoppedByMatcherManagerTest

//设置package包名称以及导入依赖的类
package org.dele.text.maen.matchers

import org.scalatest.ShouldMatchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class StoppedByMatcherManagerTest extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {
  import StoppedByMatcherManager._

  val testData = Table(
    ("stoppedByMap", "reverseMap"),

    (Iterable("l1" -> List(StoppedByConfig("sl1", true), StoppedByConfig("sl2", true))), Map("sl1" -> (true -> List("l1")), "sl2" -> (true -> List("l1")))),
    (
      Iterable("l1" -> List(StoppedByConfig("sl1", true), StoppedByConfig("sl2", true)), ("l1" -> List(StoppedByConfig("sl3", false)))),
      Map("sl1" -> (true -> List("l1")), "sl2" -> (true -> List("l1")), "sl3" -> (false -> List("l1")))
    )
  )

  @Test
  def t1 = {
    forAll(testData) {
      (stoppedByMap, reverseMap) => {
        val m = new StoppedByMatcherManager(stoppedByMap)
        reverseMap.foreach(
          p => {
            val k = p._1
            val expected = p._2
            m.getListsStopBy(k).get shouldBe expected
          }
        )
      }
    }
  }

} 
开发者ID:new2scala,项目名称:text-util,代码行数:39,代码来源:StoppedByMatcherManagerTest.scala


示例5: RgbColorTest

//设置package包名称以及导入依赖的类
package kokellab.utils.core.addons

import org.scalacheck.Gen
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, TableDrivenPropertyChecks}
import org.scalatest.{Matchers, PropSpec}


class RgbColorTest extends PropSpec with GeneratorDrivenPropertyChecks with TableDrivenPropertyChecks with Matchers {

	val gen = Gen.listOfN(6, Gen.frequency((10, Gen.numChar), (6, Gen.oneOf('A', 'B', 'C', 'D', 'E', 'F', 'a', 'b', 'c', 'd', 'e', 'f')))) map (_.mkString)
	val things = Table("0000ff", "0000ff")

	property(s"toHex(fromHex)) should be the identity") {
		forAll(gen) { (hexColor: String) =>
			RgbColor.fromHex(hexColor).toHex should equal (hexColor.toLowerCase)
		}}

	val blendGen: Gen[(List[String], String)] = Gen.oneOf(
		(List("CC3366", "99FF00"), "B39933"),
		(List("ff0000", "0000ff", "ff00ff"), "aa00aa")
	)

	property(s"Colors should blend correctly") {
		forAll(blendGen) { case (colors: Seq[String], correct: String) =>
			if (colors.nonEmpty) {
				RgbColor.blend(colors map RgbColor.fromHex).toHex should equal (correct.toLowerCase)
			}
		}}


} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:32,代码来源:RgbColorTest.scala


示例6: BooleanExpressionTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.prop.Tables.Table
import org.scalactic.TolerantNumerics

class BooleanExpressionTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	val doubleEq = TolerantNumerics.tolerantDoubleEquality(1e-4f)

	property(s"Should work, damn it") {
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) = -3", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) ? -3.788", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) ? -3.788", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("(15+20) < 50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(15-20) > -50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(15-20) > -50 and (50*2)=100", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 = 5 = 5", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 = 5 = 6", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5 < 6 < 7", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 > 20 < 15", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5 < 10 = 10", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("2=0 or 50=50 and ((50*2)=100)", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(2=0 or 50=50) and ((50*2)=100)", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("0=1 or 2<5 and 5=5", 0.01) should equal (true) // tests precedence
		BooleanRealNumberGrammar.eval("sqrt(10) < mean(10, 50, 60) nand 50=50", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("sqrt(10) < mean(10, 50, 60) and 50=50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("sqrt(10) >= mean(10, 50, 60) or 50=50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("sqrt(10) >= mean(10, 50, 60) nor 50=50", 0.01) should equal (false)
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:34,代码来源:BooleanRealNumberGrammarTest.scala


示例7: RealNumberGrammarTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.prop.Tables.Table
import org.scalactic.TolerantNumerics

class RealNumberGrammarTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	val doubleEq = TolerantNumerics.tolerantDoubleEquality(1e-4f)

	property(s"Should work, damn it") {
		RealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) + mean(10, 20)") should equal (11.211799096658236)
	}

	property("Exp notation") {
		RealNumberGrammar.eval("-5.0E10 + (2E10) + (1E-2) + (3E+5)") should equal (-2.999969999999E10)
	}

	property("NaN") {
		assert(RealNumberGrammar.eval("-NaN*5").isNaN)
	}
	property("Inf") {
		assert(RealNumberGrammar.eval("-?").isNegInfinity)
	}
} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:27,代码来源:RealNumberGrammarTest.scala


示例8: IfElseRealNumberGrammarTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks

class IfElseRealNumberGrammarTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	property(s"If only") {
		IfElseRealNumberGrammar.eval("if 50>5: 0") should equal (Some(0))
		IfElseRealNumberGrammar.eval("if 50<5: 0") should equal (None)
		IfElseRealNumberGrammar.eval("if 50<5 or 500=500: 0") should equal (Some(0))
	}

	property(s"If-else") {
		IfElseRealNumberGrammar.eval("if 50>5: 0 else: 500") should equal (Some(0))
		IfElseRealNumberGrammar.eval("if 50<5: 0 else: 500") should equal (Some(500))
	}

	property(s"Nested if-else") {
		IfElseRealNumberGrammar.eval("if 2<1: 50 else: if 5<10: 100 else: 150") should equal (Some(100))
		IfElseRealNumberGrammar.eval("if 2<1: 50 else: if 5>10: 100 else: 150") should equal (Some(150))
		IfElseRealNumberGrammar.eval("if 2>1: if 1<2: 5 else: 500") should equal (Some(5))
		IfElseRealNumberGrammar.eval("if 2>1: if 1>2: 5 else: 500") should equal (Some(500))
		IfElseRealNumberGrammar.eval("if 2>1: if 1>2: 5 else: 999 else: 500") should equal (Some(999))
		IfElseRealNumberGrammar.eval("if 1>2: if 1>2: 5 else: 999 else: 500") should equal (Some(500))
		IfElseRealNumberGrammar.eval("if 2>1: if 1>2: 5 elif 2>1: 234 else: 999 else: 500") should equal (Some(234))
		IfElseRealNumberGrammar.eval("if 2>1: if 1>2: 5 elif 1>2: 234 else: 999 else: 500") should equal (Some(999))
		IfElseRealNumberGrammar.eval("if 1>2: if 1>2: 5 elif 1>2: 234 else: 999 elif 2>1: 777 else: 500") should equal (Some(777))
	}

	property(s"If-elif-else") {
		IfElseRealNumberGrammar.eval("if 0=5: 0 elif 10=10: 1 else: 2") should equal (Some(1))
		IfElseRealNumberGrammar.eval("if 0=5: 0 elif 10=-5: 1 else: 2") should equal (Some(2))
		IfElseRealNumberGrammar.eval("if 0=5: 0 elif 10=-5: 1 elif 40=50: 2 elif 50=60: 3 else: 4") should equal (Some(4))
		IfElseRealNumberGrammar.eval("if 0=5: 0 elif 10=-5: 1 elif 40=50: 2 elif 50=50: 3 else: 4") should equal (Some(3))
		IfElseRealNumberGrammar.eval("if 0=5: 0 elif 10=-5: 1 elif 40=50: 2 elif 50=50 and 40=50: 3 else: 4") should equal (Some(4))
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:40,代码来源:IfElseRealNumberGrammarTest.scala


示例9: IfElseStringGrammarTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks

class IfElseStringGrammarTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	property(s"If-elif-else") {
		IfElseStringGrammar.eval("if 0=5: \"cat\" elif 12%5=2: \"dog\" else: \"potato\"") should equal (Some("dog"))
	}

	property(s"Nested if-else") {
		IfElseStringGrammar.eval("""if 2>1: if 1<2: "5" else: "500"""") should equal (Some("5"))
		IfElseStringGrammar.eval("""if 2>1: if 1>2: "5" else: "500"""") should equal (Some("500"))
		IfElseStringGrammar.eval("""if 2>1: if 1>2: "5" else: "999" else: "500"""") should equal (Some("999"))
		IfElseStringGrammar.eval("""if 1>2: if 1>2: "5" else: "999" else: "500"""") should equal (Some("500"))
		IfElseStringGrammar.eval("""if 2>1: if 1>2: "5" elif 2>1: "234" else: "999" else: "500"""") should equal (Some("234"))
		IfElseStringGrammar.eval("""if 2>1: if 1>2: "5" elif 1>2: "234" else: "999" else: "500"""") should equal (Some("999"))
		IfElseStringGrammar.eval("""if 1>2: if 1>2: "5" elif 1>2: "234" else: "999" elif 2>1: "777" else: "500"""") should equal (Some("777"))
	}

	property(s"Trivial") {
		IfElseStringGrammar.eval("\"50+500\"") should equal (Some("50+500"))
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:27,代码来源:IfElseStringGrammarTest.scala


示例10: IfElseIntegerTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks

class IfElseIntegerTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	property(s"If-elif-else") {
		IfElseIntegerGrammar.eval("if 0=5: 1 elif 12%5=2: 2 else: 3") should equal (Some(2))
	}

	property("Nested if-else") {
		IfElseIntegerGrammar.eval("if 2<1: 50 else: if 5<10: 100 else: 150") should equal (Some(100))
		IfElseIntegerGrammar.eval("if 2<1: 50 else: if 5>10: 100 else: 150") should equal (Some(150))
		IfElseIntegerGrammar.eval("if 2>1: if 1<2: 5 else: 500") should equal (Some(5))
		IfElseIntegerGrammar.eval("if 2>1: if 1>2: 5 else: 500") should equal (Some(500))
		IfElseIntegerGrammar.eval("if 2>1: if 1>2: 5 else: 999 else: 500") should equal (Some(999))
		IfElseIntegerGrammar.eval("if 1>2: if 1>2: 5 else: 999 else: 500") should equal (Some(500))
		IfElseIntegerGrammar.eval("if 2>1: if 1>2: 5 elif 2>1: 234 else: 999 else: 500") should equal (Some(234))
		IfElseIntegerGrammar.eval("if 2>1: if 1>2: 5 elif 1>2: 234 else: 999 else: 500") should equal (Some(999))
		IfElseIntegerGrammar.eval("if 1>2: if 1>2: 5 elif 1>2: 234 else: 999 elif 2>1: 777 else: 500") should equal (Some(777))
	}

	property(s"Should fail on fraction") {
		a [GrammarException] should be thrownBy {
			IfElseIntegerGrammar.eval("if 0=5: 1.5 elif 12%5=2: 2 else: 3")
		}
		a [GrammarException] should be thrownBy {
			IfElseIntegerGrammar.eval("sqrt(5)")
		}
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:34,代码来源:IfElseIntegerTest.scala


示例11: SquintsTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars.squints

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.time.Millisecond
import org.scalatest.{Matchers, PropSpec}
import squants.MetricSystem
import squants.mass.{ChemicalAmount, Molars, Moles, SubstanceConcentration}
import squants.space.Inches
import squants.time.{Hours, Milliseconds, Seconds, Time}

class SquintsTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	property(s"Molarity") {
		val squinter = new Squinter(SubstanceConcentration.apply(_), Set("M", "mol/L"))
		squinter("5 Gmol/L") should equal (Molars(5) * MetricSystem.Giga)
	}

	property(s"Time") {
		val squinter = new Squinter(Time.apply(_), Set("s", "m", "h", "d")) // this has a weird consequence of allowing picohours and femtodays
		squinter("5 Gs") should equal (Seconds(5) * MetricSystem.Giga)
		squinter("5E6 ms") should equal (Seconds(5000))
		squinter("5.23E-02 µh") should equal (Hours(5.23E-8))
	}

	property("Time without a prefix or units") {
		val squinter: Squinter[Time] = new Squinter(Time.apply(_), Set("s", "m", "h"), numberParser = _.toInt, defaultUnit = "ms", numberPattern = Squinter.nonnegativeDoublePattern,
			siPrefixes = List(SiPrefix.milli, SiPrefix.kilo))
		squinter("7s") should equal (Seconds(7))
		squinter("7 s") should equal (Seconds(7))
		squinter("7") should equal (Milliseconds(7))
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:34,代码来源:SquintsTest.scala


示例12: AlphanumericGridTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks

class AlphanumericGridTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	property("Index, rows, and columns") {
		val grid = AlphanumericGrid(4, 6)
		import grid.Point
		Point(1, 1).index should equal (1)
		Point(1, 2).index should equal (2)
		Point(1, 6).index should equal (6)
		Point(2, 1).index should equal (7)
		Point(4, 6).index should equal (4*6)
		Point(1, 1) should equal (new Point(1))
		Point(1, 2) should equal (new Point(2))
		Point(1, 6) should equal (new Point(6))
		Point(2, 1) should equal (new Point(7))
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:23,代码来源:AlphanumericGridTest.scala


示例13: TransferServiceSpec

//设置package包名称以及导入依赖的类
package sample

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FunSpec, GivenWhenThen, Matchers}

class TransferServiceSpec extends FunSpec with Matchers with TableDrivenPropertyChecks with GivenWhenThen {
  describe("TransferService"){
    it("can transfer money from source account to target account"){
      val srcAccount = new Account("xx",100.0)
      val targetAccount = new Account("yy", 50.0)
      TransferService.transfer(srcAccount, targetAccount, 50.0)
      srcAccount.balance shouldBe 50.0
      targetAccount.balance shouldBe 100.0
    }
    it("transfer should fail if not enough balance in source account"){
      pending
    }
    //this is a scalatest table-driven-property-check example
    it("can transfer any amount of money"){
      val example =
        Table(
          ("source account balance","target account balance","transfer amount"," expected source account balance","expected target account balance"),
          (100, 50, 50, 50, 100),
          (77, 0, 50, 27, 50)
        )
      forAll(example){ (srcBalance, targetBalance, amount, expSrcBalance,expTargetBalance) =>
        Given(s"source account who's owner is xx,have balance: $srcBalance")
        val srcAccount = new Account("xx", srcBalance)
        And(s"target account who's owner is yy, have balance: $targetBalance")
        val targetAccount = new Account("yy", targetBalance)
        When(s"Transfer $amount from srcAccount to targetAccount")
        TransferService.transfer(srcAccount, targetAccount, amount)
        Then(s"srcAccount should have balance $expSrcBalance")
        srcAccount.balance shouldBe expSrcBalance
        And(s"targetAccount should have balance $expTargetBalance")
        targetAccount.balance shouldBe expTargetBalance
      }
    }
  }
} 
开发者ID:notyy,项目名称:scalaTrainning,代码行数:41,代码来源:TransferServiceSpec.scala


示例14: SolutionValidatorSpec

//设置package包名称以及导入依赖的类
package sudoku.validator

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FlatSpec, Matchers}
import sudoku.Boards

class SolutionValidatorSpec extends FlatSpec with Matchers with TableDrivenPropertyChecks
{

  val cases = Table(
    ("input", "expected"),
    (Boards.VALID, true),
    (Boards.INCOMPLETE_VALID, true),
    (Boards.INVALID, false),
    (Boards.INVALID_SUBGROUP, false),
    (Boards.INVALID_ROW, false),
    (Boards.INVALID_COL, false)
  )

  "SolutionValidator" should "validate sudokus" in {
    forAll(cases) { (board, expected) =>
      SolutionValidator.validate(board) should be === expected
    }
  }

} 
开发者ID:buritos,项目名称:SudokuValidator,代码行数:27,代码来源:SolutionValidatorSpec.scala


示例15: UrlParserTest

//设置package包名称以及导入依赖的类
package webcrawler

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FreeSpec, Matchers}

class UrlParserTest extends FreeSpec with TableDrivenPropertyChecks with Matchers {

  "A parser" - {
    val parser = UrlParser()
    "when parsing a string with" - {

      "no hrefs" - {
        val validHtmlWithNoTags = "<html></html>"
        val invalidHtml = "lsdkhfasldkhfsadhf<>J!!!"

        "should return an empty set" in {
          parser.parse(validHtmlWithNoTags) shouldBe empty
          parser.parse(invalidHtml) shouldBe empty
        }
      }

      "a single href value" - {

        val fancyUrl = """http://AaZz123456789'0_.~!*();:@&+$,/?$[%-].com"""
        val table = Table(
          ("input", "output"),
          ("""<a href='http://myurl.com'>>""", Set("http://myurl.com")),
          ("""<a href='http://myurl12.com'>>""", Set("http://myurl12.com")),
          ("""<a href="http://myurl.com">>""", Set("http://myurl.com")),
          (s"""<a href="$fancyUrl">>""", Set(fancyUrl)),
          ("""fhsdlf <buya! href="http://myurl.com"!! >xxcd//!**)(*>""", Set("http://myurl.com")),
          ("""<a href  =   "http://myurl.com">>""", Set("http://myurl.com"))
        )

        "should return that value" in {
          forAll(table) { (input, output) =>
            parser.parse(input) shouldBe output
          }
        }
      }

      "multiple href values" - {
        val table = Table(
          ("input", "output"),
          ("""<a href='http://myurl.com'>><boo href = 'baz' """, Set("/baz", "http://myurl.com")),
          ("""<a href='http://myurl.com/foobar/'>>""", Set("http://myurl.com/foobar")),
          ("""<a href='http://myurl.com'>><boo href = '/baz' """, Set("/baz", "http://myurl.com")),
          ("""<a href='http://myurl.com'>><boo href = ' /baz '><><href ="/baz">//>> """, Set("/baz", "http://myurl.com")),
          ("""<a href='http://myurl.com'>><boo href ="/baz" """, Set("/baz", "http://myurl.com"))
        )

        "should return those unique values" in {
          forAll(table) { (input, output) =>
            parser.parse(input) shouldBe output
          }
        }
      }
    }
  }
} 
开发者ID:memoizr,项目名称:web-crawler-kata,代码行数:61,代码来源:UrlParserTest.scala


示例16: ProcessObjectsFinderTest

//设置package包名称以及导入依赖的类
package pl.touk.nussknacker.ui.process

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FlatSpec, Matchers}
import pl.touk.nussknacker.engine.build.EspProcessBuilder
import pl.touk.nussknacker.ui.api.ProcessTestData._
import pl.touk.nussknacker.ui.api.helpers.TestProcessUtil

class ProcessObjectsFinderTest extends FlatSpec with Matchers with TableDrivenPropertyChecks {

  val process1 = TestProcessUtil.toDisplayable(
    EspProcessBuilder.id("fooProcess1").exceptionHandler()
      .source("source", existingSourceFactory)
      .customNode("custom", "out1", existingStreamTransformer)
      .customNode("custom2", "out2", otherExistingStreamTransformer)
      .sink("sink", existingSinkFactory))

  val process2 = TestProcessUtil.toDisplayable(
    EspProcessBuilder.id("fooProcess2").exceptionHandler()
      .source("source", existingSourceFactory)
      .customNode("custom", "out1", otherExistingStreamTransformer)
      .sink("sink", existingSinkFactory))

  val process3 = TestProcessUtil.toDisplayable(
    EspProcessBuilder.id("fooProcess3").exceptionHandler()
      .source("source", existingSourceFactory)
      .sink("sink", existingSinkFactory))

  it should "find processes for queries" in {
    val queriesForProcesses = ProcessObjectsFinder.findQueries(List(process1, process2, process3), processDefinition)

    queriesForProcesses shouldBe Map(
      "query1" -> List(process1.id),
      "query2" -> List(process1.id),
      "query3" -> List(process1.id, process2.id)
    )
  }

  it should "find processes for transformers" in {
    val table = Table(
      ("transformers", "expectedProcesses"),
      (Set(existingStreamTransformer), List(process1.id)),
      (Set(otherExistingStreamTransformer), List(process1.id, process2.id)),
      (Set(existingStreamTransformer, otherExistingStreamTransformer), List(process1.id, process2.id)),
      (Set("garbage"), List())
    )
    forAll(table) { (transformers, expectedProcesses) =>
      val definition = processDefinition.withSignalsWithTransformers("signal1", classOf[String], transformers)
      val signalDefinition = ProcessObjectsFinder.findSignals(List(process1, process2, process3), definition)
      signalDefinition should have size 1
      signalDefinition("signal1").availableProcesses shouldBe expectedProcesses
    }

  }

} 
开发者ID:TouK,项目名称:nussknacker,代码行数:57,代码来源:ProcessObjectsFinderTest.scala


示例17: TestCustomIndexName

//设置package包名称以及导入依赖的类
package com.datamountaineer.streamreactor.connect.elastic.indexname

import org.scalatest.prop.{GeneratorDrivenPropertyChecks, TableDrivenPropertyChecks}
import org.scalatest.{FlatSpec, Matchers}

class TestCustomIndexName extends FlatSpec with TableDrivenPropertyChecks with GeneratorDrivenPropertyChecks with Matchers {

  val ValidIndexNames = Table(
    ("Valid index name", "Expectations"),
    ("", Vector()),
    ("abc", Vector(TextFragment("abc"))),
    ("abc{YYYY-MM-dd}", Vector(TextFragment("abc"), DateTimeFragment("YYYY-MM-dd"))),
    ("{YYYY-MM-dd}abc", Vector(DateTimeFragment("YYYY-MM-dd"), TextFragment("abc"))),
    ("{YYYY-MM-dd}abc{HH-MM-ss}", Vector(DateTimeFragment("YYYY-MM-dd"), TextFragment("abc"), DateTimeFragment("HH-MM-ss"))),
    ("{YYYY-MM-dd}{HH-MM-ss}", Vector(DateTimeFragment("YYYY-MM-dd"), DateTimeFragment("HH-MM-ss"))),
    ("abc{}", Vector(TextFragment("abc"))),
    ("{}abc", Vector(TextFragment("abc")))
  )

  val InvalidIndexNames = Table(
    ("Invalid index name"),
    ("}abc"),
    ("abc}"),
    ("abc}def")
  )

  "Custom index name" should "parse a valid String with date time formatting options" in {
    forAll (ValidIndexNames) { case (validIndexName, expectations) =>
      CustomIndexName.parseIndexName(validIndexName) shouldBe CustomIndexName(expectations)
    }
  }

  it should "throw an exception when using invalid index name" in {
    forAll (InvalidIndexNames) { case (invalidIndexName) =>
      intercept[InvalidCustomIndexNameException] {
        CustomIndexName.parseIndexName(invalidIndexName)
      }
    }
  }

  it should "return a valid String from a list of fragments" in new ClockFixture {
    CustomIndexName(
      Vector(DateTimeFragment("YYYY-MM-dd", TestClock),
        TextFragment("ABC"),
        DateTimeFragment("HH:mm:ss", TestClock))
    ).toString shouldBe "2016-10-02ABC14:00:00"
  }
} 
开发者ID:datamountaineer,项目名称:stream-reactor,代码行数:49,代码来源:TestCustomIndexName.scala


示例18: HiveTypeParserSpec

//设置package包名称以及导入依赖的类
package com.criteo.vizatra.vizsql.hive

import com.criteo.vizatra.vizsql._
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{Matchers, PropSpec}

class HiveTypeParserSpec extends PropSpec with Matchers {

  val types = TableDrivenPropertyChecks.Table(
    ("Type string", "Expected type"),

    ("double", DECIMAL(true)),
    ("array<int>", HiveArray(INTEGER(true))),
    ("map<string,struct<a:boolean,b:timestamp>>", HiveMap(STRING(true), HiveStruct(List(
      Column("a", BOOLEAN(true)),
      Column("b", TIMESTAMP(true))
    )))),
    ("array<struct<foo:array<map<string,string>>,bar:array<int>,`baz`:double>>", HiveArray(HiveStruct(List(
      Column("foo", HiveArray(HiveMap(STRING(true), STRING(true)))),
      Column("bar", HiveArray(INTEGER(true))),
      Column("baz", DECIMAL(true))
    )))),
    ("struct<timestamp:integer>", HiveStruct(List(
      Column("timestamp", INTEGER(true))
    )))
  )

  // --

  property("parse to correct types") {
    val parser = new TypeParser
    TableDrivenPropertyChecks.forAll(types) {
      case (typeString, expectedType) =>
        parser.parseType(typeString) shouldEqual Right(expectedType)
    }
  }
} 
开发者ID:criteo,项目名称:vizsql,代码行数:38,代码来源:HiveTypeParserSpec.scala


示例19: HiveParsingErrorsSpec

//设置package包名称以及导入依赖的类
package com.criteo.vizatra.vizsql.hive

import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{EitherValues, Matchers, PropSpec}

class HiveParsingErrorsSpec extends PropSpec with Matchers with EitherValues {

  val invalidSQL99SelectStatements = TableDrivenPropertyChecks.Table(
    ("SQL", "Expected error"),

    (
      "select bucket from t",
      """select bucket from t
        |       ^
        |Error: *, table or expression expected
      """
    ),
    (
      "select foo from tbl limit 100 order by foo",
      """select foo from tbl limit 100 order by foo
        |                              ^
        |Error: ; expected
      """
    ),
    (
      "select foo from bar tablesample (bucket 2 out af 3)",
      """select foo from bar tablesample (bucket 2 out af 3)
        |                                              ^
        |Error: of expected
      """.stripMargin
    )
  )

  // --

  property("report parsing errors on invalid Hive statements") {
    TableDrivenPropertyChecks.forAll(invalidSQL99SelectStatements) {
      case (sql, expectedError) =>
        new HiveDialect(Map.empty).parser.parseStatement(sql)
          .fold(_.toString(sql, ' ').trim, _ => "[NO ERROR]") should be (expectedError.toString.stripMargin.trim)
    }
  }

} 
开发者ID:criteo,项目名称:vizsql,代码行数:45,代码来源:HiveParsingErrorsSpec.scala


示例20: ProvidersTest

//设置package包名称以及导入依赖的类
package ru.tinkoff.api.providers

import org.scalactic.Snapshots._
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{FlatSpec, GivenWhenThen}
import play.api.libs.json.{JsArray, JsValue}

class ProvidersTest extends FlatSpec with GivenWhenThen with TableDrivenPropertyChecks {

  val providerGroups =
    Table(
      ("providerName"),
      ("????????"),
      ("????????"),
      ("???????????????????")
    )

  forAll(providerGroups) {
    (groupId: String) => {
      s"Provider group $groupId" should "return ok from ANONYMOUS with groups" in {
        When("I perform providers")
        val model = new ProvidersModel(ProvidersRequestHolder(groups = Some(groupId)))
        model.fire()
        info(s"$model")
        Then("I expect status in 2xx")
        assert(model.checkResult(), snap(model.globResult))
        Then("I expect doc is JSON")
        assert(model.responseModel.isInstanceOf[JsValue], snap(model))
        Then("I expect resultCode is OK")
        assert((model.responseModel \ "resultCode").asOpt[String].contains("OK"), snap(model))
        Then(s"I expect all groupId is $groupId")
        (model.responseModel \\ "groupId").foreach(x => {
          assert(x.as[String] == groupId, snap(model))
        })
        Then("I expect name is ??????? ??????????? where id is lastName")
        (model.responseModel \\ "providerFields").foreach(x => {
          x.as[JsArray].value.foreach(y => {if((y \ "id").asOpt[String].contains("lastName")){
            assert((y \ "name").asOpt[String].getOrElse("None").contains("???????"), snap(y))
          }})
        })
      }
    }
  }
} 
开发者ID:nmiroshnichenko,项目名称:apitests,代码行数:45,代码来源:ProvidersTest.scala



注:本文中的org.scalatest.prop.TableDrivenPropertyChecks类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Before类代码示例发布时间:2022-05-23
下一篇:
Scala HandlerList类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap