本文整理汇总了Scala中org.scalatest.PropSpec类的典型用法代码示例。如果您正苦于以下问题:Scala PropSpec类的具体用法?Scala PropSpec怎么用?Scala PropSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PropSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CheckSpec
//设置package包名称以及导入依赖的类
package example
import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop._
class CheckSpec
extends PropSpec
with GeneratorDrivenPropertyChecks
with Matchers {
property ("Addition and multiplication are related") {
forAll { (x: Int) =>
whenever(x > 0) {
x * 2 should be(x + x)
}
}
}
}
示例2: CheckSpec
//设置package包名称以及导入依赖的类
package com.andreaskostler.grpcs
import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop._
class CheckSpec
extends PropSpec
with GeneratorDrivenPropertyChecks
with Matchers {
property ("Addition and multiplication are related") {
forAll { (x: Int) =>
whenever(x > 0) {
x * 2 should be(x + x)
}
}
}
}
示例3: CheckSpec
//设置package包名称以及导入依赖的类
package io.mehitabel.morphism
import org.scalatest.{ Matchers, PropSpec }
import org.scalatest.prop._
class CheckSpec
extends PropSpec
with GeneratorDrivenPropertyChecks
with Matchers {
property("Addition and multiplication are related") {
forAll { (x: Int) ?
whenever(x > 0) {
x * 2 should be(x + x)
}
}
}
}
示例4: 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)
}
}}
}
示例5: TextUtilsTest
//设置package包名称以及导入依赖的类
package kokellab.utils.core.addons
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{Matchers, PropSpec}
class TextUtilsTest extends PropSpec with GeneratorDrivenPropertyChecks with Matchers {
property("signByte can be out of range") {
assertThrows[NumberFormatException] {
TextUtils.signByte("270")
}
}
property("pint can be out of range") {
assertThrows[NumberFormatException] {
TextUtils.signByte("270")
}
assertThrows[NumberFormatException] {
TextUtils.signByte("-1")
}
}
property("pint strips .0") {
TextUtils.pint("1000.0") should equal (1000)
}
property("signByte strips .0") {
TextUtils.signByte("200.0") should equal (200 - 128)
TextUtils.signByte("0.0") should equal (0 - 128)
}
}
示例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)
}
}
示例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)
}
}
示例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))
}
}
示例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"))
}
}
示例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)")
}
}
}
示例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))
}
}
示例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))
}
}
示例13: GridRangeGrammarTest
//设置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 GridRangeGrammarTest extends PropSpec with TableDrivenPropertyChecks with Matchers {
property(s"Only one") {
val parser = new GridRangeGrammar("A1", AlphanumericGrid(5, 6))
parser.run().get.map(_.name) should equal (List("A1"))
}
property(s"Simple range horizontal") {
val parser = new GridRangeGrammar("A1-A4", AlphanumericGrid(5, 6))
parser.run().get.map(_.name) should equal (List("A1", "A2", "A3", "A4"))
}
property(s"Simple range vertical") {
val parser = new GridRangeGrammar("A1-D1", AlphanumericGrid(5, 6))
parser.run().get.map(_.name) should equal (List("A1", "B1", "C1", "D1"))
}
property(s"Block range") {
val parser = new GridRangeGrammar("A1*C3", AlphanumericGrid(5, 6))
parser.run().get.map(_.name) should equal (List("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"))
}
property(s"Traversal range") {
val parser = new GridRangeGrammar("A1...C2", AlphanumericGrid(5, 6))
parser.run().get.map(_.name) should equal (List("A1", "A2", "A3", "A4", "A5", "A6", "B1", "B2", "B3", "B4", "B5", "B6", "C1", "C2"))
}
property(s"Traversal range at end") {
val parser = new GridRangeGrammar("A1...D2", AlphanumericGrid(4, 2))
parser.run().get.map(_.name) should equal (List("A1", "A2", "B1", "B2", "C1", "C2", "D1", "D2"))
}
}
示例14: BarcoderTest
//设置package包名称以及导入依赖的类
package kokellab.utils.misc
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import com.google.zxing.BarcodeFormat
import org.scalacheck.Gen
import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks}
import org.scalatest.{Matchers, PropSpec}
class BarcoderTest extends PropSpec with GeneratorDrivenPropertyChecks with Matchers {
def fakeEncodeDecode(text: String, barcodeFormat: BarcodeFormat, dimensions: (Int, Int), imageFormat: String): String =
if (text.isEmpty) text else encodeDecode(text.toUpperCase, barcodeFormat, dimensions, imageFormat)
def genBoundedList[T](maxSize: Int, gen: Gen[T]): Gen[List[T]] =
Gen.choose(0, maxSize) flatMap (size => Gen.listOfN(size, gen))
def genBoundedString(maxSize: Int, gen: Gen[Char]): Gen[String] =
Gen.choose(0, maxSize) flatMap (size => Gen.listOfN(size, gen) map (_.mkString))
def encodeDecode(text: String, codeFormat: BarcodeFormat, dimensions: (Int, Int), imageFormat: String): String = {
val barcoder = new Barcoder(codeFormat, imageFormat, dimensions._1, dimensions._2)
val os = new ByteArrayOutputStream()
barcoder.encode(text, os)
val is = new ByteArrayInputStream(os.toByteArray)
barcoder.decode(is)
}
val imageFormatGen = Gen.oneOf("png", "jpg", "gif")
def test(barcodeFormat: BarcodeFormat, dimensionsGen: Gen[(Int, Int)], stringGen: Gen[String]) = {
property(s"Decoding an encoded string should yield the original string for ${barcodeFormat.name} codes") {
forAll(imageFormatGen, stringGen, dimensionsGen) { (imageFormat: String, text: String, dimensions: (Int, Int)) =>
fakeEncodeDecode(text, barcodeFormat, dimensions, imageFormat) should equal (text.toUpperCase)
}
}
}
val rectangularGen: Gen[(Int, Int)] = for {
width <- Gen.choose(20, 100)
height <- Gen.choose(20, 100)
} yield (width, height)
val squareGen: Gen[(Int, Int)] = for {
size <- Gen.choose(20, 100)
} yield (size, size)
val code39And93Gen: Gen[String] = genBoundedString(48, Gen.frequency((36, Gen.alphaNumChar), (7, Gen.oneOf('-', '.', '$', '/', '+', '%', ' '))))
test(BarcodeFormat.CODE_39, rectangularGen, code39And93Gen)
test(BarcodeFormat.CODE_93, rectangularGen, code39And93Gen)
// TODO this fails due to https://github.com/zxing/zxing/issues/716
// there's nothing I can do now
// test(BarcodeFormat.CODE_128, rectangularGen, genBoundedString(48, Gen.choose[Char](0x20, 127)))
// TODO QR codes break; also not my fault
// test(BarcodeFormat.QR_CODE, squareGen, genBoundedString(4296, Gen.frequency((36, Gen.alphaNumChar), (8, Gen.oneOf('-', '.', '$', '/', '+', '%', ' ', ':')))))
}
示例15: SevenZipTest
//设置package包名称以及导入依赖的类
package kokellab.utils.misc
import java.io.File
import java.nio.file.{Files, Paths}
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{Matchers, PropSpec}
import scala.io.Source
class SevenZipTest extends PropSpec with Matchers {
val archive = Paths.get(this.getClass.getResource("test.7z").toURI)
val correctFile = Paths.get(this.getClass.getResource("expected_file_to_hash.txt").toURI)
val newFile = Paths.get(archive.getParent.toFile.getPath, "file_to_hash.txt")
newFile.toFile.deleteOnExit()
property("Should be able to unzip correctly") {
SevenZip.un7zip(archive, archive.getParent)
val goodStuff = Source.fromFile(correctFile.toFile).mkString
val newStuff = Source.fromFile(newFile.toFile).mkString
goodStuff should equal (newStuff)
}
}