summaryrefslogtreecommitdiffstats
path: root/t/13_drhtz-drhfz.t
blob: fc8ee01c865621b9719cd3b48a5184d7c2d2c921 (plain)
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
# t/13_drhtz-drhfz.t - drhtz and drhfz tests
#
# Copyright (C) 2017  Patrick McDermott
#
# 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;

my @std_tests;
my @tie_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 = (
	[ 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],
);

$i = 0;
map({$i += scalar(@{$_}) - 3} @std_tests);
map({$i += scalar(@{$_}) - 3} @tie_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));
	}
}