~ubuntu-branches/ubuntu/saucy/sphinxtrain/saucy

« back to all changes in this revision

Viewing changes to test/scripts/compare_table.pl

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2013-01-02 04:10:21 UTC
  • Revision ID: package-import@ubuntu.com-20130102041021-ynsizmz33fx02hea
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# ====================================================================
 
3
# Copyright (c) 2000 Carnegie Mellon University.  All rights reserved.
 
4
#
 
5
# Redistribution and use in source and binary forms, with or without
 
6
# modification, are permitted provided that the following conditions
 
7
# are met:
 
8
#
 
9
# 1. Redistributions of source code must retain the above copyright
 
10
#    notice, this list of conditions and the following disclaimer. 
 
11
#
 
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
 
15
#    distribution.
 
16
#
 
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.
 
20
#
 
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.
 
32
 
 
33
use strict;
 
34
 
 
35
die "$0 <file1> <file2> (tolerance)\n" unless (($#ARGV == 1) or ($#ARGV == 2));
 
36
 
 
37
my $fn1 = $ARGV[0];
 
38
my $fn2 = $ARGV[1];
 
39
my $tolerance = 0.002;
 
40
$tolerance = $ARGV[2] if ($#ARGV == 2);
 
41
 
 
42
my $comparison = 0;
 
43
 
 
44
my $line1 = "";
 
45
my $line2 = "";
 
46
if ((open (FN1, "<$fn1")) and (open (FN2, "<$fn2"))) {
 
47
  $comparison = 1;
 
48
  while (($line1 = <FN1>) . ($line2 = <FN2>)) {
 
49
    chomp($line1);
 
50
    chomp($line2);
 
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) {
 
57
      $comparison = 0;
 
58
      last;
 
59
    }
 
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]) {
 
66
          $comparison = 0;
 
67
          last;
 
68
        }
 
69
      } elsif (abs($field1[$i] - $field2[$i]) > $tolerance) {
 
70
        # If the tokens are both numbers, check if they match within
 
71
        # a tolerance
 
72
        $comparison = 0;
 
73
        last;
 
74
      }
 
75
    }
 
76
    # If there was a mismatch, we can skip to the end of the loop
 
77
    last if ($comparison == 0);
 
78
  }
 
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);
 
82
}
 
83
 
 
84
close(FN1);
 
85
close(FN2);
 
86
 
 
87
if ($comparison) {
 
88
  print "Comparison: SUCCESS\n";
 
89
} else {
 
90
  print "Comparison: FAIL\n";
 
91
}