Skip to content
Permalink
Browse files

Upgrades scalacheck and scalatest libraries

  • Loading branch information
fedefernandez committed Dec 2, 2016
1 parent e087eb7 commit 2c0fd186bcc7274c9daba57d76ebf80d9c786e74
@@ -11,11 +11,11 @@ lazy val scalacheck = (project in file("."))
Resolver.sonatypeRepo("releases")
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.2.4",
"org.scala-exercises" %% "exercise-compiler" % version.value,
"org.scala-exercises" %% "definitions" % version.value,
"org.scalacheck" %% "scalacheck" % "1.12.5",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.12" % "0.3.1",
"org.scalatest" %% "scalatest" % "3.0.1" exclude("org.scalacheck", "scalacheck"),
"org.scala-exercises" %% "exercise-compiler" % version.value excludeAll ExclusionRule("com.github.alexarchambault"),
"org.scala-exercises" %% "definitions" % version.value excludeAll ExclusionRule("com.github.alexarchambault"),
"com.fortysevendeg" %% "scalacheck-datetime" % "0.2.0",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.13" % "1.1.3",
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.0")
)
)
@@ -185,7 +185,7 @@ object PropertiesSection extends Checkers with Matchers with org.scalaexercises.
*
*/
def groupingProperties(res0: Int, res1: Int, res2: Int) = {
import org.scalacheck.Properties
import org.scalacheck.{Prop, Properties}

class ZeroSpecification extends Properties("Zero") {

@@ -199,6 +199,6 @@ object PropertiesSection extends Checkers with Matchers with org.scalaexercises.

}

check(new ZeroSpecification)
check(Prop.all(new ZeroSpecification().properties.map(_._2): _*))
}
}
@@ -1,14 +1,13 @@
package scalachecklib

import org.scalacheck.Shapeless._
import org.scalaexercises.Test
import org.scalatest.Spec
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class ArbitrarySpec extends Spec with Checkers {
class ArbitrarySpec extends FunSuite with Checkers {

def `implicit arbitrary char` = {
test("implicit arbitrary char") {

check(
Test.testSuccess(
@@ -18,7 +17,7 @@ class ArbitrarySpec extends Spec with Checkers {
)
}

def `implicit arbitrary case class` = {
test("implicit arbitrary case class") {

check(
Test.testSuccess(
@@ -28,7 +27,7 @@ class ArbitrarySpec extends Spec with Checkers {
)
}

def `arbitrary on gen` = {
test("arbitrary on gen") {

check(
Test.testSuccess(
@@ -1,14 +1,13 @@
package scalachecklib

import org.scalacheck.Shapeless._
import org.scalaexercises.Test
import org.scalatest.Spec
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class GeneratorsSpec extends Spec with Checkers {
class GeneratorsSpec extends FunSuite with Checkers {

def `for-comprehension generator` = {
test("for-comprehension generator") {

check(
Test.testSuccess(
@@ -19,7 +18,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `oneOf method` = {
test("oneOf method") {

check(
Test.testSuccess(
@@ -30,7 +29,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `alphaChar, posNum and listOfN` = {
test("alphaChar, posNum and listOfN") {

check(
Test.testSuccess(
@@ -41,7 +40,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `suchThat condition` = {
test("suchThat condition") {

check(
Test.testSuccess(
@@ -52,7 +51,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `case class generator` = {
test("case class generator") {

check(
Test.testSuccess(
@@ -63,7 +62,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `sized generator` = {
test("sized generator") {

check(
Test.testSuccess(
@@ -74,7 +73,7 @@ class GeneratorsSpec extends Spec with Checkers {

}

def `list container` = {
test("list container") {

check(
Test.testSuccess(
@@ -1,15 +1,13 @@
package scalachecklib

import org.scalacheck.Shapeless._
import org.scalaexercises.Test
import org.scalatest.Spec
import org.scalatest.FunSuite
import org.scalatest.prop.Checkers
import shapeless.HNil

class PropertiesSpec extends FunSuite with Checkers {

class PropertiesSpec extends Spec with Checkers {

def `always ends with the second string` = {
test("always ends with the second string") {

check(
Test.testSuccess(
@@ -19,7 +17,7 @@ class PropertiesSpec extends Spec with Checkers {
)
}

def `all numbers are generated between the desired interval` = {
test("all numbers are generated between the desired interval") {

check(
Test.testSuccess(
@@ -29,7 +27,7 @@ class PropertiesSpec extends Spec with Checkers {
)
}

def `all generated numbers are even` = {
test("all generated numbers are even") {

check(
Test.testSuccess(
@@ -39,7 +37,7 @@ class PropertiesSpec extends Spec with Checkers {
)
}

def `only the second condition is true` = {
test("only the second condition is true") {

check(
Test.testSuccess(
@@ -49,7 +47,7 @@ class PropertiesSpec extends Spec with Checkers {
)
}

def `the zero specification only works for 0` = {
test("the zero specification only works for 0") {

check(
Test.testSuccess(
@@ -0,0 +1,53 @@
package scalachecklib

import shapeless._
import shapeless.ops.function._

import cats.implicits._
import org.scalacheck.{ Prop, Arbitrary }
import org.scalacheck.Gen
import Prop.forAll

import org.scalatest.exceptions._

import org.scalacheck.Shapeless._

object Test {

def testSuccess[F, R, L <: HList](method: F, answer: L)(
implicit
A: Arbitrary[L],
fntop: FnToProduct.Aux[F, L R]
): Prop = {
val rightGen = genRightAnswer(answer)
val rightProp = forAll(rightGen)({ p

val result = Either.catchOnly[GeneratorDrivenPropertyCheckFailedException]({ fntop(method)(p) })
result match {
case Left(exc) exc.cause match {
case Some(originalException) throw originalException
case _ false
}
case _ true
}
})

val wrongGen = genWrongAnswer(answer)
val wrongProp = forAll(wrongGen)({ p
Either.catchNonFatal({ fntop(method)(p) }).isLeft
})

Prop.all(rightProp, wrongProp)
}

def genRightAnswer[L <: HList](answer: L): Gen[L] = {
Gen.const(answer)
}

def genWrongAnswer[L <: HList](l: L)(
implicit
A: Arbitrary[L]
): Gen[L] = {
A.arbitrary.suchThat(_ != l)
}
}

0 comments on commit 2c0fd18

Please sign in to comment.
You can’t perform that action at this time.