| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.regression; |
| 20 |
|
| 21 |
import java.io.File; |
| 22 |
import java.io.FileNotFoundException; |
| 23 |
import java.util.List; |
| 24 |
|
| 25 |
import footleg.cavesurvey.converter.CmdLineLogger; |
| 26 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public final class DiffFiles { |
| 37 |
final static String FILES_IDENTICAL = "IDENTICAL"; |
| 38 |
|
| 39 |
public static String diffFiles(String referenceFile, String testFile) throws FileNotFoundException { |
| 40 |
String result = FILES_IDENTICAL; |
| 41 |
CmdLineLogger logger = new CmdLineLogger(); |
| 42 |
|
| 43 |
List<String> original = UtilityFunctions.readTextFile( new File( referenceFile ), |
| 44 |
RunFileConverter.defaultCharset, false, null, logger ); |
| 45 |
List<String> revised = UtilityFunctions.readTextFile( new File( testFile ), |
| 46 |
RunFileConverter.defaultCharset, false, null, logger ); |
| 47 |
|
| 48 |
|
| 49 |
if ( original.size() == 0 ) { |
| 50 |
throw new FileNotFoundException("Reference data file '" + referenceFile + "' not found (or was empty)."); |
| 51 |
} |
| 52 |
if ( revised.size() == 0 ) { |
| 53 |
throw new FileNotFoundException("Output data file '" + revised + "' not found (or was empty)."); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
int shortestFileLength = original.size(); |
| 58 |
if (revised.size() < shortestFileLength ) { |
| 59 |
shortestFileLength = revised.size(); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
for (int i = 0; i < shortestFileLength; i++) { |
| 64 |
String ori = original.get(i); |
| 65 |
String rev = revised.get(i); |
| 66 |
if ( ori.equals( rev ) == false ) { |
| 67 |
|
| 68 |
result = "Files differ at line " + (i + 1) + |
| 69 |
". Reference line: '" + original.get(i) + "'; Generated line: '" + revised.get(i) + "'."; |
| 70 |
break; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
if ( ( original.size() != revised.size() ) && ( result.equals(FILES_IDENTICAL) ) ) { |
| 76 |
result = "Files are different lengths. " + |
| 77 |
"Reference file length: " + original.size() + "; Generated file length: " + revised.size() + "."; |
| 78 |
} |
| 79 |
|
| 80 |
return result; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
} |