File: Base-Generic.t

package info (click to toggle)
libmath-planepath-perl 117-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,988 kB
  • ctags: 5,587
  • sloc: perl: 99,131; ansic: 299; sh: 233; lisp: 73; makefile: 4
file content (109 lines) | stat: -rw-r--r-- 2,866 bytes parent folder | download | duplicates (4)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl -w

# Copyright 2012, 2013 Kevin Ryde

# This file is part of Math-PlanePath.
#
# Math-PlanePath is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# Math-PlanePath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.

use 5.004;
use strict;
use Test;
plan tests => 22;

use lib 't','xt';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings(); }

use Math::PlanePath::Base::Generic
  'is_infinite',
  'round_nearest',
  'floor';


#------------------------------------------------------------------------------
# is_infinite()

{
  my $pos_infinity = 0;
  my $neg_infinity = 0;
  my $nan = 0;

  my $skip_inf;
  my $skip_nan;
  if (! eval { require Data::Float; 1 }) {
    MyTestHelpers::diag ("Data::Float not available");
    $skip_inf = 'due to Data::Float not available';
    $skip_nan = 'due to Data::Float not available';
  } else {
    if (Data::Float::have_infinite()) {
      $pos_infinity = Data::Float::pos_infinity();
      $neg_infinity = Data::Float::neg_infinity();
    } else {
      $skip_inf = 'due to Data::Float no infinite';
    }

    if (Data::Float::have_nan()) {
      $nan = Data::Float::nan();
      MyTestHelpers::diag ("nan is ",$nan);
    } else {
      $skip_nan = 'due to Data::Float no nan';
    }
  }

  skip ($skip_inf,
        !! is_infinite($pos_infinity), 1, '_is_infinte() +inf');
  skip ($skip_inf,
        !! is_infinite($neg_infinity), 1, '_is_infinte() -inf');
  skip ($skip_nan,
        !! is_infinite($nan), 1, '_is_infinte() nan');
}
{
  require POSIX;
  ok (! is_infinite(POSIX::DBL_MAX()), 1, '_is_infinte() DBL_MAX');
  ok (! is_infinite(- POSIX::DBL_MAX()), 1, '_is_infinte() neg DBL_MAX');
}


#------------------------------------------------------------------------------
# round_nearest()

ok (round_nearest(-.75),  -1);
ok (round_nearest(-.5),   0);
ok (round_nearest(-0.25), 0);

ok (round_nearest(0.25), 0);
ok (round_nearest(1.25), 1);
ok (round_nearest(1.5),  2);
ok (round_nearest(1.75), 2);
ok (round_nearest(2),    2);

#------------------------------------------------------------------------------
# floor()

ok (floor(-.75),  -1);
ok (floor(-.5),   -1);
ok (floor(-0.25), -1);

ok (floor(0.25), 0);
ok (floor(0.75), 0);
ok (floor(1.25), 1);
ok (floor(1.5),  1);
ok (floor(1.75), 1);
ok (floor(2),    2);


#------------------------------------------------------------------------------
1;
__END__