-
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.
- Loading branch information
1 parent
36eab98
commit c8e9d71
Showing
4 changed files
with
141 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.2 | ||
v3.4.3 |
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; | ||
|
||
StringBuilder sb1 = new StringBuilder(); | ||
System.out.println("sb1 bytes: nil"); | ||
errorCount += checker("sb1.capacity(default)", 16, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1 = new StringBuilder(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,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; | ||
|
||
StringBuilder sb1 = new StringBuilder(); | ||
errorCount += checker("sb1.capacity(default)", 16, sb1.capacity()); | ||
errorCount += checker("sb1.length()", 0, sb1.length()); | ||
|
||
sb1 = new StringBuilder(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()); | ||
|
||
StringBuilder sb2 = new StringBuilder("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"); | ||
} | ||
} |