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
6
votes
2 answers

How to get ScalaTest correctly reporting tests results when using scalacheck with Propspec and PropertyCheck?

I'd like to test my scala program using property based testing with scalacheck. I wrote : class MyProperties extends PropSpec with PropertyChecks { property("My property") { val myProperty: org.scalacheck.Prop = new MyProperty //…
ygu
  • 345
  • 1
  • 16
5
votes
1 answer

Help with ScalaCheck

I'd like to use ScalaTest's Checkers trait to use ScalaCheck from ScalaTest cases. A simple case I'm playing with is: test("can create local date UTC from millis") { check(localDate.toTimestampUTC.toLocalDateUTC == localDate) } I need to…
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150
5
votes
1 answer

Sharing elements between generated objects in ScalaCheck using nested forAll

Started coding in Scala fairly recently and I tried to write some property based test-cases. Here, I am trying to generate raw data which mimics the system I am testing. The goal is to first generate base elements (ctrl and idz), then use those…
Ic3fr0g
  • 1,199
  • 15
  • 26
5
votes
1 answer

ScalaCheck: generate arbitrary functions with arbitrary types

I have implemented the following function: /** * Returns a function h , which is the composition of the functions f and g. */ def compose[A, B, C](g: B => C, f: A => B): A => C = f.andThen(g) And I'm trying to test it with ScalaCheck. I could…
5
votes
4 answers

Generating arbitrary (legal) Unicode character with scalacheck?

I'm trying to create a generator that produces (non-zero-length) legal unicode strings, with scalacheck 1.6.6 and specs 1.7 (scala 2.8.1). I hoped I could just create generators like: object Generators { def unicodeChar: Gen[Char] = …
5
votes
2 answers

Understanding ScalaChecks' 'generation size'

ScalaCheck's Gen API docs explain lazy val sized: def sized[T](f: (Int) ⇒ Gen[T]): Gen[T] Creates a generator that can access its generation size Looking at the following example: import org.scalacheck.Gen.{sized, posNum} scala> sized( s => {…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
5
votes
3 answers

ScalaCheck specificy minimum successful tests for property

I'm trying to make sure that my ScalaCheck property runs 500 times instead of the default 100 times. I'm having trouble configuring this though. class BlockSpec extends Properties("BlockSpec") with BitcoinSLogger { val myParams =…
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60
5
votes
4 answers

Scalacheck number generator between 0 <= x < 2^64

I'm trying to right a good number generator that covers uint64_t in C. Here is what I have so far. def uInt64s : Gen[BigInt] = Gen.choose(0,64).map(pow2(_) - 1) It is a good start, but it only generates numbers 2^n - 1. Is there a more effective…
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60
5
votes
1 answer

Test valid state transitions with scalacheck

Suppose I have this class: case class Receipt(id: Long, state: String) { def transitionTo(newState: String) = { if (!canTransitionTo(newState)) { throw new IllegalStateExcetion(s"cant transition from $state to $newState") } …
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
5
votes
2 answers

Scalacheck, generator for lists between size 5 and 12

I can find many examples of setting maximum sizes for generators, but how do I generate lists between a min and max length?
Felix
  • 8,385
  • 10
  • 40
  • 59
5
votes
1 answer

Type constraint for higher-kinded type in Scala

I am trying to write a generic law for Functors in scala, in a format that I could reuse for many functors in scalacheck tests. The law should be parameterized by the constructor F[_] and by the type of elements, say A. Ideally I would write…
5
votes
1 answer

How to specify number of checks to the forAll method in property checks

The forAll method takes generator(s) and performs number of checks of them. 100 checks by generator passed by default. Number of runs multiplied and you may quickly get too large if you use multiple generators. I'd like to sort generators based on…
ayvango
  • 5,867
  • 3
  • 34
  • 73
5
votes
1 answer

Scalacheck is ignoring the provided generators

I'm trying to implement a simple property check but Scalacheck is ignoring my generators. What I'm doing wrong here? object AlgorithmTest extends Properties("Algorithm") { property("Test") = forAll (Gen.choose(0,10)) (n => n>=0 & n<10) } and this…
tonicebrian
  • 4,715
  • 5
  • 41
  • 65
4
votes
1 answer

defining a simple implicit Arbitary

I have a type Foo with a constructor that takes an Int. How do I define an implicit Arbitrary for Foo to be used with scalacheck? implicit def arbFoo: Arbitrary[Foo] = ??? I came up with the following solution, but it's a bit too "manual" and…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
4
votes
0 answers

Generator Ordering Causing Infinite Recursion in For Comprehension in Scala

In the following codes, the change in ordering of generators in for-comprehension is causing an infinite recursion. The following code gives infinite recursion lazy val genHeap: Gen[H] = oneOf(const(empty), for { heap <- genHeap value <-…
1 2
3
18 19