Skip to content
Snippets Groups Projects
Commit 5984b82c authored by Regis Blanc's avatar Regis Blanc
Browse files

bank transfer example with variables

parent a372b9c1
No related branches found
No related tags found
No related merge requests found
import leon.lang._
object BankTransfer {
def okTransaction(): Unit = {
var balance: BigInt = 0
def balanceInvariant: Boolean = balance >= 0
def deposit(x: BigInt): Unit = {
require(balanceInvariant && x >= 0)
balance += x
} ensuring(_ => balance == old(balance) + x && balanceInvariant)
def withdrawal(x: BigInt): Unit = {
require(balanceInvariant && x >= 0 && x <= balance)
balance -= x
} ensuring(_ => balance == old(balance) - x && balanceInvariant)
deposit(35)
withdrawal(30)
}
def invalidTransaction(): Unit = {
var balance: BigInt = 0
def balanceInvariant: Boolean = balance >= 0
def deposit(x: BigInt): Unit = {
require(balanceInvariant && x >= 0)
balance += x
} ensuring(_ => balance == old(balance) + x && balanceInvariant)
def withdrawal(x: BigInt): Unit = {
require(balanceInvariant && x >= 0 && x <= balance)
balance -= x
} ensuring(_ => balance == old(balance) - x && balanceInvariant)
deposit(35)
withdrawal(40)
}
}
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