Created
February 12, 2022 00:03
-
-
Save roboguy13/0797ce58ca051b52387bfb1c13cb2b89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Budget { | |
var days : array<int> | |
var weeks : array<int> | |
function valid() : bool | |
reads this, weeks, days | |
{ | |
days.Length == weeks.Length && | |
(forall i :: 0 <= i < days.Length ==> (weeks[i] == 7 * days[i])) | |
} | |
method adjustCOLA(cola : int) | |
modifies days, weeks | |
requires valid() | |
ensures valid() | |
{ | |
for i := 0 to days.Length | |
invariant valid() // NOTE: This is required to be explicit | |
{ | |
if (days[i] > 0) | |
{ | |
days[i] := days[i] * cola; | |
} | |
weeks[i] := 7*days[i]; // This would be synthesized from the data invariant | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment