aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-06 11:09:24 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-06 11:36:02 +1300
commit7fa252fe32a34065852e73aebc00272833f5537a (patch)
treef302efa68ea8df12a67ff555cf096946a75fd22d /t
parentBump version number (diff)
downloadList-Breakdown-7fa252fe32a34065852e73aebc00272833f5537a.tar.gz
List-Breakdown-7fa252fe32a34065852e73aebc00272833f5537a.zip
Add numeric ranges checking
Diffstat (limited to 't')
-rw-r--r--t/errors.t9
-rw-r--r--t/intervals.t34
2 files changed, 40 insertions, 3 deletions
diff --git a/t/errors.t b/t/errors.t
index 44cf190..499310e 100644
--- a/t/errors.t
+++ b/t/errors.t
@@ -4,7 +4,7 @@ use strict;
use warnings;
use utf8;
-use Test::More tests => 5;
+use Test::More tests => 7;
use List::Breakdown 'breakdown';
@@ -23,8 +23,11 @@ is( eval { breakdown { a => undef }, @t } || undef,
# A non-reference value in spec hashref is fatal
is( eval { breakdown { a => 'a' }, @t } || undef, undef, 'error_notref_def' );
-# The wrong kind of reference as a value in spec hashref is fatal
-is( eval { breakdown { a => [] }, @t } || undef, undef, 'error_badref_array' );
+# Any number of items in the numeric range shortcut besides 2 is fatal
+is( eval { breakdown { a => [] }, @t } || undef, undef, 'error_badref_array' );
+is( eval { breakdown { a => [1] }, @t } || undef, undef, 'error_badref_array' );
+is( eval { breakdown { a => [ 1, 2, 3 ] }, @t } || undef,
+ undef, 'error_badref_array' );
# A double reference as a value in a spec hashref is fatal
is( eval { breakdown { a => \{} }, @t } || undef, undef,
diff --git a/t/intervals.t b/t/intervals.t
new file mode 100644
index 0000000..53f4724
--- /dev/null
+++ b/t/intervals.t
@@ -0,0 +1,34 @@
+#!perl -T
+
+use strict;
+use warnings;
+use utf8;
+
+use Test::More tests => 1;
+
+use List::Breakdown 'breakdown';
+
+our $VERSION = '0.14';
+
+## no critic (ProhibitMagicNumbers,ProhibitLeadingZeros)
+my @numbers = ( 1, 32, 3718.4, 0x56, 0777, 3.14, -5, 1.2e5 );
+my $filters = {
+ negative => [ undef, 0 ],
+ positive => {
+ small => [ 0, 10 ],
+ medium => [ 10, 100 ],
+ large => [ 100, undef ],
+ },
+};
+my %filtered = breakdown $filters, @numbers;
+
+my %expected = (
+ negative => [ -5, ],
+ positive => {
+ large => [ 3_718.4, 511, 120_000, ],
+ medium => [ 32, 86, ],
+ small => [ 1, 3.14, ],
+ },
+);
+
+is_deeply( \%filtered, \%expected, 'words' );