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
|
# t/13_drhtz-drhfz.t - drhtz and drhfz tests
#
# Copyright (C) 2017 Libiquity LLC
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
use Test::More;
use B qw(svref_2object);
use Math::Decimal::FastPP qw(dadd dmul drhtz drhfz);
my @std_tests;
my @tie_tests;
my @inv_tests;
my $i;
my $a;
my $p;
my $r;
my @funcs;
my $f;
@std_tests = (
# a p r functions
[ 23.1 , 0, "23." , \&drhtz, \&drhfz],
[ 23.9 , 0, "24." , \&drhtz, \&drhfz],
[ 2.31, 1, "2.3", \&drhtz, \&drhfz],
[ 2.39, 1, "2.4", \&drhtz, \&drhfz],
[-23.1 , 0, "-23." , \&drhtz, \&drhfz],
[-23.9 , 0, "-24." , \&drhtz, \&drhfz],
[ -2.31, 1, "-2.3", \&drhtz, \&drhfz],
[ -2.39, 1, "-2.4", \&drhtz, \&drhfz],
);
@tie_tests = (
# a p r functions
[ 23.5 , 0, "23." , \&drhtz ],
[ 23.5 , 0, "24." , \&drhfz],
[ 2.35, 1, "2.3", \&drhtz ],
[ 2.35, 1, "2.4", \&drhfz],
[-23.5 , 0, "-23." , \&drhtz ],
[-23.5 , 0, "-24." , \&drhfz],
[ -2.35, 1, "-2.3", \&drhtz ],
[ -2.35, 1, "-2.4", \&drhfz],
);
@inv_tests = (
# a p r functions
[ 23 , 1, undef, \&drhtz, \&drhfz],
);
$i = 0;
map({$i += scalar(@{$_}) - 3} @std_tests);
map({$i += scalar(@{$_}) - 3} @tie_tests);
map({$i += scalar(@{$_}) - 3} @inv_tests);
plan("tests" => $i);
note("Basic tests:");
foreach (@std_tests) {
($a, $p, $r, @funcs) = @{$_};
foreach $f (@funcs) {
is(&$f($a, $p), $r, sprintf("%s(%6.2f, %d) = %5.1f",
svref_2object($f)->GV->NAME, $a, $p, $r));
}
}
note("Tie-breaking tests:");
foreach (@tie_tests) {
($a, $p, $r, @funcs) = @{$_};
foreach $f (@funcs) {
is(&$f($a, $p), $r, sprintf("%s(%6.2f, %d) = %5.1f",
svref_2object($f)->GV->NAME, $a, $p, $r));
}
}
note("Invalid precision tests:");
foreach (@inv_tests) {
($a, $p, $r, @funcs) = @{$_};
foreach $f (@funcs) {
is(&$f($a, $p), $r, sprintf("%s(%s, %d) = undef",
svref_2object($f)->GV->NAME, $a, $p));
}
}
|