Skip to content

Commit 54d943d

Browse files
Test for the cproverNondetInitialize feature
1 parent a1acecb commit 54d943d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
896 Bytes
Binary file not shown.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import org.cprover.CProver;
2+
3+
class Test {
4+
int size;
5+
int[] data1;
6+
int[] data2;
7+
8+
void cproverNondetInitialize() {
9+
// This specifies invariants about object of this class.
10+
// This avoids finding spurious bugs.
11+
CProver.assume(data1 != null && data2 != null && size == data1.length + data2.length);
12+
}
13+
14+
int check(int x) {
15+
int i;
16+
if(x >= size || x < 0)
17+
return -1;
18+
19+
assert(data1 != null || data2 == null);
20+
21+
if (x >= data1.length) {
22+
i = x - data1.length;
23+
assert(i < data2.length);
24+
return data2[i];
25+
} else {
26+
assert(x < data1.length);
27+
return data1[x];
28+
}
29+
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
Test.class
3+
--function Test.check
4+
^VERIFICATION SUCCESSFUL$
5+
--

0 commit comments

Comments
 (0)