use warnings; use strict; use Test::More 'no_plan'; use Test::NoWarnings; use Data::Dump qw(pp); note "testing under perl version $]"; BEGIN { use_ok 'TrigCalc', qw(reduce); } my @TESTS = ( 'degenerate cases', [ [], [ 0, 0, 0 ], 'empty argument list' ], [ [ undef ], [ 0, 0, 0 ], 'undefined argument(s)' ], [ [ undef, undef ], [ 0, 0, 0 ], 'undefined argument(s)' ], [ [ undef, undef, undef ], [ 0, 0, 0 ], 'undefined argument(s)' ], 'irreducible cases', [ [ 123, 180, 59, 59 ], [ 180, 59, 59 ], 'left ignored' ], [ [ 180, 59, 59 ], [ 180, 59, 59 ], ], [ [ 180, 59, 58 ], [ 180, 59, 58 ], ], [ [ 1, 1, 1 ], [ 1, 1, 1 ], ], [ [ 0, 0, 0 ], [ 0, 0, 0 ], ], [ [ -1, -1, -1 ], [ -1, -1, -1 ], ], [ [ -180, -59, -58 ], [ -180, -59, -58 ], ], [ [ -123, -180, -59, -59 ], [ -180, -59, -59 ], 'left ignored' ], 'reducible cases', [ [ 179, 0, 60 ], [ 179, 1, 0 ], ], [ [ 179, 61, 61 ], [ 180, 2, 1 ], ], [ [ 179, 59, 60 ], [ 180, 0, 0 ], ], [ [ -179, 60, 0 ], [ -178, 0, 0 ], 'reduction of negatives' ], # [ [ 0, 0, -60 ], [ -1, 59, 2 ], 'negative borrow' ], # <-- ???? [ [ 0, 0, -60 ], [ 0, -1, 0 ], 'negative borrow' ], [ [ 90, 360, 360 ], [ 96, 6, 0 ], 'multiple reduction' ], [ [ 90, -360, -360 ], [ 83, 54, 0 ], 'multiple reduction' ], 'only rightmost arguments are reduced, others ignored', [ [ 200, 179, 0, 60 ], [ 179, 1, 0 ], ], [ [ 200, 200, 179, 0, 60 ], [ 179, 1, 0 ], ], [ [ 200, 200, 200, 179, 0, 60 ], [ 179, 1, 0 ], ], [ [ 200, 90, -360, -360 ], [ 83, 54, 0 ], ], [ [ 200, 200, 90, -360, -360 ], [ 83, 54, 0 ], ], [ [ 200, 200, 200, 90, -360, -360 ], [ 83, 54, 0 ], ], ); # just to be sure... is_deeply [ reduce ], [ 0, 0, 0 ], 'REALLY empty argument list'; VECTOR: for my $ar_vector (@TESTS) { # comments can be mixed into test vector list. if (not ref $ar_vector) { note "--- $ar_vector ---"; # actually a comment next VECTOR; } # expand test vector. my ($ar_args, $ar_expected, $cmnt) = @$ar_vector; # prepare fancy-shmancy test comment. $cmnt = defined $cmnt ? ": $cmnt" : ''; my $args_str = pp @$ar_args; my $expected_str = pp @$ar_expected; my $full_comment = "$args_str -> $expected_str$cmnt"; # do it to it. is_deeply [ reduce(@$ar_args) ], $ar_expected, $full_comment; } # end for VECTOR # a way to test non-exported functions. note "\n=== testing TrigCalc::dms_2_secs() ===\n\n"; # aliasing not really necessary, but more sexy. *dms2s = *TrigCalc::dms_2_secs; VECTOR: for my $ar_vector ( # only LEFT-most input args are converted. # expected ------ input args ------ # seconds secs mins degs ignored [ 0, ], # empty args list [ 1, 1 ], [ 62, 2, 1 ], [ 3723, 3, 2, 1 ], [ 7384, 4, 3, 2, 4 ], [ 11045, 5, 4, 3, 5, 6 ], [ 14706, 6, 5, 4, 7, 8, 9 ], ) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } my ($expected, @args) = @$ar_vector; is dms2s(@args), $expected, "(@args) == $expected seconds"; } # end for VECTOR done_testing; exit; # support subroutines ############################################## # none for now