File: number.t

package info (click to toggle)
libautobox-core-perl 1.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 328 kB
  • ctags: 161
  • sloc: perl: 567; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!perl

use Test::More;
use autobox::Core;

#is( 12.34->ceil,       13);
#is( 12.34->round_up,   13);
#is( 12.34->floor,      12);
#is( 12.34->round_down, 12);
is( 12.34->int, 12);

#is( 2.5->round, 3 );
#is( 2->round, 2 );
#is( 0->round, 0 );
#is( 2.51->round, 3 );
#is( -3.51->round, -4 );

ok( 12->is_number );
ok(!'FF'->is_number );

ok( 12->is_positive );
ok( "+12"->is_positive );
ok( 12.34->is_positive );
ok( !"foo"->is_positive );
ok( !"-12.2"->is_positive );

ok( !12->is_negative );
ok( "-12"->is_negative );
ok( (-12.34)->is_negative );
ok( !"foo"->is_negative );
ok( "-12.2"->is_negative );

ok !0->is_negative,     "zero is not negative";
ok !0->is_positive,     "zero is not positive";

ok( 12->is_integer );
ok( -12->is_integer );
ok( "+12"->is_integer );
ok(!12.34->is_integer );

ok( 12->is_int );
ok(!12.34->is_int );

ok( 12.34->is_decimal );
ok( ".34"->is_decimal );
ok( !12->is_decimal );
ok(!'abc'->is_decimal );

is( '123'->reverse, '321' );

TODO: {
   local $TODO = q{ hex is weird };

   is( 255->hex, 'FF');
   is( 'FF'->dec, 255);
   is( 0xFF->dec, 255);

};

TODO: {
    todo_skip "Make number methods work on non-scalar refs", 20;

    for my $ref ([ 'foo' ], { bar => 1 }, \'baz', sub { 'gorch' }) {
        for my $method (qw(is_decimal is_integer is_int is_negative is_positive)) {
            ok(!$ref->$method);
        }
    }
}

done_testing();