I have a very simple scenario: test that any pair of random strings of length 10 passed as parameters into a case class Pair(a custom one being under test) should be the same.
class ExercisesPropSpec extends PropSpec with Checkers with Matchers with Inside{
import Exercises._
lazy val genPairs = for {
left <- Gen.listOfN(10, Gen.alphaChar)
right <- Gen.listOfN(10, Gen.alphaChar)
} yield (left.mkString, right.mkString)
property("pattern match tuples of alphanumerics to our custom pair class"){
forAll(genPairs) {case (left: String, right: String) =>
val pair = Pair(left, right)
inside(pair) { case Pair(firstName, lastName) =>
firstName shouldEqual(left)
lastName shouldEqual(right)
}
}
}
}
However when I am running testOnly *ExercisesPropSpec
from sbt I get this compilation error:
Compiling 1 Scala source to /home/vgorcinschi/ideaProjects/Learning Concurrent Programming in Scala/chapter01_introduction/target/scala-2.12/test-classes ...
[error] ~/ideaProjects/Learning Concurrent Programming in Scala/chapter01_introduction/src/test/scala/org/learningconcurrency/ExercisesPropSpec.scala:18:28: No implicit view available from org.scalatest.Assertion => org.scalacheck.Prop.
[error] check(forAll(genPairs) {case (left: String, right: String) =>
[error] ^
A note in scalacheck-cookbook sais that
what the error message indicates is that our property check is not evaluating in terms of Boolean logic
I was hoping that the inside block in the end should be returning Boolean. I would be grateful if you could point out what am I missing from understanding of property based testing or using Inside trait in this implementation.