Commits

Shlomi Fish committed ecc410b

Add more tests and enhance the spec.

Comments (0)

Files changed (2)

App-Countdown/lib/App/Countdown.pm

 sub _calc_delay {
     my ($self, $delay_spec) = @_;
 
-    if (my ($n, $qualifier) = $delay_spec =~ /\A([1-9][0-9]*)([mh]?)\z/)
+    if (my ($n, $qualifier) = $delay_spec =~ /\A((?:[1-9][0-9]*(?:\.\d*)?)|(?:0\.\d+))([mh]?)\z/)
     {
-        return ($n * ($qualifier eq 'h'
+        return int($n * ($qualifier eq 'h'
                 ? (60 * 60)
                 : $qualifier eq 'm'
                 ? 60

App-Countdown/t/unit-calc-delay.t

 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 9;
 
 use App::Countdown;
 
 
     # TEST
     is ($obj->_calc_delay('5h'), 5*60*60, "_calc_delay(5h) == 5*60*60 (5 hours)");
+
+    # TEST
+    is ($obj->_calc_delay('1.5m'), 60+30, "_calc_delay(1.5m) == 60*1.5 (fractional minutes)");
+
+    # TEST
+    is ($obj->_calc_delay('1.5h'), 3600 + 1800, "_calc_delay(1.5h) == 3600*1.5 (fractional hours)");
+
+    # TEST
+    is ($obj->_calc_delay('0.5m'), 30, "_calc_delay(0.5m) == 30 (leading zero)");
 }