File tree 5 files changed +74
-0
lines changed
regression/jbmc-strings/StringIndexOf
5 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ --
You can’t perform that action at this time.
0 commit comments