Skip to content
Snippets Groups Projects
Commit cd8784ac authored by Philippe Suter's avatar Philippe Suter
Browse files

one more example, and Specs.forAll does not provoke a crash at runtime anymore...

one more example, and Specs.forAll does not provoke a crash at runtime anymore (a warning instead that its body has not been replaced by the plugin)

parent 8a5336b2
Branches
Tags
No related merge requests found
package contracts.insertionsort
import scala.collection.immutable.Set
object InsertionSort {
import funcheck.lib.Specs
assert(
Specs.forAll(
(l: List[Int]) => { content(sorted(l)) equals content(l) }
)
)
def content(l: List[Int]): Set[Int] = l match {
case Nil => Set.empty
case x :: xs => content(xs) + x
}
def sortedIns(e: Int, l: List[Int]): List[Int] = l match {
case Nil => e :: Nil
case x :: xs if (x < e) => x :: sortedIns(e, xs)
case _ => e :: l
}
def sorted(l: List[Int]): List[Int] = l match {
case Nil => Nil
case x :: xs => sortedIns(x, sorted(xs))
}
def main(args: Array[String]): Unit = {
val ls: List[Int] = List(5, 2, 4, 5, 1, 8)
println(ls)
println(sorted(ls))
}
}
...@@ -14,12 +14,17 @@ object Specs { ...@@ -14,12 +14,17 @@ object Specs {
def ==>(p: Boolean) = Specs ==> (b,p) def ==>(p: Boolean) = Specs ==> (b,p)
} }
def forAll[A](f: A => Boolean): Boolean = def forAll[A](f: A => Boolean): Boolean = {
error("\"forAll\" combinator is currently unsupported by plugin.") Console.err.println("Warning: ignored forAll. Are you using the funcheck plugin?")
true
// error("\"forAll\" combinator is currently unsupported by plugin.")
}
/** Implication */ /** Implication */
def ==>(ifz: => Boolean, then: Boolean): Boolean = def ==>(ifz: => Boolean, then: Boolean): Boolean = {
error("\"==>\" (implication) combinator is currently unsupported by plugin.") Console.err.println("Warning: ignored implication. Are you using the funcheck plugin?")
true
//error("\"==>\" (implication) combinator is currently unsupported by plugin.")
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment