Questions tagged [scalacheck]

ScalaCheck is a powerful tool for automatic unit testing of Scala and Java programs.

ScalaCheck is a powerful tool for automatic unit testing of Scala and Java programs. It features automatic test case generation and minimization of failing test cases. ScalaCheck started out as a Scala port of the Haskell library QuickCheck, and has since evolved and been extended with features not found in Haskell QuickCheck .

275 questions
4
votes
2 answers

Generate arbitrary Function1 in ScalaCheck

For my testing, I would like to generate arbitrary random functions of type String => Boolean. Is it possible to do that using ScalaCheck?
IllSc
  • 1,419
  • 3
  • 17
  • 24
4
votes
3 answers

How can I get random data generated for scala case classes with the ability to "change some values" for unit testing?

I'm working with a piece of code that has a broad/deep case class hierarchy. For unit testing, I'd like to have "random data" populated in the classes with the ability to change the data for the fields I care about? Example: case class Foo(bar: Bar,…
PhD
  • 11,202
  • 14
  • 64
  • 112
4
votes
1 answer

ScalaCheck generate BST

I'm trying to create a Gen for BST with ScalaCheck, but when I call .sample method it gives me java.lang.NullPointerException. Where do I wrong? sealed trait Tree case class Node(left: Tree, right: Tree, v: Int) extends Tree case object Leaf…
Marco Mantovani
  • 111
  • 2
  • 7
4
votes
2 answers

generating permutations with scalacheck

I have some generators like this: val fooRepr = oneOf(a, b, c, d, e) val foo = for (s <- choose(1, 5); c <- listOfN(s, fooRepr)) yield c.mkString("$") This leads to duplicates ... I might get two a's, etc. What I really want is to generate random…
4
votes
1 answer

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

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…
bugfoot
  • 667
  • 7
  • 20
4
votes
1 answer

Symbol 'type .scalacheck.Shrink' is missing from the classpath

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…
bsky
  • 19,326
  • 49
  • 155
  • 270
4
votes
1 answer

There is no started application when trying to use beforeAll in scalatest

in my test class I want to do something before all the tests begin, so I did something like this: class ApplicationSpec extends FreeSpec with OneServerPerSuite with BeforeAndAfterAll { override protected def beforeAll(): Unit = { …
JohnBigs
  • 2,691
  • 3
  • 31
  • 61
4
votes
1 answer

ScalaCheck can not cast boolean to Prop instance

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…
ppopoff
  • 658
  • 7
  • 17
4
votes
1 answer

ScalaCheck valid/invalid test boundary

I'm using ScalaCheck to do some property-based tests in ScalaTest. Say I want to test a function, f(x: Double): Double that is only defined for x >= 0.0, and which returns NaN for arguments outside of that domain. Ideally, I'd like to do something…
scalabling
  • 112
  • 1
  • 7
4
votes
1 answer

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

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…
Zaphod
  • 1,387
  • 2
  • 17
  • 33
4
votes
2 answers

Deriving arbitrary function instances using shapeless-scalacheck

After upgrading to scalacheck 1.13.3, I'm running into an odd issue where deriving instances of A => B Or C, where Or is essentially a light Either, will almost always fail. This is the simplest code I could write to reproduce the issue: import…
Nicolas Rinaudo
  • 6,068
  • 28
  • 41
4
votes
1 answer

How to test Monad instance using discipline

Given a monad for Fun type type FUN[A] = Map[String, String] => (List[String], A) val funMonad: Monad[FUN] = new Monad[FUN] { override def flatMap[A, B](fa: FUN[A])(f: (A) => FUN[B]): FUN[B] = m => { val (list1, a1) = fa(m) val (list2,…
pawel.panasewicz
  • 1,831
  • 16
  • 27
4
votes
1 answer

How to use ScalaCheck's collect and classify in ScalaTest?

The following use of Prop.collect((a, b)) isn't printing the statistics as expected even though the test runs successfully. import org.scalacheck.Prop import org.scalatest.{GivenWhenThen, PropSpec} import org.scalatest.prop.{Checkers,…
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
4
votes
1 answer

ScalaCheck: Gen.choose outputting values beyond a specified range

I am using Scalacheck for finding defects, as a part of an assignment. Unbelievably perhaps, I am stuck as it is generating a pair of non-zero integers. From my IntelliJ worksheet, ad verbatim: import org.scalacheck._ import Arbitrary._ …
Nirmalya
  • 717
  • 9
  • 19
4
votes
3 answers

How to generate time using scalacheck generators?

Is there a way to generate random dates for property tests using Scalacheck . I want to generate both future and past dates . But the existing Scalacheck.Gen class does not provide any predefined method to do so .
trupti rath
  • 71
  • 1
  • 6