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

Add good synthesis testcases

parent 953ec315
Branches
Tags
No related merge requests found
...@@ -8,8 +8,8 @@ object Diff { ...@@ -8,8 +8,8 @@ object Diff {
case object Nil extends List case object Nil extends List
def size(l: List) : BigInt = (l match { def size(l: List) : BigInt = (l match {
case Nil => 0 case Nil => BigInt(0)
case Cons(_, t) => 1 + size(t) case Cons(_, t) => BigInt(1) + size(t)
}) ensuring(res => res >= 0) }) ensuring(res => res >= 0)
def content(l: List): Set[BigInt] = l match { def content(l: List): Set[BigInt] = l match {
...@@ -34,15 +34,6 @@ object Diff { ...@@ -34,15 +34,6 @@ object Diff {
} }
} ensuring { content(_) == content(in1) -- Set(v) } } ensuring { content(_) == content(in1) -- Set(v) }
def union(in1: List, in2: List): List = {
in1 match {
case Cons(h, t) =>
Cons(h, union(t, in2))
case Nil =>
in2
}
} ensuring { content(_) == content(in1) ++ content(in2) }
// def diff(in1: List, in2: List): List = { // def diff(in1: List, in2: List): List = {
// in2 match { // in2 match {
// case Nil => // case Nil =>
......
...@@ -8,8 +8,8 @@ object Insert { ...@@ -8,8 +8,8 @@ object Insert {
case object Nil extends List case object Nil extends List
def size(l: List) : BigInt = (l match { def size(l: List) : BigInt = (l match {
case Nil => 0 case Nil => BigInt(0)
case Cons(_, t) => 1 + size(t) case Cons(_, t) => BigInt(1) + size(t)
}) ensuring(res => res >= 0) }) ensuring(res => res >= 0)
def content(l: List): Set[BigInt] = l match { def content(l: List): Set[BigInt] = l match {
......
...@@ -10,8 +10,8 @@ object Complete { ...@@ -10,8 +10,8 @@ object Complete {
case object Nil extends List case object Nil extends List
def size(l: List) : BigInt = (l match { def size(l: List) : BigInt = (l match {
case Nil => 0 case Nil => BigInt(0)
case Cons(_, t) => 1 + size(t) case Cons(_, t) => BigInt(1) + size(t)
}) ensuring(res => res >= 0) }) ensuring(res => res >= 0)
def content(l: List): Set[BigInt] = l match { def content(l: List): Set[BigInt] = l match {
...@@ -19,63 +19,7 @@ object Complete { ...@@ -19,63 +19,7 @@ object Complete {
case Cons(i, t) => Set(i) ++ content(t) case Cons(i, t) => Set(i) ++ content(t)
} }
def insert(in1: List, v: BigInt): List = {
Cons(v, in1)
} ensuring { content(_) == content(in1) ++ Set(v) }
//def insert(in1: List, v: BigInt) = choose {
// (out : List) =>
// content(out) == content(in1) ++ Set(v)
//}
def delete(in1: List, v: BigInt): List = {
in1 match {
case Cons(h,t) =>
if (h == v) {
delete(t, v)
} else {
Cons(h, delete(t, v))
}
case Nil =>
Nil
}
} ensuring { content(_) == content(in1) -- Set(v) }
//def delete(in1: List, v: BigInt) = choose {
// (out : List) =>
// content(out) == content(in1) -- Set(v)
//}
def union(in1: List, in2: List): List = {
in1 match {
case Cons(h, t) =>
Cons(h, union(t, in2))
case Nil =>
in2
}
} ensuring { content(_) == content(in1) ++ content(in2) }
//def union(in1: List, in2: List) = choose {
// (out : List) =>
// content(out) == content(in1) ++ content(in2)
//}
def diff(in1: List, in2: List): List = {
in2 match {
case Nil =>
in1
case Cons(h, t) =>
diff(delete(in1, h), t)
}
} ensuring { content(_) == content(in1) -- content(in2) }
//def diff(in1: List, in2: List) = choose {
// (out : List) =>
// content(out) == content(in1) -- content(in2)
//}
def splitSpec(list : List, res : (List,List)) : Boolean = { def splitSpec(list : List, res : (List,List)) : Boolean = {
val s1 = size(res._1) val s1 = size(res._1)
val s2 = size(res._2) val s2 = size(res._2)
abs(s1 - s2) <= 1 && s1 + s2 == size(list) && abs(s1 - s2) <= 1 && s1 + s2 == size(list) &&
...@@ -86,16 +30,10 @@ object Complete { ...@@ -86,16 +30,10 @@ object Complete {
if(i < 0) -i else i if(i < 0) -i else i
} ensuring(_ >= 0) } ensuring(_ >= 0)
// def split(list : List) : (List,List) = (list match {
// case Nil => (Nil, Nil)
// case Cons(x, Nil) => (Cons(x, Nil), Nil)
// case Cons(x1, Cons(x2, xs)) =>
// val (s1,s2) = split(xs)
// (Cons(x1, s1), Cons(x2, s2))
// }) ensuring(res => splitSpec(list, res))
def split(list : List) : (List,List) = { def split(list : List) : (List,List) = {
choose { (res : (List,List)) => splitSpec(list, res) } choose { (res : (List,List)) => splitSpec(list, res) }
} }
// case (h1, (h2, t)) => (h1 :: split(t)._1, h2 :: split(t)._2)
} }
...@@ -8,8 +8,8 @@ object Union { ...@@ -8,8 +8,8 @@ object Union {
case object Nil extends List case object Nil extends List
def size(l: List) : BigInt = (l match { def size(l: List) : BigInt = (l match {
case Nil => 0 case Nil => BigInt(0)
case Cons(_, t) => 1 + size(t) case Cons(_, t) => BigInt(1)+ size(t)
}) ensuring(res => res >= 0) }) ensuring(res => res >= 0)
def content(l: List): Set[BigInt] = l match { def content(l: List): Set[BigInt] = l match {
...@@ -21,19 +21,6 @@ object Union { ...@@ -21,19 +21,6 @@ object Union {
Cons(v, in1) Cons(v, in1)
} ensuring { content(_) == content(in1) ++ Set(v) } } ensuring { content(_) == content(in1) ++ Set(v) }
def delete(in1: List, v: BigInt): List = {
in1 match {
case Cons(h,t) =>
if (h == v) {
delete(t, v)
} else {
Cons(h, delete(t, v))
}
case Nil =>
Nil
}
} ensuring { content(_) == content(in1) -- Set(v) }
// def union(in1: List, in2: List): List = { // def union(in1: List, in2: List): List = {
// in1 match { // in1 match {
// case Cons(h, t) => // case Cons(h, t) =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment