Skip to content

Commit

Permalink
Test comparing jbmc lastIndexOf with loop version
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbrenguier committed Dec 8, 2017
1 parent 985684a commit 3ab853e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Binary file not shown.
27 changes: 27 additions & 0 deletions regression/jbmc-strings/VerifStringLastIndexOf/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Test {
// This compares the model of indexOf to an implementation
// using loops

public int math_min(int i, int j) {
if (i < j)
return i;
else
return j;
}

public int referenceLastIndexOf(String s, char ch, int fromIndex) {
for (int i = math_min(fromIndex, s.length() - 1); i >= 0; i--) {
if (s.charAt(i) == ch) {
return i;
}
}
return -1;
}

public int check(String s, char ch, int fromIndex) {
int reference = referenceLastIndexOf(s, ch, fromIndex);
int jbmc_result = s.lastIndexOf(ch, fromIndex);
assert(reference == jbmc_result);
return jbmc_result;
}
}
7 changes: 7 additions & 0 deletions regression/jbmc-strings/VerifStringLastIndexOf/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
THOROUGH
Test.class
--function Test.check --refine-strings --string-max-length 50 --unwind 50 --java-assume-inputs-non-null
^EXIT=10$
^SIGNAL=0$
assertion at file Test.java line 32 .* SUCCESS$
assertion at file Test.java line 34 .* FAILURE$

0 comments on commit 3ab853e

Please sign in to comment.