-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test cases: stringbuffer-append, stringbuffer-delete, stringbuffe…
…r-dynamic, stringbuffer-insert, stringbuffer-misc
- Loading branch information
1 parent
f5dae24
commit 90c8532
Showing
7 changed files
with
413 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v3.4.4 | ||
v3.4.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
public class main { | ||
|
||
public static int checker(String label, String expected, String observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected.equals(observed)) { | ||
System.out.printf(" ok, expected = %s = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %s, observed = %s\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static int checker(String label, int expected, int observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected == observed) { | ||
System.out.printf(" ok, expected = %d = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %d, observed = %d\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int errorCount = 0; | ||
|
||
StringBuffer sb1 = new StringBuffer(); | ||
System.out.println("sb1 bytes: nil"); | ||
errorCount += checker("sb1.capacity(default)", 16, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1 = new StringBuffer(3); | ||
errorCount += checker("sb1.capacity(3)", 3, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1.append("12345678"); | ||
errorCount += checker("sb1.append(\"12345678\")", "12345678", sb1.toString()); | ||
errorCount += checker("sb1.capacity(8)", 8, sb1.capacity()); | ||
errorCount += checker("sb1.length(8)", 8, sb1.length()); | ||
|
||
sb1.append(true); | ||
errorCount += checker("sb1.append(true)", "12345678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(12)", 12, sb1.length()); | ||
|
||
sb1.append('C'); | ||
errorCount += checker("sb1.append(C)", "12345678trueC", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(13)", 13, sb1.length()); | ||
|
||
char charray [] = { 'a', 'b', 'c' }; | ||
sb1.append(charray); | ||
errorCount += checker("sb1.append('a', 'b', 'c')", "12345678trueCabc", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(16)", 16, sb1.length()); | ||
|
||
double dd = 1.23; | ||
sb1.append(dd); | ||
errorCount += checker("sb1.append(dd)", "12345678trueCabc1.23", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(20)", 20, sb1.length()); | ||
|
||
int ii = 345; | ||
sb1.append(ii); | ||
errorCount += checker("sb1.append(ii)", "12345678trueCabc1.23345", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(23)", 23, sb1.length()); | ||
|
||
int jj = 81517; | ||
sb1.append(jj); | ||
errorCount += checker("sb1.append(jj)", "12345678trueCabc1.2334581517", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(28)", 28, sb1.length()); | ||
|
||
String str = "JKLMNOP"; | ||
sb1.append(str); | ||
errorCount += checker("sb1.append(JKLMNOP)", "12345678trueCabc1.2334581517JKLMNOP", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(35)", 35, sb1.length()); | ||
|
||
assert(errorCount == 0); | ||
System.out.printf("No errors\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
public class main { | ||
|
||
public static int checker(String label, String expected, String observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected.equals(observed)) { | ||
System.out.printf(" ok, expected = %s = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %s, observed = %s\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static int checker(String label, int expected, int observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected == observed) { | ||
System.out.printf(" ok, expected = %d = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %d, observed = %d\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int errorCount = 0; | ||
|
||
StringBuffer sb1 = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||
|
||
sb1.deleteCharAt(3); | ||
errorCount += checker("sb1.delete(3)", "ABCEFGHIJKLMNOPQRSTUVWXYZ", sb1.toString()); | ||
errorCount += checker("sb1.capacity(42)", 42, sb1.capacity()); | ||
errorCount += checker("sb1.length(25)", 25, sb1.length()); | ||
|
||
sb1.delete(5, 5); | ||
errorCount += checker("sb1.delete(5, 5)", "ABCEFGHIJKLMNOPQRSTUVWXYZ", sb1.toString()); | ||
errorCount += checker("sb1.capacity(42)", 42, sb1.capacity()); | ||
errorCount += checker("sb1.length(25)", 25, sb1.length()); | ||
|
||
sb1.delete(5, 10); | ||
errorCount += checker("sb1.delete(5, 10)", "ABCEFLMNOPQRSTUVWXYZ", sb1.toString()); | ||
errorCount += checker("sb1.capacity(42)", 42, sb1.capacity()); | ||
errorCount += checker("sb1.length(20)", 20, sb1.length()); | ||
|
||
sb1.deleteCharAt(0); | ||
errorCount += checker("sb1.delete(0)", "BCEFLMNOPQRSTUVWXYZ", sb1.toString()); | ||
errorCount += checker("sb1.capacity(42)", 42, sb1.capacity()); | ||
errorCount += checker("sb1.length(19)", 19, sb1.length()); | ||
|
||
sb1.deleteCharAt(18); | ||
errorCount += checker("sb1.delete(0)", "BCEFLMNOPQRSTUVWXY", sb1.toString()); | ||
errorCount += checker("sb1.capacity(42)", 42, sb1.capacity()); | ||
errorCount += checker("sb1.length(18)", 18, sb1.length()); | ||
|
||
try { | ||
sb1.deleteCharAt(-42); | ||
System.out.println("********** ERROR, failed to catch exception 1"); | ||
errorCount++; | ||
} catch(StringIndexOutOfBoundsException ex) { | ||
System.out.println("Successfully caught exception 1"); | ||
} | ||
|
||
try { | ||
sb1.delete(5, 3); | ||
System.out.println("********** ERROR, failed to catch exception 2"); | ||
errorCount++; | ||
} catch(StringIndexOutOfBoundsException ex) { | ||
System.out.println("Successfully caught exception 2"); | ||
} | ||
|
||
assert(errorCount == 0); | ||
System.out.printf("No errors\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
public class main { | ||
|
||
public static int checker(String label, String expected, String observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected.equals(observed)) { | ||
System.out.printf(" ok, expected = %s = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %s, observed = %s\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static int checker(String label, int expected, int observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected == observed) { | ||
System.out.printf(" ok, expected = %d = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %d, observed = %d\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int errorCount = 0; | ||
|
||
StringBuffer sb1 = new StringBuffer(); | ||
errorCount += checker("sb1.capacity(default)", 16, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1 = new StringBuffer(3); | ||
errorCount += checker("sb1.capacity(3)", 3, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1.append("abcdefgh"); | ||
errorCount += checker("sb1.append(\"abcdefgh\")", "abcdefgh", sb1.toString()); | ||
errorCount += checker("sb1.capacity(8)", 8, sb1.capacity()); | ||
errorCount += checker("sb1.length(8)", 8, sb1.length()); | ||
|
||
StringBuffer sb2 = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||
System.out.println("Bytes: ABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||
errorCount += checker("sb2.capacity(42)", 42, sb2.capacity()); | ||
errorCount += checker("sb2.length(26)", 26, sb2.length()); | ||
errorCount += checker("charAt(2)", "C", String.valueOf(sb2.charAt(2))); | ||
errorCount += checker("substring(13)", "NOPQRSTUVWXYZ", sb2.substring(13)); | ||
errorCount += checker("substring(13, 16)", "NOP", sb2.substring(13, 16)); | ||
errorCount += checker("dynamic 1", "NOPQRSTUVWXYZ NOP", String.format("%s %s", sb2.substring(13), sb2.substring(13, 16))); | ||
errorCount += checker("dynamic 2", "NOPQRSTUVWXYZ 4.0 NOP", String.format("%s %.1f %s", sb2.substring(13), Math.sqrt(16.0), sb2.substring(13, 16))); | ||
errorCount += checker("dynamic 3", 29, sb2.length() + Math.getExponent(Math.sqrt(16.3)) + 1); | ||
errorCount += checker("dynamic 4", "\"29\"", String.format("\"%d\"", sb2.length() + Math.getExponent(Math.sqrt(16.3)) + 1)); | ||
|
||
assert(errorCount == 0); | ||
System.out.printf("No errors\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
public class main { | ||
|
||
public static int checker(String label, String expected, String observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected.equals(observed)) { | ||
System.out.printf(" ok, expected = %s = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %s, observed = %s\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static int checker(String label, int expected, int observed) { | ||
System.out.printf("checker %s ", label); | ||
if (expected == observed) { | ||
System.out.printf(" ok, expected = %d = observed\n", expected); | ||
return 0; | ||
} | ||
System.out.printf(" ********** ERROR, expected = %d, observed = %d\n", expected, observed); | ||
return 1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int errorCount = 0; | ||
|
||
StringBuffer sb1 = new StringBuffer(3); | ||
errorCount += checker("sb1.capacity(3)", 3, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1.append("12345678"); | ||
errorCount += checker("sb1.append(\"12345678\")", "12345678", sb1.toString()); | ||
errorCount += checker("sb1.capacity(8)", 8, sb1.capacity()); | ||
errorCount += checker("sb1.length(8)", 8, sb1.length()); | ||
|
||
sb1.append(true); | ||
errorCount += checker("sb1.append(true)", "12345678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(12)", 12, sb1.length()); | ||
|
||
sb1.insert(3, 'C'); | ||
errorCount += checker("sb1.insert(3, C)", "123C45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(13)", 13, sb1.length()); | ||
|
||
char charray [] = { 'x', 'y', 'z' }; | ||
sb1.insert(3, charray); | ||
errorCount += checker("sb1.insert(3, 'x', 'y', 'z')", "123xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(18)", 18, sb1.capacity()); | ||
errorCount += checker("sb1.length(16)", 16, sb1.length()); | ||
|
||
double dd = 1.23; | ||
sb1.insert(3, dd); | ||
errorCount += checker("sb1.insert(3, dd)", "1231.23xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(20)", 20, sb1.length()); | ||
|
||
int ii = 345; | ||
sb1.insert(3, ii); | ||
errorCount += checker("sb1.insert(3, ii)", "1233451.23xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(23)", 23, sb1.length()); | ||
|
||
int jj = 81517; | ||
sb1.insert(3, jj); | ||
errorCount += checker("sb1.insert(3, jj)", "123815173451.23xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(28)", 28, sb1.length()); | ||
|
||
String str = "JKLMNOP"; | ||
sb1.insert(3, str); | ||
errorCount += checker("sb1.insert(3, JKLMNOP)", "123JKLMNOP815173451.23xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(38)", 38, sb1.capacity()); | ||
errorCount += checker("sb1.length(35)", 35, sb1.length()); | ||
|
||
str = "QRSTU"; | ||
sb1.insert(0, str); | ||
errorCount += checker("sb1.insert(0, QRSTU)", "QRSTU123JKLMNOP815173451.23xyzC45678true", sb1.toString()); | ||
errorCount += checker("sb1.capacity(78)", 78, sb1.capacity()); | ||
errorCount += checker("sb1.length(40)", 40, sb1.length()); | ||
|
||
str = "_THE_END"; | ||
sb1.insert(40, str); | ||
errorCount += checker("sb1.insert(35, _THE_END)", "QRSTU123JKLMNOP815173451.23xyzC45678true_THE_END", sb1.toString()); | ||
errorCount += checker("sb1.capacity(78)", 78, sb1.capacity()); | ||
errorCount += checker("sb1.length(48)", 48, sb1.length()); | ||
|
||
assert(errorCount == 0); | ||
System.out.printf("No errors\n"); | ||
} | ||
} |
Oops, something went wrong.