summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MANIFEST1
-rw-r--r--t/13_drhtz-drhfz.t72
2 files changed, 73 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 4742eab..b413bd6 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -9,4 +9,5 @@ t/00_compile.t
t/10_dadd.t
t/11_dmul.t
t/12_dmul-dadd.t
+t/13_drhtz-drhfz.t
t/20_nj-st-75-2017.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 <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],
+ [-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));
+ }
+}