Testinator

This commit is contained in:
2026-07-01 13:12:07 +09:00
parent d801090960
commit b3d71f5336
12 changed files with 418 additions and 2 deletions
+56
View File
@@ -0,0 +1,56 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import swiss.qpq.gajumaru.core.encoding.Base58;
public class Testinator {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Error: Provide the test suite name and the working dir path.");
System.exit(1);
}
try {
switch (args[0]) {
case "base64" -> {
System.out.print(base64(args[1]));
}
case "base58" -> {
System.out.print(base58(args[1]));
}
}
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
System.exit(1);
}
}
private static String base64(String workingPath) throws IOException {
Path testPath = Path.of(workingPath, "base64.test");
Path encPath = Path.of(workingPath, "base64.java.txt");
Path decPath = Path.of(workingPath, "base64.java.back");
byte[] rawBytes = Files.readAllBytes(testPath);
byte[] encBytes = Base64.getEncoder().encode(rawBytes);
Files.write(encPath, encBytes);
byte[] readEncBytes = Files.readAllBytes(encPath);
byte[] decBytes = Base64.getDecoder().decode(readEncBytes);
Files.write(decPath, decBytes);
return encPath.toString() + " " + decPath.toString();
}
private static String base58(String workingPath) throws IOException {
Path testPath = Path.of(workingPath, "base58.test");
Path encPath = Path.of(workingPath, "base58.java.txt");
Path decPath = Path.of(workingPath, "base58.java.back");
byte[] rawBytes = Files.readAllBytes(testPath);
String encString = Base58.encode(rawBytes);
Files.write(encPath, encString.getBytes());
byte[] readEncBytes = Files.readAllBytes(encPath);
String readEncString = new String(readEncBytes);
byte[] decBytes = Base58.decode(readEncString);
Files.write(decPath, decBytes);
return encPath.toString() + " " + decPath.toString();
}
}
@@ -132,8 +132,8 @@ public final class Base58 {
// The remainder of this pass is the next raw base-256 byte payload
decoded[--outputStart] = (byte) remainder;
// Permanently advance past this leading index if its value has been exhausted
if (input58[i] == 0) {
// Advance past this leading index if its value has been exhausted or is 0
while (i < input58.length && input58[i] == 0) {
i++;
}
}