if (args.length != 2) {
System.out.println("Rossz praméterezés.");
} else {
ComponentModel cm = new ComponentModel();
CommandInterpreter ci = new CommandInterpreter();
String inputFilePath = args[0];
String generatedFilePath = "generted.txt";
String logFilePath = "log.txt";
String expectedResultFilePath = args[1];
//fájlok létrehozása
File fg = new File(generatedFilePath);
if (!fg.exists()) {
fg.createNewFile();
System.out.println(generatedFilePath + " has been created.");
}
File f_log = new File(logFilePath);
if (!f_log.exists()) {
f_log.createNewFile();
System.out.println(logFilePath + " has been created.");
}
// File olvasók létrehozsása
FileReader fr_generated = new FileReader(generatedFilePath);
BufferedReader in_generated = new BufferedReader(fr_generated);
FileReader fr_expected = new FileReader(expectedResultFilePath);
BufferedReader in_expected = new BufferedReader(fr_expected);
FileReader fr_inputFile = new FileReader(inputFilePath);
BufferedReader in_inputFile = new BufferedReader(fr_inputFile);
FileOutputStream os_generated = new FileOutputStream(generatedFilePath);
PrintStream ps_generated = new PrintStream(os_generated);
FileOutputStream os_logfile = new FileOutputStream(logFilePath);
PrintStream ps_logfile = new PrintStream(os_logfile);
//Átirányítás
System.setOut(ps_generated);
String s = "";
try {
while (!(s == null || s.equals("quit") || s.equals("exit"))) {
s = in_inputFile.readLine();
if (s != null) {
ci.ExecuteCommand(s);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getClass());
} finally {
fr_inputFile.close();
in_inputFile.close();
os_generated.close();
ps_generated.close();
System.setOut(System.out);
ci.translate("quit");
System.out.println("Vege");
}
//Eredmény és elvárt eredmény sorainak összehasonlítása
int lineCounter = 0;
String expectedLine = "";
String generatedLine = "";
try {
while (expectedLine!= null || generatedLine!=null) {
expectedLine = in_expected.readLine();
generatedLine = in_generated.readLine();
if(expectedLine==null && generatedLine!=null){
ps_logfile.println(generatedFilePath+" has more lines then "+ expectedResultFilePath+".");
}
if(expectedLine!=null && generatedLine==null){
ps_logfile.println(expectedResultFilePath+" has more lines then "+ generatedFilePath+".");
}
lineCounter++;
if (generatedLine.equals(expectedLine) == false) {
int indexOfDifference=0;
String SubGenerated=generatedLine.substring(0,indexOfDifference);
String SubExpected = expectedLine.substring(0,indexOfDifference);
while( SubGenerated.equals(SubExpected)){
indexOfDifference++;
SubGenerated=generatedLine.substring(0,indexOfDifference);
SubExpected = expectedLine.substring(0,indexOfDifference);
}
ps_logfile.println(lineCounter + ". line "+indexOfDifference+". character is DIFFERENT.");
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getClass());
} finally {
fr_generated.close();
in_generated.close();
fr_expected.close();
in_expected.close();
fr_inputFile.close();
in_inputFile.close();
os_generated.close();
ps_generated.close();
ps_logfile.close();
os_logfile.close();
ci.translate("quit");
System.out.println("Vege");
}
System.setOut(System.out);
System.out.println("halksdjlgkjsaldgj");
}