Skip to content
Snippets Groups Projects
Commit 8dd505a5 authored by Mirco Dotta's avatar Mirco Dotta
Browse files

updated example used to explain the transformation performed by the FunCheck plugin.

parent 015ebd6b
No related branches found
No related tags found
No related merge requests found
...@@ -19,11 +19,11 @@ object BSTTest { ...@@ -19,11 +19,11 @@ object BSTTest {
} }
/** Properties */ /** Properties */
val treeContainsValue = forAll[(BST,Int)]( p => contains(p._2,p._1) == content(p._1).contains(p._2)) forAll[(BST,Int)]( p => contains(p._2,p._1) == content(p._1).contains(p._2))
/** Program */ /** Program */
@generator @generator
abstract class BST sealed abstract class BST
case class Node(left: BST, right: BST, v: Int) extends BST case class Node(left: BST, right: BST, v: Int) extends BST
case class Leaf() extends BST case class Leaf() extends BST
} }
...@@ -29,14 +29,15 @@ object BSTTest { ...@@ -29,14 +29,15 @@ object BSTTest {
/** Properties */ /** Properties */
// removed // removed
//val treeContainsValue = forAll[(BST,Int)]( p => contains(p._2,p._1) == content(p._1).contains(p._2)) // forAll[(BST,Int)]( p => contains(p._2,p._1) == content(p._1).contains(p._2))
// injected // injected
// replaced with ScalaCheck forAll // replaced with ScalaCheck forAll
val treeContainsValue = Prop.forAll( (tree:BST,v:Int) => contains(v,tree) == content(tree).contains(v))(b: Boolean => Prop.propBoolean(b), arbBST, Shrink.shrinkAny[BST], Arbitrary.arbInt, Shrink.shrinkInt) Console.Prop.forAll( (tree:BST,v:Int) => contains(v,tree) == content(tree).contains(v))(b: Boolean => Prop.propBoolean(b), arbBST, Shrink.shrinkAny[BST], Arbitrary.arbInt, Shrink.shrinkInt)
/** Program */ /** Program */
abstract class BST @generator
sealed abstract class BST
case class Node(left: BST, right: BST, v: Int) extends BST case class Node(left: BST, right: BST, v: Int) extends BST
case class Leaf() extends BST case class Leaf() extends BST
...@@ -47,13 +48,13 @@ object BSTTest { ...@@ -47,13 +48,13 @@ object BSTTest {
// Generators // Generators
def genBST: Gen[BST] = Gen.lzy(Gen.oneOf(genLeaf,genNode)) def genBST: Gen[BST] = Gen.lzy(Gen.oneOf(genLeaf,genNode))
val genNode: Gen[Node] = for { def genNode: Gen[Node] = Gen.lzy(for {
left <- genBST left <- genBST
right <- genBST right <- genBST
v <- Arbitrary.arbitrary[Int] v <- Arbitrary.arbitrary[Int]
} yield Node(left,right,v) } yield Node(left,right,v))
val genLeaf: Gen[Leaf] = Gen.value(Leaf()) def genLeaf: Gen[Leaf] = Gen.lzy(Gen.value(Leaf()))
// Arbitrary // Arbitrary
def arbBST: Arbitrary[BST] = Arbitrary(genBST) def arbBST: Arbitrary[BST] = Arbitrary(genBST)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment