added string methods length, position, replace, toUpperCase, toLowerCase, and trim
Signed-off-by: Lucas Cordeiro <lucasccordeiro@gmail.com>
This commit is contained in:
parent
c94a19350a
commit
2ec8fe0f29
Binary file not shown.
|
@ -0,0 +1,32 @@
|
|||
public class StringMiscellaneous01
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String s1 = "Automatic Test Generation";
|
||||
String s2 = "noitareneG tseT citamotuA";
|
||||
String s3 = "Autom";
|
||||
char[] charArray = new char[5];
|
||||
|
||||
assert s1.length()==25;
|
||||
|
||||
int i=0;
|
||||
for (int count = s1.length() - 1; count >= 0; count--)
|
||||
{
|
||||
System.out.printf("%c ", s1.charAt(count));
|
||||
assert s1.charAt(count) == s2.charAt(i);
|
||||
++i;
|
||||
}
|
||||
|
||||
// copy characters from string into charArray
|
||||
s1.getChars(0, 5, charArray, 0);
|
||||
i=0;
|
||||
for (char character : charArray)
|
||||
{
|
||||
System.out.print(character);
|
||||
assert s3.charAt(i) == character;
|
||||
++i;
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
FUTURE
|
||||
StringMiscellaneous01.class
|
||||
--string-refine --unwind 30
|
||||
^EXIT=0$
|
||||
^SIGNAL=0$
|
||||
^VERIFICATION SUCCESSFUL$
|
||||
--
|
||||
^warning: ignoring
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
public class StringMiscellaneous02
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String s1 = "Automatic Test Generation";
|
||||
assert s1.length()==24;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
FUTURE
|
||||
StringMiscellaneous02.class
|
||||
--string-refine --unwind 30
|
||||
^EXIT=0$
|
||||
^SIGNAL=0$
|
||||
^VERIFICATION FAILED$
|
||||
--
|
||||
^warning: ignoring
|
Binary file not shown.
|
@ -0,0 +1,15 @@
|
|||
public class StringMiscellaneous03
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String s1 = "Automatic Test Generation";
|
||||
String s2 = "noitareneG tseT citamotuA";
|
||||
char[] charArray = new char[5];
|
||||
int i=0;
|
||||
for (int count = s1.length() - 1; count >= 0; count--)
|
||||
{
|
||||
assert s1.charAt(count) != s2.charAt(i);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
FUTURE
|
||||
StringMiscellaneous03.class
|
||||
--string-refine --unwind 30
|
||||
^EXIT=0$
|
||||
^SIGNAL=0$
|
||||
^VERIFICATION FAILED$
|
||||
--
|
||||
^warning: ignoring
|
Binary file not shown.
|
@ -0,0 +1,40 @@
|
|||
public class StringMiscellaneous04
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String s1 = "diffblue";
|
||||
String s2 = "TESTGENERATION";
|
||||
String s3 = " automated ";
|
||||
|
||||
assert s1.equals("diffblue");
|
||||
assert s2.equals("TESTGENERATION");
|
||||
assert s3.equals(" automated ");
|
||||
|
||||
System.out.printf(
|
||||
"Replace 'f' with 'F' in s1: %s\n\n", s1.replace('f', 'F'));
|
||||
String tmp=s1.replace('f', 'F');
|
||||
assert tmp.equals("diFFblue");
|
||||
|
||||
tmp=s1.toUpperCase();
|
||||
assert tmp.equals("DIFFBLUE");
|
||||
|
||||
tmp=s2.toLowerCase();
|
||||
assert tmp.equals("testgeneration");
|
||||
|
||||
tmp=s3.trim();
|
||||
assert tmp.equals("automated");
|
||||
|
||||
// test toCharArray method
|
||||
char[] charArray = s1.toCharArray();
|
||||
System.out.print("s1 as a character array = ");
|
||||
|
||||
int i=0;
|
||||
for (char character : charArray)
|
||||
{
|
||||
assert character=="diffblue".charAt(i);
|
||||
++i;
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
FUTURE
|
||||
StringMiscellaneous04.class
|
||||
--string-refine --unwind 30
|
||||
^EXIT=0$
|
||||
^SIGNAL=0$
|
||||
^VERIFICATION SUCCESSFUL$
|
||||
--
|
||||
^warning: ignoring
|
Loading…
Reference in New Issue