~ubuntu-branches/debian/jessie/liblouis/jessie

« back to all changes in this revision

Viewing changes to tests/check_tables_against_corpus.pl

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Thibault
  • Date: 2010-01-12 23:48:47 UTC
  • mto: (1.1.4 upstream) (5.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100112234847-ph9xdk3lrjdox6ks
ImportĀ upstreamĀ versionĀ 1.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
use strict;
 
3
$|++;
 
4
 
 
5
my $TEST_CORPUS_PREFIX = "$ENV{srcdir}/table_test_corpuses/test_";
 
6
 
 
7
my @test_corpuses;
 
8
my $table_counter = 0;
 
9
my $word_counter;
 
10
my $failed_counter;
 
11
my $failed = 0;
 
12
 
 
13
for my $test_corpus (glob "$TEST_CORPUS_PREFIX*") {
 
14
    my ($table) = ($test_corpus =~ /^$TEST_CORPUS_PREFIX(.*)$/);
 
15
 
 
16
    # ignore tables which are not vaild
 
17
    unless (system("lou_checktable $table > /dev/null 2>&1") == 0) {
 
18
        print "Table $table doesn't seem to be valid. Skipping it.\n";
 
19
        next;
 
20
    }
 
21
    
 
22
    open(CORPUS, "<", $test_corpus) or die "cannot open test corpus: $test_corpus\n";
 
23
 
 
24
    print "Testing $table...\n";
 
25
 
 
26
    $table_counter++;
 
27
    $word_counter = 0;
 
28
    $failed_counter = 0;
 
29
    while (<CORPUS>) {
 
30
        chomp;
 
31
        # ignore comment and empty lines
 
32
        next if (/^#.*/);
 
33
        next if (/^ *$/);
 
34
        my ($untranslated, $expected_translation) = split;
 
35
        $word_counter++;
 
36
        my $translation = `echo $untranslated | lou_translate -f $table`;
 
37
        chomp $translation;
 
38
        unless ($expected_translation eq $translation) {
 
39
            print "Translation error: '$translation' expected '$expected_translation'\n";
 
40
            $failed_counter++;
 
41
            $failed = 1;
 
42
        }
 
43
    }
 
44
    print "Tested $word_counter words. ";
 
45
    if ($failed_counter == 0) {
 
46
        print "All translations are correct.\n";
 
47
    } else {
 
48
        print "$failed_counter words failed with a wrong translation.\n";
 
49
    }
 
50
    close(CORPUS);
 
51
}
 
52
print "Tested $table_counter tables.\n";
 
53
 
 
54
exit $failed;