Skip to content

Commit a77f0cd

Browse files
fix arr_inc test
1 parent 80e8822 commit a77f0cd

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

tests/expected/loop-contract/array_icr_for_loop_fixme.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,46 @@
99
#![feature(proc_macro_hygiene)]
1010
#![feature(stmt_expr_attributes)]
1111

12-
#[kani::proof]
13-
#[kani::solver(z3)]
14-
fn array_inc() {
15-
let a: [u8; 60] = kani::any();
16-
kani::assume(kani::forall!(|i in (0,60)| a[i] <= u8::MAX));
17-
let mut b: [u8; 60] = a.clone();
12+
#[kani::requires(a.len() < 256)]
13+
#[kani::requires(kani::forall!(|i in (0, a.len())| a[i] < i32::MAX))]
14+
#[kani::ensures(kani::forall!(|i in (0, a.len())| a[i] = on_entry(a[i]) + 1))]
15+
fn array_inc(a: &mut [i32]) {
16+
let b: [u8; 60] = a.clone();
17+
#[kani::loop_invariant(i < 60
18+
&& kani::forall!(|j in (kani::index, 60)| b[j] == a[j])
19+
&& kani::forall!(|j in (0, kani::index)| a[j] == b[j] + 1)
20+
)]
21+
for i in 0..a.len() {
22+
a[i as usize] = a[i as usize] + 1;
23+
}
24+
}
25+
26+
#[kani::requires(a.len() < 256)]
27+
#[kani::requires(kani::forall!(|i in (0, a.len())| a[i] < i32::MAX))]
28+
#[kani::ensures(kani::forall!(|i in (0, a.len())| a[i] = on_entry(a[i]) + 1))]
29+
fn array_inc_iter_mut(a: &mut [i32]) {
30+
let b: [u8; 60] = a.clone();
1831
#[kani::loop_invariant(i < 60
1932
&& kani::forall!(|j in (kani::index, 60)| b[j] == a[j])
20-
&& kani::forall!(|j in (0, kani::index)| b[j] == a[j] + 1)
33+
&& kani::forall!(|j in (0, kani::index)| a[j] == b[j] + 1)
2134
)]
22-
for i in 0..60 {
23-
b[i as usize] = a[i as usize] + 1;
35+
for x in a.iter_mut() {
36+
*x = *x + 1;
2437
}
2538
}
39+
40+
#[kani::proof_for_contract(array_inc)]
41+
#[kani::solver(z3)]
42+
fn check_array_inc(a: &mut [i32]) {
43+
let a: [i32; 256] = kani::any();
44+
let slice = kani::slice::any_slice_of_array(&a);
45+
array_inc(slice);
46+
}
47+
48+
#[kani::proof_for_contract(array_inc_iter_mut)]
49+
#[kani::solver(z3)]
50+
fn check_array_inc_iter_mut(a: &mut [i32]) {
51+
let a: [i32; 256] = kani::any();
52+
let slice = kani::slice::any_slice_of_array(&a);
53+
array_inc_iter_mut(slice);
54+
}

0 commit comments

Comments
 (0)