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
10
votes
1 answer

Difference between ScalaCheck Arbitrary[T] and Scalacheck Gen[T]

In my tests I am making quite an extensive usage of Specs2 + ScalaCheck and there are some patterns to factor out. I still haven't found out if my functions should use an Arbitrary[T] or a Gen[T], since they are very similar: sealed abstract class…
Edmondo
  • 19,559
  • 13
  • 62
  • 115
9
votes
4 answers

Scalacheck: Generate list corresponding to list of generators

I want to generate a list of integers corresponding to a list of generators in ScalaCheck. import org.scalacheck._ import Arbitrary.arbitrary val smallInt = Gen.choose(0,10) val bigInt = Gen.choose(1000, 1000000) val…
dips
  • 1,627
  • 14
  • 25
8
votes
3 answers

How can I test Java programs with ScalaCheck?

I have read in the ScalaCheck user guide that it's a tool for testing Scala and Java programs. I wonder, is it just marketing, or testing Java-only codebase with it would be a reasonable idea? And if so, what's the best way to integrate it with the…
siledh
  • 3,268
  • 2
  • 16
  • 29
7
votes
1 answer

ScalaCheck - Ordered array generator

I am trying out ScalaCheck for the first time and I want to generate an ordered array of Ints. I read the documentation and did some search but I didn't find a way to do it. Can someone shed some light on this? Thanks
rmorais
  • 229
  • 1
  • 5
7
votes
2 answers

How to display entire stack trace for thrown exceptions from ScalaCheck tests?

I'm running ScalaCheck tests in sbt, and if my test fails because the code under test throws an exception, the test report shows the failed test, the thrown exception and the message, but not the entire stack trace (note the mere Exception:…
Martijn
  • 11,964
  • 12
  • 50
  • 96
7
votes
1 answer

Why does sbt give "object scalacheck is not a member of package org" after successful scalacheck resolve?

I have added the following in build.sbt: libraryDependencies <<= scalaVersion { scala_version => Seq( "org.scalacheck" %% "scalacheck" % "1.10.0" % "test", ) } Upon compile the project in sbt, the dependencies…
dips
  • 1,627
  • 14
  • 25
6
votes
2 answers

Is ScalaCheck's Gen.pick really random?

I observed the following unexpected behaviour when using ScalaCheck's Gen.pic, which (for me) indicates that its picking is not quite random, even though its documentation says so: /** A generator that picks a given number of elements from a list,…
bugfoot
  • 667
  • 7
  • 20
6
votes
1 answer

Scalacheck Shrink

I am fairly new to ScalaCheck (and Scala entirely) so this may be a fairly simple solution I am using ScalaCheck to generate tests for an AST and verifying that the writer/parser work. I have these files AST.scala package com.test object Operator…
Chase Walden
  • 1,252
  • 1
  • 14
  • 31
6
votes
0 answers

Is it possible to automatically derive a sealed trait family/ADT?

I have a method that is able to persist any type, as long as that type has a io.circe.Encoder[A] instance, something like this: def persist[A](a: A)(implicit ea: Encoder[A]): Boolean Now while testing this, I can create any old case class, or set…
Noel M
  • 15,812
  • 8
  • 39
  • 47
6
votes
0 answers

diverging implicit expansion

Can someone please explain to me why I get a 'diverging implicit expansion error' here? I think it has to do with the type synonym type MyIdType = String but I am not sure why. import org.scalacheck.Arbitrary import…
dmz73
  • 1,588
  • 4
  • 20
  • 32
6
votes
2 answers

ScalaCheck: choose an integer with custom probability distribution

I want to create a generator in ScalaCheck that generates numbers between say 1 and 100, but with a bell-like bias towards numbers closer to 1. Gen.choose() distributes numbers randomly between the min and max value: scala> (1 to 10).flatMap(_ =>…
jjst
  • 2,631
  • 2
  • 22
  • 34
6
votes
1 answer

PlayFramework + ScalaTest + ScalaCheck

I'm using the frameworks mentioned in the title with the following configuration: "com.typesafe.play" % "sbt-plugin" % "2.4.2" "org.scalacheck" %% "scalacheck" % "1.12.4" % "test" "org.scalatest" %% "scalatest" % "2.2.5" %…
Taig
  • 6,718
  • 4
  • 44
  • 65
6
votes
1 answer

Generate Strings from Grammar in ScalaCheck

In Scala, I have a grammar implemented using the Parser Combinators library. Now, what I want to do is generate random strings given a grammar from the parser combinators library. It seems to me, that what the ScalaCheck library does it somehow the…
Felix
  • 8,385
  • 10
  • 40
  • 59
6
votes
1 answer

How can I reduce the number of test cases ScalaCheck generates?

I'm trying to solve two ScalaCheck (+ specs2) problems: Is there any way to change the number of cases that ScalaCheck generates? How can I generate strings that contain some Unicode characters? For example, I'd like to generate about 10 random…
Zaphod
  • 1,387
  • 2
  • 17
  • 33
6
votes
3 answers

Reproducing a ScalaCheck test run

This was asked as a "bonus question" in https://stackoverflow.com/questions/12639454/make-scalacheck-tests-deterministic, but not answered: Is there a way to print out the random seed used by ScalaCheck, so that you can reproduce a specific test…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
1
2
3
18 19