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
0
votes
0 answers

Using specs2 + scalacheck to validate type classes (simple Arbitrary[...] example)

I'm having trouble getting specs2 and scalacheck to cooperate. I have a simple class, Credit, that takes a single integer within the range of 1 to 59 (anything outside of this range should throw an exception). I want to define two tests: 1 test that…
Zaphod
  • 1,387
  • 2
  • 17
  • 33
0
votes
2 answers

scalacheck whenever value not recognized

I have a basic question about scalacheck's whenever clause. For some reason, my compiler doesn't recognize whenever, nor the (conditional subset) ==> part. (I am following along Odersky's second scala course on Coursera, and I've written a…
Allen Wang
  • 2,426
  • 2
  • 24
  • 48
0
votes
1 answer

how to reuse generated data on scalacheck

In our system we have really big objects that are generated for scalacheck. All properties are of the same data structure, and therefore it seems unnecessary to generate cases for each property. They should be reused. I'm aware of something like…
caente
  • 141
  • 7
0
votes
1 answer

Why does a Scalacheck Prop value not get evaluated?

The official scalacheck documentation gives the following example: property("stringLength") = Prop.forAll { s: String => val len = s.length (s+s).length == len+len } I read that this can also be written as: val stringLength =…
Pavel
  • 3,481
  • 26
  • 31
0
votes
1 answer

enable implicit import for runtime type in scala check. "could not find implicit value for parameter"

I'm testing my own home-brewed Monoid classes in scala using the ScalaCheck library and ScalaTest when attempting to implement DRY tests, I get the implicit error in the title: Error:(16, 12) could not find implicit value for parameter arbA:…
coderatchet
  • 8,120
  • 17
  • 69
  • 125
0
votes
1 answer

ScalaCheck nested Gen

In ScalaCheck it seems that a mapped/flatMapped Gen will fail as soon as any inner gen has a value filtered out. E.g. (using ScalaTest) class ScalaCheckGen extends FreeSpec with GeneratorDrivenPropertyChecks { "Fails" in { …
Pengin
  • 4,692
  • 6
  • 36
  • 62
0
votes
1 answer

Output of unit test printed after execution of the test finished

I have the following unit test: test("All - gather message") { def fs: List[Future[Int]] = List(Future{ blocking {Thread.sleep(4000)} println("Finished sleeping in future 1!") 1 }, Future { blocking…
bsky
  • 19,326
  • 49
  • 155
  • 270
0
votes
1 answer

Can Gen[String] Produce Other Values?

Given: import org.scalatest._ import org.scalatest.prop.Checkers import org.scalacheck.Gen import org.scalacheck.Gen._ object Test { def fooOrBar: Gen[String] = oneOf("foo", "bar") } class Test extends FunSuite with Checkers { import Test._ …
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Expressing a property in ScalaCheck that does not have evaluations discarded

Given this: property("Empty range") { forAll { (min: Int, max: Int) => whenever (min == max) { Range(min, max).size should be (0) } } } I get [info] - Empty range *** FAILED *** [info] Gave up after 5 successful…
egbokul
  • 3,944
  • 7
  • 36
  • 54
0
votes
1 answer

High-order Scalacheck property

I'm new into Scala, Scalacheck and specs2 so bear with me if maybe question is kind of obvious. I tried to look an example of this but couldnt find anything related. Basically I'm looking for a way to create a test class using specs2 to define a…
mtelloz
  • 5
  • 3
0
votes
1 answer

Generating Strings which can be encoded by a specific Charset in ScalaCheck

In my ScalaTest test I need strings which can be encoded in US-ASCII. I tried checking if a string can be encoded in that charset after generating it with the default generator for Strings: forAll { str: String => …
Vladimir Korenev
  • 1,124
  • 1
  • 9
  • 27
0
votes
0 answers

Which properties can I test here?

Given a function like: def f(x: BigDecimal, high: BigDecimal, highest: BigDecimal, thresh: BigDecimal): BigDecimal = { val lowMultiplier = BigDecimal(0.2) val highMultiplier = BigDecimal(0.4) val highestMultiplier = BigDecimal(0.45) if (x >…
dmz73
  • 1,588
  • 4
  • 20
  • 32
0
votes
2 answers

Can not run scalacheck

I am doing the Principles of Reactive Programming course from Coursera. In one of the assignments I need to use a scalacheck class. I have the following test class open in Intellij: package quickcheck import org.scalatest.FunSuite import…
bsky
  • 19,326
  • 49
  • 155
  • 270
0
votes
1 answer

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

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…
user2230605
  • 2,390
  • 6
  • 27
  • 45
0
votes
2 answers

Scalacheck: generate list of numbers with total less than a certain value

I need to generate a random list of numbers of a given size whose total is less than a given fixed threshold using ScalaCheck. In other words, do something like: val threshold = 3000 val listGenerator = Gen.listOfN(2000, Gen.choose(1,2000))…
jjst
  • 2,631
  • 2
  • 22
  • 34