Skip to content

Commit a233a22

Browse files
Test comparing jbmc lastIndexOf with loop version
1 parent 85a65e6 commit a233a22

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public class Test {
2+
// This compares the model of indexOf to an implementation
3+
// using loops
4+
5+
public int math_min(int i, int j) {
6+
if (i < j)
7+
return i;
8+
else
9+
return j;
10+
}
11+
12+
public int referenceLastIndexOf(String s, char ch, int fromIndex) {
13+
int i = math_min(fromIndex, s.length() - 1);
14+
for (; i >= 0; i--) {
15+
if (s.charAt(i) == ch) {
16+
return i;
17+
}
18+
}
19+
return -1;
20+
}
21+
22+
public int check(String s, char ch, int fromIndex) {
23+
int reference = referenceLastIndexOf(s, ch, fromIndex);
24+
int jbmc_result = s.lastIndexOf(ch, fromIndex);
25+
assert(reference == jbmc_result);
26+
return jbmc_result;
27+
}
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
THOROUGH
2+
Test.class
3+
--function Test.check --refine-strings --string-max-length 50 --unwind 50 --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 .* FAILURE$

0 commit comments

Comments
 (0)