Skip to content

Instantly share code, notes, and snippets.

@parallelepiped
Created February 21, 2016 21:16
Show Gist options
  • Save parallelepiped/f50f08ab48e25fb4b5f1 to your computer and use it in GitHub Desktop.
Save parallelepiped/f50f08ab48e25fb4b5f1 to your computer and use it in GitHub Desktop.
package quickcheck
import common._
import org.scalacheck._
import Arbitrary._
import Gen._
import Prop._
abstract class QuickCheckHeap extends Properties("Heap") with IntHeap {
property("min1") = forAll { a: Int =>
val h = insert(a, empty)
findMin(h) == a
}
property("min of only 2 inserted elements") = forAll { (a: Int, b: Int) =>
val h = insert(a, insert(b, empty))
findMin(h) == (if (a < b) a else b)
}
property("delete the only element") = forAll { a: Int =>
val h: H = insert(a, empty)
isEmpty(deleteMin(h))
}
property("min of two heaps") = forAll { (h: H, g: H) =>
val a = findMin(h)
val b = findMin(g)
findMin(meld(h, g)) == (if (a < b) a else b)
}
property("continually delete from a heap") = forAll { h: H =>
def unpackHeap(heap: Heap, elems: List[Int]) : (Heap, List[Int]) = {
heap match {
case empty => elems
case _ =>
}
???
}
???
}
lazy val genHeap: Gen[H] = for {
l <- arbitrary[Int]
m <- oneOf(const(empty), genHeap)
} yield insert(l, m)
lazy val genMap: Gen[Map[Int,Int]] = for {
k <- arbitrary[Int]
v <- arbitrary[Int]
m <- oneOf(const(Map.empty[Int,Int]), genMap)
} yield m.updated(k, v)
implicit lazy val arbHeap: Arbitrary[H] = Arbitrary(genHeap)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment