Skip to content
Snippets Groups Projects
Verified Commit f3825ad5 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

file testing

parent a631cabf
No related branches found
No related tags found
No related merge requests found
Pipeline #7936 passed
......@@ -6,8 +6,8 @@ import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
public class Main {
......@@ -23,6 +23,10 @@ public class Main {
return sb.toString();
}
private static byte[] decodeB64(String input) {
return Base64.getDecoder().decode(input);
}
private static boolean runTest(String jarfile, String testName) throws FileNotFoundException {
System.out.printf("Running test \"%s\"\n", testName);
......@@ -97,8 +101,8 @@ public class Main {
System.out.printf("File: %s\n", f);
System.out.println();
try {
String got = fileToString(f);
boolean erro = compareStrings(got, e);
byte[] got = Files.readAllBytes(Paths.get(f));
boolean erro = compareFiles(got, decodeB64(e));
if (erro) {
error.set(true);
} else {
......@@ -211,10 +215,19 @@ public class Main {
return error;
}
private static String fileToString(String path) throws IOException {
StringBuilder build = new StringBuilder();
Stream<String> stream = Files.lines(Paths.get(path), StandardCharsets.UTF_8);
stream.forEach(s -> build.append(s).append("\n"));
return build.toString();
private static boolean compareFiles(byte[] got, byte[] expect) {
if (got.length != expect.length) {
System.out.println("❌ A fájlméretek különböznek");
return false;
}
var err = false;
for (int i = 0; i < expect.length; i++) {
if (got[i] != expect[i]) {
System.out.printf("❌ A %d. byte (karakter) nem passzol\n", i);
err = true;
}
}
return err;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment