added string methods length, position, replace, toUpperCase, toLowerCase, and trim

Signed-off-by: Lucas Cordeiro <lucasccordeiro@gmail.com>
This commit is contained in:
Lucas Cordeiro 2017-02-22 14:24:07 +00:00
parent c94a19350a
commit 2ec8fe0f29
12 changed files with 127 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -0,0 +1,8 @@
FUTURE
StringMiscellaneous01.class
--string-refine --unwind 30
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring

View File

@ -0,0 +1,8 @@
public class StringMiscellaneous02
{
public static void main(String[] args)
{
String s1 = "Automatic Test Generation";
assert s1.length()==24;
}
}

View File

@ -0,0 +1,8 @@
FUTURE
StringMiscellaneous02.class
--string-refine --unwind 30
^EXIT=0$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring

View File

@ -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;
}
}
}

View File

@ -0,0 +1,8 @@
FUTURE
StringMiscellaneous03.class
--string-refine --unwind 30
^EXIT=0$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring

View File

@ -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();
}
}

View File

@ -0,0 +1,8 @@
FUTURE
StringMiscellaneous04.class
--string-refine --unwind 30
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring