drop a reminder diag for bignumber support in perl
[rersyncrecent.git] / t / 01-util.t
blob72d1b953655ebc9a00a46a0e9505922d59d60d6f
1 use Test::More;
2 my $tests;
3 BEGIN { $tests = 0 }
4 use lib "lib";
5 use File::Rsync::Mirror::Recentfile;
6 use File::Rsync::Mirror::Recentfile::FakeBigFloat qw(_increase_a_bit _bigfloatlt);
9     BEGIN { $tests += 5 }
10     my $rf = File::Rsync::Mirror::Recentfile->new;
11     for my $x ([-12, undef],
12                [0, 0],
13                [undef, undef],
14                [(12)x2],
15                [(12000000000000)x2],
16               ) {
17         my $ret = eval { $rf->interval_secs(defined $x->[0] ? $x->[0] . "s" : ()); };
18         is $ret, $x->[1];
19     }
23     BEGIN { $tests += 5 }
24     my $rf = File::Rsync::Mirror::Recentfile->new;
25     for my $x (["12s" => 12],
26                ["12m" => 720],
27                ["2h"  => 7200],
28                ["1d"  => 86400],
29                ["4Q"  => 31104000],
30               ) {
31         my $ret = $rf->interval_secs ( $x->[0] );
32         is $ret, $x->[1];
33     }
37     my @x;
38     BEGIN {
39         @x = (
40               ["1" => "2"],
41               ["1" => undef],
42               ["0.99999999900000080543804870103485882282257080078125",
43                "0.9999999990000010274826536260661669075489044189453125"],
45 # the following is an interesting example because I saw this in the debugger:
46 #   DB<104> x "123456789123456789.2" <=> "123456789123456790"
47 # 0  1
49               ["123456789123456789","123456789123456790"],
50              );
51         for (@x) {
52             if (defined $_->[1]) {
53                 $tests += 2;
54             } else {
55                 $tests++;
56             }
57         }
58     }
59     for my $x (@x) {
60         my $ret = _increase_a_bit ( $x->[0], $x->[1] );
61         ok _bigfloatlt($x->[0], $ret), "L: $x->[0] < $ret";
62         if (defined $x->[1]) {
63             ok _bigfloatlt($ret, $x->[1]), "R: $ret < $x->[1]";
64         }
65     }
66     diag sprintf 'testing "native" big math: "123456789123456789.2" <=> "123456789123456790" [%d]',
67         "123456789123456789.2" <=> "123456789123456790";
70 BEGIN { plan tests => $tests }
72 # Local Variables:
73 # mode: cperl
74 # cperl-indent-level: 4
75 # End: