-
Notifications
You must be signed in to change notification settings - Fork 31
Add Max and Min functions with properties tests #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leozou2004
wants to merge
9
commits into
utgheith:main
Choose a base branch
from
leozou2004:add-max-properties-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aff4dbb
Add Max and Min functions with properties tests
leozou2004 e0320cf
Updated test case
leozou2004 2590d34
Added proof for min max properties
leozou2004 d78da5c
Rename MaxMin.dfy to max_min_properties.dfy for consistency
leozou2004 4abb827
Apply suggestions from code review
myf07 f078da5
Merge branch 'utgheith:main' into add-max-properties-test
leozou2004 0673078
Merge branch 'utgheith:main' into add-max-properties-test
leozou2004 5ef9ef8
Added a bit of complexity so the proof doesn't directly pass
leozou2004 c8ef9c7
change proof file to correspond with the test file
leozou2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| lemma {:induction false} MaxMin_Bounds(a: int, b: int) | ||
| ensures Max(a, b) >= a | ||
| ensures Max(a, b) >= b | ||
| ensures Min(a, b) <= a | ||
| ensures Min(a, b) <= b | ||
| ensures Max(a, b) == a || Max(a, b) == b | ||
| ensures Min(a, b) == a || Min(a, b) == b | ||
| { | ||
| } | ||
|
|
||
| lemma {:induction false} MaxMin_Symmetry(a: int, b: int) | ||
| ensures Max(a, b) == Max(b, a) | ||
| ensures Min(a, b) == Min(b, a) | ||
| ensures Max(a, a) == a | ||
| ensures Min(a, a) == a | ||
| { | ||
| } | ||
|
|
||
| lemma {:induction false} MaxMin_Relation(a: int, b: int) | ||
| ensures a <= b ==> Max(a, b) == b && Min(a, b) == a | ||
| ensures b <= a ==> Max(a, b) == a && Min(a, b) == b | ||
| { | ||
| } | ||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| function {:induction false} Max(a: int, b: int): int | ||
| { | ||
| if a >= b then a else b | ||
| } | ||
|
|
||
| function {:induction false} Min(a: int, b: int): int | ||
| { | ||
| if a <= b then a else b | ||
| } | ||
|
|
||
| // Test 1: bounds + “returns one of the arguments”. | ||
| method {:induction false} Test_MaxMin_Bounds(a: int, b: int) | ||
| { | ||
| assert | ||
| Max(a, b) >= a && | ||
| Max(a, b) >= b && | ||
| Min(a, b) <= a && | ||
| Min(a, b) <= b && | ||
| (Max(a, b) == a || Max(a, b) == b) && | ||
| (Min(a, b) == a || Min(a, b) == b) | ||
| by | ||
| { | ||
| MaxMin_Bounds(a, b); | ||
myf07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| // Test 2: commutativity + idempotence. | ||
| method {:induction false} Test_MaxMin_Symmetry(a: int, b: int) | ||
| { | ||
| assert | ||
| Max(a, b) == Max(b, a) && | ||
| Min(a, b) == Min(b, a) && | ||
| Max(a, a) == a && | ||
| Min(a, a) == a | ||
| by | ||
| { | ||
| MaxMin_Symmetry(a, b); | ||
myf07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| // Test 3: case-wise behavior (ordering). | ||
| method {:induction false} Test_MaxMin_Relation(a: int, b: int) | ||
| { | ||
| if a <= b { | ||
| assert Max(a, b) == b && Min(a, b) == a | ||
| by | ||
| { | ||
| MaxMin_Relation(a, b); | ||
| } | ||
| } else { | ||
| assert Max(a, b) == a && Min(a, b) == b | ||
| by | ||
| { | ||
| MaxMin_Relation(a, b); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, this proof stub directly passes and trivially proves the test case. I think the test case needs to include more things so that the proof would actually require code in the body of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think i have fixed this now.