# 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 . 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)); } }