diff options
author | Rustan Leino <leino@microsoft.com> | 2012-01-10 16:19:10 -0800 |
---|---|---|
committer | Rustan Leino <leino@microsoft.com> | 2012-01-10 16:19:10 -0800 |
commit | 3be3e9a226ee0defb514da6fe136ce7cadf9e17c (patch) | |
tree | 40fefdd0b69ec16d46e54531be71aa33a7d3f5d2 /Test/dafny0/Refinement.dfy | |
parent | 17d1562bae394856c24f09a2dac9f7404c5dd759 (diff) |
Dafny: added test case for refinement and predicates (and fixed a parsing bug)
Diffstat (limited to 'Test/dafny0/Refinement.dfy')
-rw-r--r-- | Test/dafny0/Refinement.dfy | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Test/dafny0/Refinement.dfy b/Test/dafny0/Refinement.dfy index e46fba0d..fb379c33 100644 --- a/Test/dafny0/Refinement.dfy +++ b/Test/dafny0/Refinement.dfy @@ -31,3 +31,74 @@ module B refines A { // inherited method body } } + +// ------------------------------------------------ +/* SOON +module Abstract { + class MyNumber { + var N: int; + ghost var Repr: set<object>; + predicate Valid + reads this, Repr; + { + this in Repr && null !in Repr + } + constructor Init() + modifies this; + ensures N == 0; + ensures Valid && fresh(Repr - {this}); + { + N, Repr := 0, {this}; + } + method Inc() + requires Valid; + modifies Repr; + ensures N == old(N) + 1; + ensures Valid && fresh(Repr - old(Repr)); + { + N := N + 1; + } + method Get() returns (n: int) + requires Valid; + ensures n == N; + { + n := N; + } + } +} + +module Concrete refines Abstract { + class MyNumber { + var a: int; + var b: int; + predicate Valid + { + N == a - b + } + constructor Init() + { + a := b; + } + method Inc() + { + if (*) { a := a + 1; } else { b := b - 1; } + } + method Get() returns (n: int) + { + n := a - b; + } + } +} + +module Client imports Concrete { + class TheClient { + method Main() { + var n := new MyNumber.Init(); + n.Inc(); + n.Inc(); + var k := n.Get(); + assert k == 2; + } + } +} +*/ |