Skip to content
Snippets Groups Projects
Commit b584855c authored by Régis Blanc's avatar Régis Blanc Committed by Ravi
Browse files

update some outdated xlang testcases

parent b3868c82
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,10 @@ import leon.lang._ ...@@ -4,8 +4,10 @@ import leon.lang._
object MaxSum { object MaxSum {
def maxSum(a: Array[Int]): (Int, Int) = ({ //not valid because of Int, unfortunately conversion between big int and
require(a.length >= 0 && isPositive(a)) //int does not work and we cannot compute a.length * Max (Int * BigInt)
def maxSum(a: Array[Int]): (Int, Int) = {
require(a.length >= 0)
var sum = 0 var sum = 0
var max = 0 var max = 0
var i = 0 var i = 0
...@@ -16,46 +18,6 @@ object MaxSum { ...@@ -16,46 +18,6 @@ object MaxSum {
i = i + 1 i = i + 1
}) invariant (sum <= i * max && i >= 0 && i <= a.length) }) invariant (sum <= i * max && i >= 0 && i <= a.length)
(sum, max) (sum, max)
}) ensuring(res => res._1 <= a.length * res._2) } ensuring(res => res._1 <= a.length * res._2)
def isPositive(a: Array[Int]): Boolean = {
require(a.length >= 0)
def rec(i: Int): Boolean = {
require(i >= 0)
if(i >= a.length)
true
else {
if(a(i) < 0)
false
else
rec(i+1)
}
}
rec(0)
}
def summ(to : Int): Int = ({
require(to >= 0)
var i = 0
var s = 0
(while (i < to) {
s = s + i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == i*(i-1)/2 && i <= to)
s
}) ensuring(res => res >= 0 && res == to*(to-1)/2)
def sumsq(to : Int): Int = ({
require(to >= 0)
var i = 0
var s = 0
(while (i < to) {
s = s + i*i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == (i-1)*i*(2*i-1)/6 && i <= to)
s
}) ensuring(res => res >= 0 && res == (to-1)*to*(2*to-1)/6)
} }
import leon.lang._
object Sums {
def summ(to : BigInt): BigInt = ({
require(to >= 0)
var i: BigInt = 0
var s: BigInt = 0
(while (i < to) {
s = s + i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == i*(i-1)/2 && i <= to)
s
}) ensuring(res => res >= 0 && res == to*(to-1)/2)
def sumsq(to : BigInt): BigInt = ({
require(to >= 0)
var i: BigInt = 0
var s: BigInt = 0
(while (i < to) {
s = s + i*i
i = i + 1
}) invariant (s >= 0 && i >= 0 && s == (i-1)*i*(2*i-1)/6 && i <= to)
s
}) ensuring(res => res >= 0 && res == (to-1)*to*(2*to-1)/6)
}
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