Don't like ads? PRO users don't see any ads ;-)
Guest

tests_checker.pl

By: a guest on Apr 18th, 2012  |  syntax: Perl  |  size: 2.35 KB  |  hits: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4.  
  5. my $shell_string = "othello> ";
  6.  
  7. my @files = <Test*.txt>;
  8.  
  9. for my $i ( 0 .. $#files ) {
  10.  
  11.         local $/=undef;
  12.         open FILE, $files[$i] or die "Couldn't open file: $!";
  13.  
  14.         print "\nTesting case " . ($i + 1) . ": $files[$i]\n";
  15.        
  16.         my $test_file = <FILE>;
  17.         close FILE;
  18.        
  19.         my @lines = split(/\n/, $test_file);
  20.        
  21.         shift @lines;
  22.         shift @lines;
  23.         shift @lines;
  24.        
  25.         my $file_contents = "";
  26.        
  27.         foreach(@lines) {
  28.        
  29.                 if ($_ =~ /PROGRAM_relaxed_test {(.*?)}.{(.*?)}/) {
  30.                         my $in = $1;
  31.                         my $out = $2;
  32.                
  33.                         $file_contents .= $1 . "\n";
  34.                         open (JAVA_IN, '>in');
  35.                         print JAVA_IN ($file_contents . "quit");
  36.                         close JAVA_IN;
  37.                        
  38.                         my $got = `java Shell < in`;
  39.                         $got =~ s/.*$shell_string(.)/$1/s;
  40.                         $got =~ s/(\n)*$shell_string//;
  41.                         $got =~ s/(\n)/ /g;
  42.                        
  43.                         if ($got ne $out) {
  44.                                 print "Error found. Input was: {$in}\nExpected response: {$out}\nGot: {$got}\n\n";
  45.                         }
  46.                        
  47.                 } elsif ($_ =~ /PROGRAM_test {(.*?)}/) {
  48.                         my $in = $1;
  49.                
  50.                         $file_contents .= $1 . "\n";
  51.                         open (JAVA_IN, '>in');
  52.                         print JAVA_IN ($file_contents . "quit");
  53.                         close JAVA_IN;
  54.                        
  55.                         my $got = `java Shell < in`;
  56.                         $got =~ s/.*$shell_string(.)/$1/s;
  57.                         $got =~ s/(\n)*$shell_string//;
  58.                        
  59.                         if ($got  ne "") {
  60.                                 print "Error found. Input was: {$in}\nExpected response: {}\nGot: {$got}\n\n";
  61.                         }      
  62.                        
  63.                 } elsif ($_ =~ /PROGRAM_list_test {(.*?)}.{(.*?)}/) {
  64.                         my $in = $1;
  65.                         my $out = $2;
  66.                        
  67.                         $file_contents .= $1 . "\n";
  68.                         open (JAVA_IN, '>in');
  69.                         print JAVA_IN ($file_contents . "quit");
  70.                         close JAVA_IN;
  71.                        
  72.                         my $got = `java Shell < in`;
  73.                         $got =~ s/.*$shell_string(.)/$1/s;
  74.                         $got =~ s/(\n)*$shell_string//;
  75.                         $got =~ s/(\n)/ /g;
  76.                        
  77.                         if ($got ne $out) {
  78.                                 print "Error found. Input was: {$in}\nExpected response: {$out}\nGot: {$got}\n\n";
  79.                         }
  80.                        
  81.                        
  82.                 } elsif ($_ =~ /PROGRAM_error {(.*?)}/) {
  83.                         my $in = $1;
  84.                
  85.                         $file_contents .= $1 . "\n";
  86.                         open (JAVA_IN, '>in');
  87.                         print JAVA_IN ($file_contents . "quit");
  88.                         close JAVA_IN;
  89.                        
  90.                         my $got = `java Shell < in`;
  91.                         $got =~ s/.*$shell_string(.)/$1/s;
  92.                         $got =~ s/(\n)*$shell_string//;
  93.                         $got =~ s/(.......)//;
  94.                        
  95.                         if ($1  ne "Error! ") {
  96.                                 print "Error found. Input was: {$in}\nExpected response: {Error! ...} (error message)\nGot: {$1$got}\n\n";
  97.                         }
  98.                 } else {
  99.                         die "Error: Unknown command.";
  100.                 }
  101.         }
  102.        
  103.         unlink "in";
  104. }