From 88f8a42f78b7d010294b26e9130c3ffa12ed46e4 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 05 Jan 2017 17:24:28 -0500 Subject: t/13_drhtz-drhfz.t: New file --- (limited to 't') diff --git a/t/13_drhtz-drhfz.t b/t/13_drhtz-drhfz.t new file mode 100644 index 0000000..3cebf7a --- /dev/null +++ b/t/13_drhtz-drhfz.t @@ -0,0 +1,72 @@ +# 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 . + +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], + [-23.1 , 0, "-23." , \&drhtz, \&drhfz], + [-23.9 , 0, "-24." , \&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)); + } +} -- cgit v0.9.1