当前位置: 首页>>代码示例>>Scala>>正文


Scala TableDrivenPropertyChecks类代码示例

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


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


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