Skip to content

Commit 28b82f3

Browse files
nobueregon
authored andcommitted
BigDecimal#precs is deprecated
1 parent 78a5544 commit 28b82f3

File tree

2 files changed

+71
-61
lines changed

2 files changed

+71
-61
lines changed

library/bigdecimal/BigDecimal_spec.rb

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18"
3131
end
3232

33-
it "accepts significant digits >= given precision" do
34-
BigDecimal("3.1415923", 10).precs[1].should >= 10
35-
end
33+
ruby_version_is ""..."3.0" do
34+
it "accepts significant digits >= given precision" do
35+
BigDecimal("3.1415923", 10).precs[1].should >= 10
36+
end
3637

37-
it "determines precision from initial value" do
38-
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
39-
BigDecimal(pi_string).precs[1].should >= pi_string.size-1
38+
it "determines precision from initial value" do
39+
pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
40+
BigDecimal(pi_string).precs[1].should >= pi_string.size-1
41+
end
4042
end
4143

4244
it "ignores leading and trailing whitespace" do
@@ -223,12 +225,14 @@ def to_s; "cheese"; end
223225
Float(@b).to_s.should == "166.66666666666666"
224226
end
225227

226-
it "has the expected precision on the LHS" do
227-
@a.precs[0].should == 18
228-
end
228+
ruby_version_is ""..."3.0" do
229+
it "has the expected precision on the LHS" do
230+
@a.precs[0].should == 18
231+
end
229232

230-
it "has the expected maximum precision on the LHS" do
231-
@a.precs[1].should == 27
233+
it "has the expected maximum precision on the LHS" do
234+
@a.precs[1].should == 27
235+
end
232236
end
233237

234238
it "produces the expected result when done via Float" do
@@ -241,32 +245,36 @@ def to_s; "cheese"; end
241245

242246
# Check underlying methods work as we understand
243247

244-
it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
245-
1.upto(100) do |n|
246-
b = BigDecimal('4' * n)
247-
precs, _ = b.precs
248-
(precs >= 9).should be_true
249-
(precs >= n).should be_true
250-
(precs % 9).should == 0
248+
ruby_version_is ""..."3.0" do
249+
it "BigDecimal precision is the number of digits rounded up to a multiple of nine" do
250+
1.upto(100) do |n|
251+
b = BigDecimal('4' * n)
252+
precs, _ = b.precs
253+
(precs >= 9).should be_true
254+
(precs >= n).should be_true
255+
(precs % 9).should == 0
256+
end
257+
BigDecimal('NaN').precs[0].should == 9
251258
end
252-
BigDecimal('NaN').precs[0].should == 9
253-
end
254259

255-
it "BigDecimal maximum precision is nine more than precision except for abnormals" do
256-
1.upto(100) do |n|
257-
b = BigDecimal('4' * n)
258-
precs, max = b.precs
259-
max.should == precs + 9
260+
it "BigDecimal maximum precision is nine more than precision except for abnormals" do
261+
1.upto(100) do |n|
262+
b = BigDecimal('4' * n)
263+
precs, max = b.precs
264+
max.should == precs + 9
265+
end
266+
BigDecimal('NaN').precs[1].should == 9
260267
end
261-
BigDecimal('NaN').precs[1].should == 9
262268
end
263269

264270
it "BigDecimal(Rational, 18) produces the result we expect" do
265271
BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3"
266272
end
267273

268-
it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
269-
BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
274+
ruby_version_is ""..."3.0" do
275+
it "BigDecimal(Rational, BigDecimal.precs[0]) produces the result we expect" do
276+
BigDecimal(@b, @a.precs[0]).to_s.should == "0.166666666666666667e3"
277+
end
270278
end
271279

272280
# Check the top-level expression works as we expect

library/bigdecimal/precs_spec.rb

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
require_relative '../../spec_helper'
22
require 'bigdecimal'
33

4-
describe "BigDecimal#precs" do
4+
ruby_version_is ""..."3.0" do
5+
describe "BigDecimal#precs" do
56

6-
before :each do
7-
@infinity = BigDecimal("Infinity")
8-
@infinity_neg = BigDecimal("-Infinity")
9-
@nan = BigDecimal("NaN")
10-
@zero = BigDecimal("0")
11-
@zero_neg = BigDecimal("-0")
7+
before :each do
8+
@infinity = BigDecimal("Infinity")
9+
@infinity_neg = BigDecimal("-Infinity")
10+
@nan = BigDecimal("NaN")
11+
@zero = BigDecimal("0")
12+
@zero_neg = BigDecimal("-0")
1213

13-
@arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
14-
@infinity, @infinity_neg, @nan, @zero, @zero_neg]
15-
@precision = BigDecimal::BASE.to_s.length - 1
16-
end
14+
@arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
15+
@infinity, @infinity_neg, @nan, @zero, @zero_neg]
16+
@precision = BigDecimal::BASE.to_s.length - 1
17+
end
1718

18-
it "returns array of two values" do
19-
@arr.each do |x|
20-
x.precs.kind_of?(Array).should == true
21-
x.precs.size.should == 2
19+
it "returns array of two values" do
20+
@arr.each do |x|
21+
x.precs.kind_of?(Array).should == true
22+
x.precs.size.should == 2
23+
end
2224
end
23-
end
2425

25-
it "returns Integers as array values" do
26-
@arr.each do |x|
27-
x.precs[0].kind_of?(Integer).should == true
28-
x.precs[1].kind_of?(Integer).should == true
26+
it "returns Integers as array values" do
27+
@arr.each do |x|
28+
x.precs[0].kind_of?(Integer).should == true
29+
x.precs[1].kind_of?(Integer).should == true
30+
end
2931
end
30-
end
3132

32-
it "returns the current value of significant digits as the first value" do
33-
BigDecimal("3.14159").precs[0].should >= 6
34-
BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
35-
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
36-
value.precs[0].should <= @precision
33+
it "returns the current value of significant digits as the first value" do
34+
BigDecimal("3.14159").precs[0].should >= 6
35+
BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
36+
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
37+
value.precs[0].should <= @precision
38+
end
3739
end
38-
end
3940

40-
it "returns the maximum number of significant digits as the second value" do
41-
BigDecimal("3.14159").precs[1].should >= 6
42-
BigDecimal('1').precs[1].should >= 1
43-
BigDecimal('1' + '0' * 100).precs[1].should >= 101
44-
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
45-
value.precs[1].should >= 1
41+
it "returns the maximum number of significant digits as the second value" do
42+
BigDecimal("3.14159").precs[1].should >= 6
43+
BigDecimal('1').precs[1].should >= 1
44+
BigDecimal('1' + '0' * 100).precs[1].should >= 101
45+
[@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
46+
value.precs[1].should >= 1
47+
end
4648
end
4749
end
4850
end

0 commit comments

Comments
 (0)