| 1 | #!perl |
| 2 | |
| 3 | use Test::More tests => 49; |
| 4 | use autobox::Core; |
| 5 | |
| 6 | #is( 12.34->ceil, 13); |
| 7 | #is( 12.34->round_up, 13); |
| 8 | #is( 12.34->floor, 12); |
| 9 | #is( 12.34->round_down, 12); |
| 10 | is( 12.34->int, 12); |
| 11 | |
| 12 | #is( 2.5->round, 3 ); |
| 13 | #is( 2->round, 2 ); |
| 14 | #is( 0->round, 0 ); |
| 15 | #is( 2.51->round, 3 ); |
| 16 | #is( -3.51->round, -4 ); |
| 17 | |
| 18 | ok( 12->is_number ); |
| 19 | ok(!'FF'->is_number ); |
| 20 | |
| 21 | ok( 12->is_positive ); |
| 22 | ok( "+12"->is_positive ); |
| 23 | ok( 12.34->is_positive ); |
| 24 | ok( !"foo"->is_positive ); |
| 25 | ok( !"-12.2"->is_positive ); |
| 26 | |
| 27 | ok( !12->is_negative ); |
| 28 | ok( "-12"->is_negative ); |
| 29 | ok( (-12.34)->is_negative ); |
| 30 | ok( !"foo"->is_negative ); |
| 31 | ok( "-12.2"->is_negative ); |
| 32 | |
| 33 | ok !0->is_negative, "zero is not negative"; |
| 34 | ok !0->is_positive, "zero is not positive"; |
| 35 | |
| 36 | ok( 12->is_integer ); |
| 37 | ok( -12->is_integer ); |
| 38 | ok( "+12"->is_integer ); |
| 39 | ok(!12.34->is_integer ); |
| 40 | |
| 41 | ok( 12->is_int ); |
| 42 | ok(!12.34->is_int ); |
| 43 | |
| 44 | ok( 12.34->is_decimal ); |
| 45 | ok( ".34"->is_decimal ); |
| 46 | ok( !12->is_decimal ); |
| 47 | ok(!'abc'->is_decimal ); |
| 48 | |
| 49 | is( '123'->reverse, '321' ); |
| 50 | |
| 51 | TODO: { |
| 52 | local $TODO = q{ hex is weird }; |
| 53 | |
| 54 | is( 255->hex, 'FF'); |
| 55 | is( 'FF'->dec, 255); |
| 56 | is( 0xFF->dec, 255); |
| 57 | |
| 58 | }; |
| 59 | |
| 60 | TODO: { |
| 61 | todo_skip "Make number methods work on non-scalar refs", 20; |
| 62 | |
| 63 | for my $ref ([ 'foo' ], { bar => 1 }, \'baz', sub { 'gorch' }) { |
| 64 | for my $method (qw(is_decimal is_integer is_int is_negative is_positive)) { |
| 65 | ok(!$ref->$method); |
| 66 | } |
| 67 | } |
| 68 | } |