# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..19\n"; } END {print "not ok 1\n" unless $loaded;} use Units::Height::DWIM qw(height2metric pretty_height); $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): my %tests=( "3"=>3, "4'"=>1.2192, "4"=>1.2192, "5'1"=>1.5494, qq(5'2")=>1.5748, "7"=>2.1336, 1.2=>1.2, 2.5=>2.5, "2,5"=>2.5, 140=>1.4, "1.4"=>1.4, "1,4"=>1.4, ); $q=2; while(my($in, $out)=each %tests) { my $meters=height2metric($in); # warn "$in gives $meters ($out)\n"; print "not " unless abs($meters-$out) <0.005; print "ok $q\n"; $q++; } my %tests2=( imperial=>{ 1.2192=>"4'", 1.5494=>qq(5'1"), }, metric=>{ 1.2=>"1.20", 2=>"2.00", }, cm=>{ 1.40=>"140", 1.00=>"100" }, ); foreach my $unit (keys %tests2) { while(my($in, $out)=each %{$tests2{$unit}}) { my $gave=pretty_height($in, $unit); # warn "$in gives $gave in $unit ($out)\n"; print "not " unless $gave eq $out; print "ok $q\n"; $q++; } }