W
www
Hi,
I have two text files, text1.xml and text2.xml. text1.xml is the bench
mark file and text2.xml is generated by my Java program. In my junit
test, I want to compare the generated text2.xml against the bench mark
file text1.xml. The bench mark file text1.xml is much bigger than
text2.xml, because it has other lines in it. All the lines in text2.xml,
except a few lines containing timing information, should find a match in
text1.xml
In another words, lines 2 to 1101 in text2.xml should be identical with
lines 850 to 1949 in text1.xml; lines 1103 all the way to the end in
text2.xml should be identical with lines from 2799 to the end in text1.xml.
One way for comparison is using for loop and with these hard-coded line
number, compare line by line. But I hate the hard-coded line number.
I tried the way below, but is too slow:
1)append all the lines in text1.xml into a huge single String line, e.g.
benchLine;
2)append lines 2 to 1101 in text2.xml into another huge String line,
e.g. patternLine;
3)Pattern pattern = Pattern.compile(".*" + patternLine + ".*"); //use
the huge line to generage a regular expression pattern
pattern.macher(benchLine).find(); //hope it is true
4)repeat step 2) but with lines 1103 to the end in text2.xml and step 3
But this is tooooo slow.
Thank you for your help.
I have two text files, text1.xml and text2.xml. text1.xml is the bench
mark file and text2.xml is generated by my Java program. In my junit
test, I want to compare the generated text2.xml against the bench mark
file text1.xml. The bench mark file text1.xml is much bigger than
text2.xml, because it has other lines in it. All the lines in text2.xml,
except a few lines containing timing information, should find a match in
text1.xml
In another words, lines 2 to 1101 in text2.xml should be identical with
lines 850 to 1949 in text1.xml; lines 1103 all the way to the end in
text2.xml should be identical with lines from 2799 to the end in text1.xml.
One way for comparison is using for loop and with these hard-coded line
number, compare line by line. But I hate the hard-coded line number.
I tried the way below, but is too slow:
1)append all the lines in text1.xml into a huge single String line, e.g.
benchLine;
2)append lines 2 to 1101 in text2.xml into another huge String line,
e.g. patternLine;
3)Pattern pattern = Pattern.compile(".*" + patternLine + ".*"); //use
the huge line to generage a regular expression pattern
pattern.macher(benchLine).find(); //hope it is true
4)repeat step 2) but with lines 1103 to the end in text2.xml and step 3
But this is tooooo slow.
Thank you for your help.