Skip to content

Commit 455cc8b

Browse files
tompngmrkn
authored andcommitted
Add argument coerce assertion for all BigMath methods
1 parent 5f769e2 commit 455cc8b

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

test/bigdecimal/test_bigmath.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def assert_consistent_precision_acceptance(accept_zero: false)
5353
end
5454

5555
def test_consistent_precision_acceptance
56-
x = BigDecimal('1.23456789')
56+
x = BigDecimal('0.123456789')
5757
# Exclude div because div(x, nil) is a special case
5858
assert_consistent_precision_acceptance(accept_zero: true) {|prec| x.add(x, prec) }
5959
assert_consistent_precision_acceptance(accept_zero: true) {|prec| x.sub(x, prec) }
@@ -66,11 +66,52 @@ def test_consistent_precision_acceptance
6666
assert_consistent_precision_acceptance {|prec| BigMath.sin(x, prec) }
6767
assert_consistent_precision_acceptance {|prec| BigMath.cos(x, prec) }
6868
assert_consistent_precision_acceptance {|prec| BigMath.tan(x, prec) }
69+
assert_consistent_precision_acceptance {|prec| BigMath.asin(x, prec) }
70+
assert_consistent_precision_acceptance {|prec| BigMath.acos(x, prec) }
6971
assert_consistent_precision_acceptance {|prec| BigMath.atan(x, prec) }
72+
assert_consistent_precision_acceptance {|prec| BigMath.atan2(x, x + 1, prec) }
73+
assert_consistent_precision_acceptance {|prec| BigMath.sinh(x, prec) }
74+
assert_consistent_precision_acceptance {|prec| BigMath.cosh(x, prec) }
75+
assert_consistent_precision_acceptance {|prec| BigMath.tanh(x, prec) }
76+
assert_consistent_precision_acceptance {|prec| BigMath.asinh(x, prec) }
77+
assert_consistent_precision_acceptance {|prec| BigMath.acosh(x + 1, prec) }
78+
assert_consistent_precision_acceptance {|prec| BigMath.atanh(x, prec) }
79+
assert_consistent_precision_acceptance {|prec| BigMath.log2(x, prec) }
80+
assert_consistent_precision_acceptance {|prec| BigMath.log10(x, prec) }
81+
assert_consistent_precision_acceptance {|prec| BigMath.log1p(x, prec) }
82+
assert_consistent_precision_acceptance {|prec| BigMath.expm1(x, prec) }
83+
7084
assert_consistent_precision_acceptance {|prec| BigMath.E(prec) }
7185
assert_consistent_precision_acceptance {|prec| BigMath.PI(prec) }
7286
end
7387

88+
def test_coerce_argument
89+
f = 0.8
90+
bd = BigDecimal(f)
91+
assert_equal(BigMath.exp(bd, N), BigMath.exp(f, N))
92+
assert_equal(BigMath.log(bd, N), BigMath.log(f, N))
93+
assert_equal(sqrt(bd, N), sqrt(f, N))
94+
assert_equal(cbrt(bd, N), cbrt(f, N))
95+
assert_equal(hypot(bd, bd, N), hypot(f, f, N))
96+
assert_equal(sin(bd, N), sin(f, N))
97+
assert_equal(cos(bd, N), cos(f, N))
98+
assert_equal(tan(bd, N), tan(f, N))
99+
assert_equal(asin(bd, N), asin(f, N))
100+
assert_equal(acos(bd, N), acos(f, N))
101+
assert_equal(atan(bd, N), atan(f, N))
102+
assert_equal(atan2(bd, bd, N), atan2(f, f, N))
103+
assert_equal(sinh(bd, N), sinh(f, N))
104+
assert_equal(cosh(bd, N), cosh(f, N))
105+
assert_equal(tanh(bd, N), tanh(f, N))
106+
assert_equal(asinh(bd, N), asinh(f, N))
107+
assert_equal(acosh(bd * 2, N), acosh(f * 2, N))
108+
assert_equal(atanh(bd, N), atanh(f, N))
109+
assert_equal(log2(bd, N), log2(f, N))
110+
assert_equal(log10(bd, N), log10(f, N))
111+
assert_equal(log1p(bd, N), log1p(f, N))
112+
assert_equal(expm1(bd, N), expm1(f, N))
113+
end
114+
74115
def test_sqrt
75116
assert_in_delta(2**0.5, sqrt(BigDecimal("2"), N))
76117
assert_equal(10, sqrt(BigDecimal("100"), N))

0 commit comments

Comments
 (0)