-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for loops, remove empty Conditional statements
- Loading branch information
Showing
5 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// compile-flags: -Pviper_backend=Lithium | ||
|
||
use prusti_contracts::*; | ||
|
||
const N: i32 = 10; | ||
|
||
#[requires(i <= N)] | ||
#[ensures(result == N)] | ||
fn wrong_invariant(i: i32) -> i32 { | ||
let mut ret = i; | ||
while ret < N { | ||
body_invariant!(ret == i); //~ ERROR loop invariant might not hold | ||
ret += 1; | ||
} | ||
ret | ||
} | ||
|
||
#[requires(i <= N)] | ||
#[ensures(result == N)] //~ ERROR might not hold | ||
fn weak_invariant(i: i32) -> i32 { | ||
let mut ret = i; | ||
while ret < N { | ||
body_invariant!(ret <= N); | ||
ret += 1; | ||
} | ||
ret | ||
} | ||
|
||
fn main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// compile-flags: -Pviper_backend=Lithium | ||
|
||
use prusti_contracts::*; | ||
|
||
const N: i32 = 10; | ||
|
||
#[requires(i <= N)] | ||
#[ensures(result == N)] | ||
fn test(i: i32) -> i32 { | ||
let mut ret = i; | ||
while ret < N { | ||
body_invariant!(ret < N); | ||
ret += 1; | ||
} | ||
ret | ||
} | ||
|
||
fn main() { | ||
assert!(test(3) == N); | ||
} |