Skip to content

Commit

Permalink
JACOBIN-547, new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
texadactyl committed Aug 5, 2024
1 parent 36eab98 commit c8e9d71
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This file is a version history of jacotest amendments. Entries appear in versio
| `Date` | `Version` | `Contents` |
| :------------: | :---: | :--- |
|<img width=90/>|<img width=60/>|<img width=600/>|
| 2024-08-05 | 3.4.3 | New test cases: stringbuilder-dynamic, stringbuilder-append. |
| 2024-07-21 | 3.4.2 | Updated ERROR_CATEGORIES.txt. |
| | | Changed trimming tactic (it probably does not matter). |
| 2024-07-19 | 3.4.1 | Updated ERROR_CATEGORIES.txt. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.4.2
v3.4.3
84 changes: 84 additions & 0 deletions tests/stringbuilder-append/main.java
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");
}
}
55 changes: 55 additions & 0 deletions tests/stringbuilder-dynamic/main.java
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");
}
}

0 comments on commit c8e9d71

Please sign in to comment.