Skip to content
Snippets Groups Projects
Commit 37bc9723 authored by Regis Blanc's avatar Regis Blanc Committed by Ravi
Browse files

io directory for tests

parent 45496c70
No related branches found
No related tags found
No related merge requests found
import leon.lang._
import leon.lang.xlang._
import leon.util.Random
object GuessNumber {
def pickRandomly(min: BigInt, max: BigInt): BigInt = {
require(min >= 0 && max >= min)
Random.nextBigInt(max - min + 1) + min
}
def main(): Unit = {
val choice = pickRandomly(0, 10)
var guess = pickRandomly(0, 10)
var top: BigInt = 10
var bot: BigInt = 0
(while(bot < top) {
if(isGreater(guess, choice)) {
top = guess-1
guess = pickRandomly(bot, top)
} else if(isSmaller(guess, choice)) {
bot = guess+1
guess = pickRandomly(bot, top)
}
}) invariant(guess >= bot && guess <= top && bot >= 0 && top <= 10 && bot <= top && choice >= bot && choice <= top)
val answer = bot
assert(answer == choice)
}
def isGreater(guess: BigInt, choice: BigInt): Boolean = guess > choice
def isSmaller(guess: BigInt, choice: BigInt): Boolean = guess < choice
}
...@@ -4,7 +4,7 @@ import leon.io.StdIn ...@@ -4,7 +4,7 @@ import leon.io.StdIn
import leon.annotation._ import leon.annotation._
object GuessNumberInteractive { object GuessNumber {
@extern @extern
def pickBetween(bot: BigInt, top: BigInt): BigInt = { def pickBetween(bot: BigInt, top: BigInt): BigInt = {
......
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