#!/usr/local/bin/perl require "roman.lib"; @tests = split /\n/, <<'END_TESTS'; I 1 II 2 III 3 IV 4 IIII 4 # As on traditional clock faces IIIIIIII 8 # the hard way :-) X 10 L 50 DCCC 800 M 1000 MMMMM 5000 # donuts... :-) MCMXCVII 1997 MIM 1999 VL 45 XLV 45 iii 3 # Lower case is allowed. IiI undef # Mixed case is not allowed. DELIVERY undef # Non-numeral characters are not allowed. LIVID undef # Arbitrary order is not allowed. II+II=V undef # Don't be silly! END_TESTS for $test (@tests) { ($roman, $expected) = split /\s+/, $test; # next unless $roman; # Omitted on purpose! undef $expected if $expected eq 'undef'; $count++; $return = &roman($roman); next if ($return == $expected) && $expected; next if !defined($return) && !defined($expected); $strict_fail++; $loose_fail++ if $expected; if (defined($return)) { print "$test\n\tyielded '$return'?\n\n"; } else { print "$test\n\tyielded undef?\n\n"; } } if ($loose_fail) { print <<"END"; Sorry, that sub failed $loose_fail of the $count tests. Keep trying! END } elsif ($strict_fail) { print <<"END"; Well, that sub passed the main tests, although it failed on $strict_fail of the stricter tests. Good work! END } else { print "All tests passed! Congratulations!\n" } __END__