Skip to content

Commit c71c64b

Browse files
Regression: include model for string to char array
Using model of char array functions in tests. Also correct java_if test description file. Remove java_object_allocation test, this should be replaced by unit tests. Removing java_append_char test duplicate of the one in string-smoke-test. Including models of char array functions for some string regression tests.
1 parent df45bdb commit c71c64b

File tree

21 files changed

+203
-133
lines changed

21 files changed

+203
-133
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
public class StringMiscellaneous04
22
{
3-
public static void main(String[] args)
4-
{
5-
String s1 = "diffblue";
6-
String s2 = "TESTGENERATION";
7-
String s3 = " automated ";
8-
9-
assert s1.equals("diffblue");
10-
assert s2.equals("TESTGENERATION");
11-
assert s3.equals(" automated ");
12-
13-
System.out.printf(
14-
"Replace 'f' with 'F' in s1: %s\n\n", s1.replace('f', 'F'));
15-
String tmp=s1.replace('f', 'F');
16-
assert tmp.equals("diFFblue");
17-
18-
tmp=s1.toUpperCase();
19-
assert tmp.equals("DIFFBLUE");
20-
21-
tmp=s2.toLowerCase();
22-
assert tmp.equals("testgeneration");
23-
24-
tmp=s3.trim();
25-
assert tmp.equals("automated");
26-
27-
// test toCharArray method
28-
char[] charArray = s1.toCharArray();
29-
System.out.print("s1 as a character array = ");
30-
31-
int i=0;
32-
for (char character : charArray)
33-
{
34-
assert character=="diffblue".charAt(i);
35-
++i;
36-
}
37-
38-
System.out.println();
39-
}
3+
// This is a model of the String.toCharArray method
4+
public static char[] toCharArray(String s)
5+
{
6+
int length=s.length();
7+
assert(length<10);
8+
char arr[]=new char[s.length()];
9+
// We limit arbitrarly the loop unfolding to 10
10+
for(int i=0; i<length && i<10; i++)
11+
arr[i]=s.charAt(i);
12+
return arr;
13+
}
14+
15+
public static void main(String[] args)
16+
{
17+
String s1 = "diffblue";
18+
String s2 = "TESTGENERATION";
19+
String s3 = " automated ";
20+
21+
assert s1.equals("diffblue");
22+
assert s2.equals("TESTGENERATION");
23+
assert s3.equals(" automated ");
24+
25+
System.out.printf(
26+
"Replace 'f' with 'F' in s1: %s\n\n", s1.replace('f', 'F'));
27+
String tmp=s1.replace('f', 'F');
28+
assert tmp.equals("diFFblue");
29+
30+
tmp=s1.toUpperCase();
31+
assert tmp.equals("DIFFBLUE");
32+
33+
tmp=s2.toLowerCase();
34+
assert tmp.equals("testgeneration");
35+
36+
tmp=s3.trim();
37+
assert tmp.equals("automated");
38+
39+
// test toCharArray method
40+
char[] charArray = toCharArray(s1);
41+
System.out.print("s1 as a character array = ");
42+
43+
int i=0;
44+
for (char character : charArray)
45+
{
46+
assert character=="diffblue".charAt(i);
47+
++i;
48+
}
49+
50+
System.out.println();
51+
}
4052
}

regression/jbmc-strings/java_char_array_init/test.desc

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ test_init.class
33
--refine-strings --string-max-length 1000
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[.*assertion.1\].* line 14.* FAILURE$
6+
assertion.* file test_init.java line 31 .* SUCCESS$
7+
assertion.* file test_init.java line 33 .* SUCCESS$
8+
assertion.* file test_init.java line 35 .* FAILURE$
9+
assertion.* file test_init.java line 37 .* FAILURE$
710
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
1-
public class test_init {
1+
public class test_init
2+
{
3+
// These are models for the constructors of strings from char arrays
4+
public static String stringOfCharArray(char arr[])
5+
{
6+
// We give an arbitrary limit on the size of arrays
7+
assert(arr.length<11);
8+
StringBuilder sb=new StringBuilder("");
9+
for(int i=0; i<arr.length && i<11; i++)
10+
sb.append(arr[i]);
11+
return sb.toString();
12+
}
213

3-
public static void main(/*String[] argv*/)
4-
{
5-
char [] str = new char[10];
6-
str[0] = 'H';
7-
str[1] = 'e';
8-
str[2] = 'l';
9-
str[3] = 'l';
10-
str[4] = 'o';
11-
String s = new String(str);
12-
String t = new String(str,1,2);
14+
public static String stringOfCharArray(char arr[], int i, int j)
15+
{
16+
return stringOfCharArray(arr).substring(i, i+j);
17+
}
1318

14-
assert(s.length() != 10 ||
15-
!t.equals("el") ||
16-
!s.startsWith("Hello"));
17-
}
19+
public static void main(int i)
20+
{
21+
char [] str = new char[10];
22+
str[0] = 'H';
23+
str[1] = 'e';
24+
str[2] = 'l';
25+
str[3] = 'l';
26+
str[4] = 'o';
27+
String s = stringOfCharArray(str);
28+
String t = stringOfCharArray(str,1,2);
29+
30+
if(i==0)
31+
assert(s.startsWith("Hello"));
32+
else if(i==1)
33+
assert(t.equals("el"));
34+
else if(i==2)
35+
assert(!s.startsWith("Hello"));
36+
else
37+
assert(!t.equals("el"));
38+
}
1839
}

regression/jbmc-strings/java_insert_char_array/test.desc

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ test_insert_char_array.class
33
--refine-strings --string-max-length 1000
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[.*assertion\.1\].* line 12.* FAILURE$
6+
assertion.* line 28.* SUCCESS$
7+
assertion.* line 30.* FAILURE$
78
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
public class test_insert_char_array
22
{
3-
public static void main(/*String[] argv*/)
4-
{
5-
StringBuilder sb = new StringBuilder("ad");
6-
char[] array = new char[2];
7-
array[0] = 'b';
8-
array[1] = 'c';
9-
sb.insert(1, array);
10-
String s = sb.toString();
11-
System.out.println(s);
12-
assert(!s.equals("abcd"));
13-
}
3+
// These are models of the String methods manipulating char arrays
4+
public static String stringOfCharArray(char arr[])
5+
{
6+
StringBuilder sb=new StringBuilder("");
7+
for(int i=0; i<arr.length; i++)
8+
sb.append(arr[i]);
9+
return sb.toString();
10+
}
11+
public static void insert(StringBuilder sb, int pos, char arr[])
12+
{
13+
String s=stringOfCharArray(arr);
14+
sb.insert(pos, s);
15+
}
16+
public static void main(int i)
17+
{
18+
StringBuilder sb = new StringBuilder("ad");
19+
char[] array = new char[2];
20+
array[0] = 'b';
21+
array[1] = 'c';
22+
insert(sb, 1, array);
23+
String s = sb.toString();
24+
System.out.println(s);
25+
if(i==0)
26+
assert(s.equals("abcd"));
27+
else
28+
assert(!s.equals("abcd"));
29+
}
1430
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CORE
22
test_append_char.class
33
--refine-strings --string-max-length 1000
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
assertion.* file test_append_char.java line 23 .* SUCCESS
7+
assertion.* file test_append_char.java line 25 .* FAILURE
78
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
public class test_append_char
22
{
3-
public static void main(/*String[] args*/)
4-
{
5-
char[] diff = {'d', 'i', 'f', 'f'};
6-
char[] blue = {'b', 'l', 'u', 'e'};
3+
public static String ofCharArray(char arr[])
4+
{
5+
StringBuilder sb = new StringBuilder("");
6+
for(int i = 0; i < arr.length; i++)
7+
sb.append(arr[i]);
8+
return sb.toString();
9+
}
10+
public static void main(String[] args)
11+
{
12+
char[] diff = {'d', 'i', 'f', 'f'};
13+
char[] blue = {'b', 'l', 'u', 'e'};
714

8-
StringBuilder buffer = new StringBuilder();
15+
StringBuilder buffer = new StringBuilder();
916

10-
buffer.append(diff)
11-
.append(blue);
17+
buffer.append(ofCharArray(diff))
18+
.append(ofCharArray(blue));
1219

13-
String tmp=buffer.toString();
14-
System.out.println(tmp);
15-
assert tmp.equals("diffblue");
16-
}
20+
String tmp=buffer.toString();
21+
System.out.println(tmp);
22+
if(args.length == 0)
23+
assert tmp.equals("diffblue");
24+
else
25+
assert !tmp.equals("diffblue");
26+
}
1727
}

regression/strings-smoke-tests/java_char_array/test.desc

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ test_char_array.class
33
--refine-strings --string-max-length 1000
44
^EXIT=10$
55
^SIGNAL=0$
6-
.*assertion.* test_char_array.java line 9 .* SUCCESS$
7-
.*assertion.* test_char_array.java line 10 .* SUCCESS$
8-
.*assertion.* test_char_array.java line 11 .* SUCCESS$
9-
.*assertion.* test_char_array.java line 13 .* FAILURE$
10-
.*assertion.* test_char_array.java line 15 .* FAILURE$
11-
.*assertion.* test_char_array.java line 17 .* FAILURE$
6+
.*assertion.* test_char_array.java line 7 .* SUCCESS$
7+
.*assertion.* test_char_array.java line 21 .* SUCCESS$
8+
.*assertion.* test_char_array.java line 22 .* SUCCESS$
9+
.*assertion.* test_char_array.java line 23 .* SUCCESS$
10+
.*assertion.* test_char_array.java line 25 .* FAILURE$
11+
.*assertion.* test_char_array.java line 27 .* FAILURE$
12+
.*assertion.* test_char_array.java line 29 .* FAILURE$
1213
^VERIFICATION FAILED$
1314
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
public class test_char_array
22
{
3-
public static void main(int i)
4-
{
5-
String s = "abc";
6-
char [] str = s.toCharArray();
7-
char c = str[2];
8-
char a = s.charAt(0);
9-
assert(str.length == 3);
10-
assert(a == 'a');
11-
assert(c == 'c');
12-
if(i==0)
13-
assert(str.length != 3);
14-
if(i==2)
15-
assert(a != 'a');
16-
if(i==3)
17-
assert(c != 'c');
18-
}
3+
// This is a model of the String.toCharArray method
4+
public static char[] toCharArray(String s)
5+
{
6+
int length = s.length();
7+
assert(length < 5);
8+
char arr[] = new char[s.length()];
9+
// We limit arbitrarly the loop unfolding to 5
10+
for(int i = 0; i < length && i < 5; i++)
11+
arr[i] = s.charAt(i);
12+
return arr;
13+
}
14+
15+
public static void main(int i)
16+
{
17+
String s = "abc";
18+
char [] str = toCharArray(s);
19+
char c = str[2];
20+
char a = s.charAt(0);
21+
assert(str.length == 3);
22+
assert(a == 'a');
23+
assert(c == 'c');
24+
if(i == 0)
25+
assert(str.length != 3);
26+
if(i == 2)
27+
assert(a != 'a');
28+
if(i == 3)
29+
assert(c != 'c');
30+
}
1931
}

regression/strings-smoke-tests/java_if/test.desc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ test.class
33
--refine-strings --string-max-length 100
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[.*assertion.1\].* line 12.* SUCCESS$
7-
^\[.*assertion.2\].* line 13.* FAILURE$
6+
^\[.*assertion.1\].* line 13.* SUCCESS$
7+
^\[.*assertion.2\].* line 15.* FAILURE$
88
--
99
$ignoring\s*char\s*array
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CORE
22
test_insert_char_array.class
33
--refine-strings --string-max-length 1000
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
assertion.* file test_insert_char_array.java line 20 .* SUCCESS$
7+
assertion.* file test_insert_char_array.java line 22 .* FAILURE$
78
--
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
public class test_insert_char_array
22
{
3-
public static void main(/*String[] argv*/)
4-
{
5-
StringBuilder sb = new StringBuilder("ad");
6-
char[] array = new char[2];
7-
array[0] = 'b';
8-
array[1] = 'c';
9-
sb.insert(1, array);
10-
String s = sb.toString();
11-
System.out.println(s);
12-
assert(s.equals("abcd"));
13-
}
3+
public static void insert(StringBuilder sb, int offset, char[] arr)
4+
{
5+
assert(arr.length<5);
6+
for(int i=0; i<arr.length && i<5; i++)
7+
sb.insert(offset+i, arr[i]);
8+
}
9+
10+
public static void main(int i)
11+
{
12+
StringBuilder sb = new StringBuilder("ad");
13+
char[] array = new char[2];
14+
array[0] = 'b';
15+
array[1] = 'c';
16+
insert(sb, 1, array);
17+
String s = sb.toString();
18+
System.out.println(s);
19+
if(i==0)
20+
assert(s.equals("abcd"));
21+
else
22+
assert(!s.equals("abcd"));
23+
}
1424
}
Binary file not shown.

regression/strings-smoke-tests/java_object_allocation/test.desc

-9
This file was deleted.

regression/strings-smoke-tests/java_object_allocation/test.java

-9
This file was deleted.

0 commit comments

Comments
 (0)