Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
816f5e34
Commit
816f5e34
authored
9 years ago
by
Regis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
banking testcases
parent
d12b44a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
testcases/verification/xlang/BankSimpleTransactions.scala
+73
-0
73 additions, 0 deletions
testcases/verification/xlang/BankSimpleTransactions.scala
testcases/verification/xlang/BankTransfer.scala
+25
-58
25 additions, 58 deletions
testcases/verification/xlang/BankTransfer.scala
with
98 additions
and
58 deletions
testcases/verification/xlang/BankSimpleTransactions.scala
0 → 100644
+
73
−
0
View file @
816f5e34
import
leon.lang._
object
BankSimpleTransactions
{
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
)
}
def
internalTransfer
()
:
Unit
=
{
var
checking
:
BigInt
=
0
var
saving
:
BigInt
=
0
def
balance
=
checking
+
saving
def
balanceInvariant
:
Boolean
=
balance
>=
0
def
deposit
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
)
checking
+=
x
}
ensuring
(
_
=>
checking
==
old
(
checking
)
+
x
&&
balanceInvariant
)
def
withdrawal
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
&&
x
<=
checking
)
checking
-=
x
}
ensuring
(
_
=>
checking
==
old
(
checking
)
-
x
&&
balanceInvariant
)
def
checkingToSaving
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
&&
checking
>=
x
)
checking
-=
x
saving
+=
x
}
ensuring
(
_
=>
checking
+
saving
==
old
(
checking
)
+
old
(
saving
)
&&
balanceInvariant
)
deposit
(
50
)
withdrawal
(
30
)
checkingToSaving
(
10
)
}
}
This diff is collapsed.
Click to expand it.
testcases/verification/xlang/BankTransfer.scala
+
25
−
58
View file @
816f5e34
...
@@ -2,72 +2,39 @@ import leon.lang._
...
@@ -2,72 +2,39 @@ import leon.lang._
object
BankTransfer
{
object
BankTransfer
{
def
okTransaction
()
:
Unit
=
{
case
class
BankAccount
(
var
checking
:
BigInt
,
var
saving
:
BigInt
)
{
var
balance
:
BigInt
=
0
require
(
checking
>=
0
&&
saving
>
=
0
)
def
balanceInvariant
:
Boolean
=
balance
>=
0
def
balance
:
BigInt
=
checking
+
saving
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
=
{
//TODO: support for map references to mutable items
var
balance
:
BigInt
=
0
//case class Bank(accounts: Map[BigInt, BankAccount])
def
balanceInvariant
:
Boolean
=
balance
>=
0
def
deposit
(
x
:
BigInt
)
:
Unit
=
{
def
deposit
(
x
:
BigInt
,
account
:
BankAccount
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
)
require
(
x
>
0
)
balance
+=
x
account
.
checking
=
account
.
checking
+
x
}
ensuring
(
_
=>
balance
==
old
(
balance
)
+
x
&&
balanceInvariant
)
}
ensuring
(
_
=>
account
.
balance
==
old
(
account
).
balance
+
x
)
def
withdrawal
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
&&
x
<=
balance
)
balance
-=
x
}
ensuring
(
_
=>
balance
==
old
(
balance
)
-
x
&&
balanceInvariant
)
deposit
(
35
)
withdrawal
(
40
)
}
def
withdrawal
(
x
:
BigInt
,
account
:
BankAccount
)
:
Unit
=
{
require
(
x
>
0
&&
account
.
checking
>=
x
)
account
.
checking
=
account
.
checking
-
x
}
ensuring
(
_
=>
account
.
balance
==
old
(
account
).
balance
-
x
)
def
internalTransfer
()
:
Unit
=
{
def
transfer
(
x
:
BigInt
,
a1
:
BankAccount
,
a2
:
BankAccount
)
:
Unit
=
{
var
checking
:
BigInt
=
0
require
(
x
>
0
&&
a1
.
checking
>=
x
)
var
saving
:
BigInt
=
0
withdrawal
(
x
,
a1
)
deposit
(
x
,
a2
)
}
ensuring
(
_
=>
a1
.
balance
+
a2
.
balance
==
old
(
a1
).
balance
+
old
(
a2
).
balance
&&
a1
.
balance
==
old
(
a1
).
balance
-
x
&&
a2
.
balance
==
old
(
a2
).
balance
+
x
)
def
balance
=
checking
+
saving
def
balanceInvariant
:
Boolean
=
balance
>=
0
def
save
(
x
:
BigInt
,
account
:
BankAccount
)
:
Unit
=
{
require
(
x
>
0
&&
account
.
checking
>=
x
)
def
deposit
(
x
:
BigInt
)
:
Unit
=
{
account
.
checking
=
account
.
checking
-
x
require
(
balanceInvariant
&&
x
>=
0
)
account
.
saving
=
account
.
saving
+
x
checking
+=
x
}
ensuring
(
_
=>
account
.
balance
==
old
(
account
).
balance
)
}
ensuring
(
_
=>
checking
==
old
(
checking
)
+
x
&&
balanceInvariant
)
def
withdrawal
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
&&
x
<=
checking
)
checking
-=
x
}
ensuring
(
_
=>
checking
==
old
(
checking
)
-
x
&&
balanceInvariant
)
def
checkingToSaving
(
x
:
BigInt
)
:
Unit
=
{
require
(
balanceInvariant
&&
x
>=
0
&&
checking
>=
x
)
checking
-=
x
saving
+=
x
}
ensuring
(
_
=>
checking
+
saving
==
old
(
checking
)
+
old
(
saving
)
&&
balanceInvariant
)
deposit
(
50
)
withdrawal
(
30
)
checkingToSaving
(
10
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment