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

Add some challenging tests

parent 20c33857
No related branches found
No related tags found
No related merge requests found
import leon.lang._
import leon.collection._
import leon.lang.synthesis._
object FirstIndexOf {
def firstIndexOf(l: List[Int], v: Int): Int = {
l match {
case Cons(h, t) if v == h => 0
case Cons(h, t) =>
if (firstIndexOf(t, v) >= 0) {
firstIndexOf(t, v)+1
} else {
-1
}
case Nil() =>
-1
}
} ensuring {
(res: Int) => (if (l.content contains v) {
l.size > res && l.apply(res) == v
} else {
res == -1
}) && (((l,v), res) passes {
case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => 3
case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => 3
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => 1
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => -1
})
}
}
import leon.lang._
import leon.collection._
import leon.lang.synthesis._
object FirstIndexOf {
def firstIndexOf(l: List[Int], v: Int): Int = {
l match {
case Cons(h, t) if v == h => 0
case Cons(h, t) =>
if (firstIndexOf(t, v) >= 0) {
firstIndexOf(t, v) // Should be +1 (Solves with CEGIS)
} else {
-1
}
case Nil() =>
-1
}
} ensuring {
(res: Int) => (if (l.content contains v) {
l.size > res && l.apply(res) == v
} else {
res == -1
}) && (((l,v), res) passes {
case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => 3
case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => 3
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => 1
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => -1
})
}
}
import leon.lang._
import leon.collection._
import leon.lang.synthesis._
object FirstIndexOf {
def firstIndexOf(l: List[Int], v: Int): Int = {
l match {
case Cons(h, t) if v == h => 0
case Cons(h, t) =>
if (firstIndexOf(t, v) >= 0) {
firstIndexOf(t, v)+2 // Should be +1
} else {
-1
}
case Nil() =>
-1
}
} ensuring {
(res: Int) => (if (l.content contains v) {
l.size > res && l.apply(res) == v
} else {
res == -1
}) && (((l,v), res) passes {
case (Cons(0, Cons(1, Cons(2, Cons(3, Nil())))), 3) => 3
case (Cons(0, Cons(2, Cons(3, Cons(1, Nil())))), 1) => 3
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 1) => 1
case (Cons(0, Cons(1, Cons(3, Cons(1, Nil())))), 2) => -1
})
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment