Skip to content
Snippets Groups Projects
Commit 07731442 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Add some stuff

parent 27c20971
Branches
Tags
No related merge requests found
...@@ -54,7 +54,7 @@ object SortedTree { ...@@ -54,7 +54,7 @@ object SortedTree {
v < max && v < max &&
v > min v > min
case _ => true case _ => true
}) }) ensuring ( res => !res || (allGreaterThan(t, min) && allSmallerThan(t, max)))
def isSortedMin(t: Tree, min: Int): Boolean = (t match { def isSortedMin(t: Tree, min: Int): Boolean = (t match {
case Node(v, l, r) => case Node(v, l, r) =>
...@@ -62,7 +62,7 @@ object SortedTree { ...@@ -62,7 +62,7 @@ object SortedTree {
isSortedMin(r, v) && isSortedMin(r, v) &&
v > min v > min
case _ => true case _ => true
}) }) ensuring ( res => !res || allGreaterThan(t, min))
def isSortedMax(t: Tree, max: Int): Boolean = (t match { def isSortedMax(t: Tree, max: Int): Boolean = (t match {
case Node(v, l, r) => case Node(v, l, r) =>
...@@ -70,7 +70,7 @@ object SortedTree { ...@@ -70,7 +70,7 @@ object SortedTree {
isSortedMinMax(r, v, max) && isSortedMinMax(r, v, max) &&
v < max v < max
case _ => true case _ => true
}) }) ensuring ( res => !res || allSmallerThan(t, max))
def isSorted(t: Tree): Boolean = (t match { def isSorted(t: Tree): Boolean = (t match {
case Node(v, l, r) => case Node(v, l, r) =>
...@@ -79,8 +79,8 @@ object SortedTree { ...@@ -79,8 +79,8 @@ object SortedTree {
case _ => true case _ => true
}) ensuring ( res => !res || (t match { }) ensuring ( res => !res || (t match {
case Node(v, l, r) => case Node(v, l, r) =>
allSmallerThan(l, v) && isSorted(l) &&
allGreaterThan(r, v) isSorted(r)
case Leaf() => true case Leaf() => true
})) }))
...@@ -161,7 +161,7 @@ object SortedTree { ...@@ -161,7 +161,7 @@ object SortedTree {
(v == searchV) || (v == searchV) ||
contains1(l, searchV) || contains1(l, searchV) ||
contains1(r, searchV) contains1(r, searchV)
}) ensuring(res => !res || (content(t) contains searchV)) }) ensuring(_ == (content(t) contains searchV))
def contains2(t: Tree, searchV: Int): Boolean = { def contains2(t: Tree, searchV: Int): Boolean = {
require(isMostlySorted(t)) require(isMostlySorted(t))
...@@ -176,20 +176,20 @@ object SortedTree { ...@@ -176,20 +176,20 @@ object SortedTree {
} else { } else {
true true
} }
})} ensuring(res => !res || (content(t) contains searchV)) })} ensuring(_ == (content(t) contains searchV))
def containsBuggy(t: Tree, searchV: Int): Boolean = { def contains3(t: Tree, searchV: Int): Boolean = {
require(isMostlySorted(t)) require(isSorted(t))
(t match { (t match {
case Leaf() => false case Leaf() => false
case Node(v, l, r) => case Node(v, l, r) =>
if (searchV > v) { if (searchV > v) {
contains2(l, searchV) contains3(r, searchV)
} else if (searchV < v) { } else if (searchV < v) {
contains2(r, searchV) contains3(l, searchV)
} else { } else {
true true
} }
})} ensuring(res => !res || (content(t) contains searchV)) })} ensuring(_ == (content(t) contains searchV))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment