scalacheck

Make ScalaCheck tests deterministic

这一生的挚爱 提交于 2020-01-12 01:45:08
问题 I would like to make my ScalaCheck property tests in my specs2 test suite deterministic, temporarily, to ease debugging. Right now, different values could be generated each time I re-run the test suite, which makes debugging frustrating, because you don't know if a change in observed behaviour is caused by your code changes, or just by different data being generated. How can I do this? Is there an official way to set the random seed used by ScalaCheck? I'm using sbt to run the test suite.

How to use scalacheck prop generators in scalatest FlatSpec

风流意气都作罢 提交于 2020-01-04 16:58:10
问题 I'm trying to use the scalacheck property generators in a scalatest.FlatSpec test file. The test should fail and be reported by junit framework (and eclipse in my case) but the test pass and error is just displayed in console. import scala.collection.immutable.TreeSet import org.junit.runner.RunWith import org.raisercostin.namek.UnitSpec import org.scalatest.junit.JUnitRunner import org.scalatest.FlatSpec import org.scalatest._ @RunWith(classOf[JUnitRunner]) class SetsTest2 extends FlatSpec

How to use scalacheck prop generators in scalatest FlatSpec

烂漫一生 提交于 2020-01-04 16:57:05
问题 I'm trying to use the scalacheck property generators in a scalatest.FlatSpec test file. The test should fail and be reported by junit framework (and eclipse in my case) but the test pass and error is just displayed in console. import scala.collection.immutable.TreeSet import org.junit.runner.RunWith import org.raisercostin.namek.UnitSpec import org.scalatest.junit.JUnitRunner import org.scalatest.FlatSpec import org.scalatest._ @RunWith(classOf[JUnitRunner]) class SetsTest2 extends FlatSpec

How can I generate a list of n unique elements picked from a set?

五迷三道 提交于 2020-01-03 16:51:23
问题 How to generate a list of n unique values ( Gen[List[T]] ) from a set of values (not generators) using ScalaCheck? This post uses Gen[T]* instead of a set of values, and I can't seem to rewrite it to make it work. EDIT At @Jubobs' request I now shamefully display what I have tried so far, revealing my utter novice status at using ScalaCheck :-) I simply tried to replace gs: Gen[T] repeated parameter to a Set in what @Eric wrote as a solution here: def permute[T](n: Int, gs: Set[T]): Gen[Seq[T

Symbol 'type <none>.scalacheck.Shrink' is missing from the classpath

拈花ヽ惹草 提交于 2019-12-23 18:47:22
问题 I have the following ScalaCheck unit test using Mockito: import org.scalatest.mockito.MockitoSugar import org.mockito.Mockito.when import org.scalatest.prop.PropertyChecks import org.mockito.Mockito.verify class PlayerTest extends org.scalatest.FunSuite with MockitoSugar with PropertyChecks { test("doesn't accept anything but M") { val mockIOHandler = mock[IOHandler] val name = "me" val player = new Player(name) when(mockIOHandler.nextLine).thenReturn("m") val apiUser = new Player("player1")

ScalaCheck can not cast boolean to Prop instance

▼魔方 西西 提交于 2019-12-23 12:37:07
问题 I have the following property: import org.scalacheck.Prop.propBoolean def elementsAreReversed(list: List[Int], reversed: List[Int]): Boolean = if (list.isEmpty) true else { val lastIdx = list.size - 1 list.zipWithIndex.forall { case (element, index) => element == reversed(lastIdx - index) } } val propReversed = Prop.forAll { list: List[Int] => val reversed = list.reverse if (list.isEmpty) list == reversed else { val hasSameSize = reversed.size == list.size val hasAllElements = list.forall

Pattern for generating negative Scalacheck scenarios: Using property based testing to test validation logic in Scala

China☆狼群 提交于 2019-12-22 08:43:32
问题 We are looking for a viable design pattern for building Scalacheck Gen (generators) that can produce both positive and negative test scenarios. This will allow us to run forAll tests to validate functionality (positive cases), and also verify that our case class validation works correctly by failing on all invalid combinations of data. Making a simple, parameterized Gen that does this on a one-off basis is pretty easy. For example: def idGen(valid: Boolean = true): Gen[String] = Gen.oneOf(ID

Generate Option[T] in ScalaCheck

早过忘川 提交于 2019-12-21 03:18:28
问题 I am trying to generate optional parameters in ScalaCheck, without success. There seems to be no direct mechanism for this. Gen.containerOf[Option, Thing](thingGenerator) fails because it cannot find an implicit Buildable[Thing, Option] . I tried for { thing <- Gen.listOfN[Thing](1, thingGenerator) } yield thing.headOption But this doesn't work because listOfN produces a list that is always of length N. As a result I always get a Some[Thing] . Similarly, listOf1 does not work, because (a) it

Why do you need Arbitraries in scalacheck?

我怕爱的太早我们不能终老 提交于 2019-12-18 12:15:35
问题 I wonder why Arbitrary is needed because automated property testing requires property definition, like val prop = forAll(v: T => check that property holds for v) and value v generator. The user guide says that you can create custom generators for custom types (a generator for trees is exemplified). Yet, it does not explain why do you need arbitraries on top of that. Here is a piece of manual implicit lazy val arbBool: Arbitrary[Boolean] = Arbitrary(oneOf(true, false)) To get support for your

No implicit view available from AnyVal => org.scalacheck.Prop. [error] property

久未见 提交于 2019-12-12 10:21:58
问题 I have 2 questions I am trying to learn scalacheck Question 1) Here is the test I am writing which is throwing the error. Can you please point to which page from docmentation i should read to understand reason behind this error. case class Student(name:String, age:Int, mathsScore:Int, scienceScore:Int){ require(name != null ,"Name cannot be blank") require(age > 3 ,"Age should be more than 3") require(mathsScore >= 0 , "Score should not be negative") require(scienceScore >= 0 ,"Score should