Skip to content

Commit f3b4c9b

Browse files
Test for verification of the indexOf method
One of these is exhaustive and too slow to run so it is marked as THOROUGH and should be run every time axioms for the indexOf methods are touched.
1 parent 9a7fa2d commit f3b4c9b

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
1.15 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
public class Test {
2+
3+
public boolean check(String input_String, char input_char, int input_int) {
4+
// Verify indexOf is conform to its specification
5+
int i = input_String.indexOf(input_char, input_int);
6+
7+
assert i < input_String.length();
8+
9+
int lower_bound;
10+
if (input_int < 0)
11+
lower_bound = 0;
12+
else
13+
lower_bound = input_int;
14+
15+
if (i == -1) {
16+
for (int j = lower_bound; j < input_String.length(); j++)
17+
assert input_String.charAt(j) != input_char;
18+
} else {
19+
assert i >= lower_bound;
20+
assert input_String.charAt(i) == input_char;
21+
22+
for (int j = lower_bound; j < i; j++)
23+
assert input_String.charAt(j) != input_char;
24+
}
25+
return true;
26+
}
27+
28+
public boolean check2() {
29+
// Verification should fail, this is to check the solver does
30+
// not get a contradiction
31+
int i = "hello".indexOf('o', 1);
32+
assert i == 4;
33+
i = "hello".indexOf('h', 1);
34+
assert i == -1;
35+
i = "hello".indexOf('e', 4);
36+
assert i == -1;
37+
i = "hello".indexOf('e', 8);
38+
assert i == -1;
39+
i = "hello".indexOf('x', 0);
40+
assert i == -1;
41+
i = "hello".indexOf('h', -1000);
42+
assert i == 0;
43+
assert false;
44+
return true;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--refine-strings --function Test.check --unwind 4 --string-max-length 3 --java-assume-inputs-non-null
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
Test.class
3+
--refine-strings --function Test.check2 --unwind 10 --string-max-length 10 --java-assume-inputs-non-null
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
assertion at file Test.java line 32 .* SUCCESS
7+
assertion at file Test.java line 34 .* SUCCESS
8+
assertion at file Test.java line 36 .* SUCCESS
9+
assertion at file Test.java line 38 .* SUCCESS
10+
assertion at file Test.java line 40 .* SUCCESS
11+
assertion at file Test.java line 42 .* SUCCESS
12+
assertion at file Test.java line 43 .* FAILURE
13+
^VERIFICATION FAILED$
14+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
THOROUGH
2+
Test.class
3+
--refine-strings --function Test.check --unwind 10 --string-max-length 10 --java-assume-inputs-non-null
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--

0 commit comments

Comments
 (0)