2
# ====================================================================
3
# Copyright (c) 2000 Carnegie Mellon University. All rights reserved.
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
9
# 1. Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
12
# 2. Redistributions in binary form must reproduce the above copyright
13
# notice, this list of conditions and the following disclaimer in
14
# the documentation and/or other materials provided with the
17
# This work was supported in part by funding from the Defense Advanced
18
# Research Projects Agency and the National Science Foundation of the
19
# United States of America, and the CMU Sphinx Speech Consortium.
21
# THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
22
# ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25
# NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
die "$0 <file1> <file2> (tolerance)\n" unless (($#ARGV == 1) or ($#ARGV == 2));
39
my $tolerance = 0.002;
40
$tolerance = $ARGV[2] if ($#ARGV == 2);
46
if ((open (FN1, "<$fn1")) and (open (FN2, "<$fn2"))) {
48
while (($line1 = <FN1>) . ($line2 = <FN2>)) {
51
next if ($line1 eq $line2);
52
my @field1 = split /[,\s]+/, $line1;
53
my @field2 = split /[,\s]+/, $line2;
54
# If the number of tokens in each line is different, the lines,
55
# and therefore the files, don't match.
56
if ($#field1 != $#field2) {
60
for (my $i = 0; $i <= $#field1; $i++) {
61
if (($field1[$i] !~ m/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) or
62
($field2[$i] !~ m/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)) {
63
# Check if any of the tokens in the line is a string rather
64
# than a number, and compare the strings
65
if ($field1[$i] ne $field2[$i]) {
69
} elsif (abs($field1[$i] - $field2[$i]) > $tolerance) {
70
# If the tokens are both numbers, check if they match within
76
# If there was a mismatch, we can skip to the end of the loop
77
last if ($comparison == 0);
79
# If the files don't have the same number of lines, one of the
80
# lines will be EOF, and the other won't.
81
$comparison = 0 if ($line1 != $line2);
88
print "Comparison: SUCCESS\n";
90
print "Comparison: FAIL\n";