Skip to content
Snippets Groups Projects
Commit 472c4e2c authored by Samuel Gruetter's avatar Samuel Gruetter
Browse files

add termination evidence to MergeSort testcase

parent f5feca73
No related branches found
No related tags found
No related merge requests found
......@@ -83,13 +83,18 @@ object MergeSort {
}
// Not really quicksort, neither mergesort.
def weirdSort(in : List) : List = (in match {
case Nil() => Nil()
case Cons(x, Nil()) => Cons(x, Nil())
case _ =>
val (s1,s2) = split(in)
mergeFast(weirdSort(s1), weirdSort(s2))
}) ensuring(res => sortSpec(in, res))
// Note: the `s` argument is just a witness for termination (always decreases),
// and not needed for functionality. Any decent optimizer will remove it ;-)
def weirdSort(s: BigInt, in : List) : List = {
require(s == size(in))
in match {
case Nil() => Nil()
case Cons(x, Nil()) => Cons(x, Nil())
case _ =>
val (s1,s2) = split(in)
mergeFast(weirdSort(size(s1), s1), weirdSort(size(s2), s2))
}
} ensuring(res => sortSpec(in, res))
def toLList(list : List) : LList = (list match {
case Nil() => LNil()
......
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