1# -*- mode: perl; -*- 2 3use strict; 4use warnings; 5 6use Test::More tests => 9; 7 8use Math::BigFloat; 9 10my $pi = { 11 16 => '3.141592653589793', 12 40 => '3.141592653589793238462643383279502884197', 13 }; 14 15subtest "Called as class method without argument.", sub { 16 plan tests => 5; 17 18 my $x; 19 my $test = '$x = Math::BigFloat -> bpi()'; 20 21 eval $test; 22 is($@, "", "'$test' gives emtpy \$\@"); 23 24 isa_ok($x, 'Math::BigFloat'); 25 is($x, $pi -> {40}, "'$test' gives correct output"); 26 is($x -> {_a}, undef, "'$test' gives correct accuracy"); 27 is($x -> {_p}, undef, "'$test' gives correct precision"); 28}; 29 30subtest "Called as class method with scalar argument.", sub { 31 plan tests => 5; 32 33 my $x; 34 my $test = '$x = Math::BigFloat -> bpi(16);'; 35 36 eval $test; 37 is($@, "", "'$test' gives emtpy \$\@"); 38 39 isa_ok($x, 'Math::BigFloat'); 40 is($x, $pi -> {16}, "'$test' gives correct output"); 41 is($x -> {_a}, 16, "'$test' gives correct accuracy"); 42 is($x -> {_p}, undef, "'$test' gives correct precision"); 43}; 44 45subtest "Called as class method with class argument.", sub { 46 plan tests => 5; 47 48 my ($n, $x); 49 my $test = '$n = Math::BigFloat -> new("16"); ' 50 . '$x = Math::BigFloat -> bpi($n);'; 51 52 eval $test; 53 is($@, "", "'$test' gives emtpy \$\@"); 54 55 isa_ok($x, 'Math::BigFloat'); 56 is($x, $pi -> {16}, "'$test' gives correct output"); 57 is($x -> {_a}, 16, "'$test' gives correct accuracy"); 58 is($x -> {_p}, undef, "'$test' gives correct precision"); 59}; 60 61subtest "Called as instance method without argument.", sub { 62 plan tests => 5; 63 64 my $x; 65 my $test = '$x = Math::BigFloat -> bnan(); $x -> bpi();'; 66 67 eval $test; 68 is($@, "", "'$test' gives emtpy \$\@"); 69 70 isa_ok($x, 'Math::BigFloat'); 71 is($x, $pi -> {40}, "'$test' gives correct output"); 72 is($x -> {_a}, undef, "'$test' gives correct accuracy"); 73 is($x -> {_p}, undef, "'$test' gives correct precision"); 74}; 75 76subtest "Called as instance method with scalar argument.", sub { 77 plan tests => 5; 78 79 my $x; 80 my $test = '$x = Math::BigFloat -> bnan(); $x -> bpi(16);'; 81 82 eval $test; 83 is($@, "", "'$test' gives emtpy \$\@"); 84 85 isa_ok($x, 'Math::BigFloat'); 86 is($x, $pi -> {16}, "'$test' gives correct output"); 87 is($x -> {_a}, 16, "'$test' gives correct accuracy"); 88 is($x -> {_p}, undef, "'$test' gives correct precision"); 89}; 90 91subtest "Called as instance method with instance argument.", sub { 92 plan tests => 5; 93 94 my ($n, $x); 95 my $test = '$n = Math::BigFloat -> new("16"); ' 96 . '$x = Math::BigFloat -> bnan(); ' 97 . '$x -> bpi($n);'; 98 99 eval $test; 100 is($@, "", "'$test' gives emtpy \$\@"); 101 102 isa_ok($x, 'Math::BigFloat'); 103 is($x, $pi -> {16}, "'$test' gives correct output"); 104 is($x -> {_a}, 16, "'$test' gives correct accuracy"); 105 is($x -> {_p}, undef, "'$test' gives correct precision"); 106}; 107 108subtest "Called as function without argument.", sub { 109 plan tests => 5; 110 111 my $x; 112 my $test = '$x = Math::BigFloat::bpi();'; 113 114 eval $test; 115 is($@, "", "'$test' gives emtpy \$\@"); 116 117 isa_ok($x, 'Math::BigFloat'); 118 is($x, $pi -> {40}, "'$test' gives correct output"); 119 is($x -> {_a}, undef, "'$test' gives correct accuracy"); 120 is($x -> {_p}, undef, "'$test' gives correct precision"); 121}; 122 123subtest "Called as function with scalar argument.", sub { 124 plan tests => 5; 125 126 my $x; 127 my $test = '$x = Math::BigFloat::bpi(16);'; 128 129 eval $test; 130 is($@, "", "'$test' gives emtpy \$\@"); 131 132 isa_ok($x, 'Math::BigFloat'); 133 is($x, $pi -> {16}, "'$test' gives correct output"); 134 is($x -> {_a}, 16, "'$test' gives correct accuracy"); 135 is($x -> {_p}, undef, "'$test' gives correct precision"); 136}; 137 138# The following is an ambiguous case. The argument list to bpi() is ($n), which 139# is assumed to mean $n->bpi(), since we favour the OO-style. So in the test 140# below, $n is assigned the value of pi with the default number of digits, and 141# then $n is assigned to $x. 142 143subtest "Called as function with instance argument.", sub { 144 plan tests => 9; 145 146 my ($n, $x); 147 my $test = '$n = Math::BigFloat -> new("16"); ' 148 . '$x = Math::BigFloat::bpi($n);'; 149 150 eval $test; 151 is($@, "", "'$test' gives emtpy \$\@"); 152 153 isa_ok($x, 'Math::BigFloat'); 154 is($x, $pi -> {40}, "'$test' gives correct output"); 155 is($x -> {_a}, undef, "'$test' gives correct accuracy"); 156 is($x -> {_p}, undef, "'$test' gives correct precision"); 157 158 isa_ok($n, 'Math::BigFloat'); 159 is($n, $pi -> {40}, "'$test' gives correct output"); 160 is($n -> {_a}, undef, "'$test' gives correct accuracy"); 161 is($n -> {_p}, undef, "'$test' gives correct precision"); 162}; 163