Acme-Spinodal-Utils
view release on metacpan or search on metacpan
lib/Acme/Spinodal/Utils.pm view on Meta::CPAN
$total *= $num;
}
return $total;
}
=head2 _check_number
Checks to see if a given scalar is a valid number.
croaks on error.
returns the number asked to check in successful scenarios.
=cut
sub _check_number {
if( !defined $_[0] ){
croak( "Argument was undefined!");
}
if( ref $_[0]){
diag("Testing Util $Acme::Spinodal::Utils::VERSION, Perl $], $^X");
ok( defined &Acme::Spinodal::Utils::sum, '&Acme::Spinodal::Utils::sum is defined' );
{ # sum tests
{ # No args
my $total;
eval { $total = Acme::Spinodal::Utils::sum() };
my $err = $@;
is( $total, 0, "Checking that the total is zero when no args are given." );
is( $err, '', "Checking no error was returned.")
}
{ # Expected total
my $total;
eval { $total = Acme::Spinodal::Utils::sum( qw(1 2 3 4) ) };
my $err = $@;
is( $total, 10, "Checking that the correct total is returned." );
is( $err, '', "Checking no error was returned.")
}
{ # Strange args
throws_ok { Acme::Spinodal::Utils::sum( qw( 1 2 3 Blarg!) ) } qr/does not appear to be a valid number!/, 'Checking an error was returned.';
}
{ # some more intersting numbers
my $total;
eval { $total = Acme::Spinodal::Utils::sum( qw( 5 -273.15 3.141592 12321 0 -12.34e56) ) };
my $err = $@;
is( $total, -1.234e+57, "Checking that the correct total is returned." );
is( $err, '', "Checking no error was returned.")
}
}
done_testing();
( run in 0.627 second using v1.01-cache-2.11-cpan-65fba6d93b7 )