Skip to content

Commit 835464f

Browse files
committed
Additional real-world Float#to_s specs
1 parent 9f7dfd5 commit 835464f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

spec/ruby/core/float/to_s_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,70 @@
223223
"\xD7\xA3p=\nwY@".unpack1('D').to_s.should == "101.86"
224224
"\xF3\xE6p\xAD\xF6\xC3x@".unpack1('D').to_s.should == "396.247724"
225225
end
226+
227+
it "random values from divisions" do
228+
(1.0 / 7).to_s.should == "0.14285714285714285"
229+
230+
# 50.times do
231+
# a = rand(10)
232+
# b = rand(10)
233+
# c = rand(10)
234+
# d = rand(10)
235+
# expression = "#{a}.#{b} / #{c}.#{d}"
236+
# puts " (#{expression}).to_s.should == #{eval(expression).to_s.inspect}"
237+
# end
238+
239+
(1.1 / 7.1).to_s.should == "0.15492957746478875"
240+
(6.5 / 8.8).to_s.should == "0.7386363636363635"
241+
(4.8 / 4.3).to_s.should == "1.1162790697674418"
242+
(4.0 / 1.9).to_s.should == "2.1052631578947367"
243+
(9.1 / 0.8).to_s.should == "11.374999999999998"
244+
(5.3 / 7.5).to_s.should == "0.7066666666666667"
245+
(2.8 / 1.8).to_s.should == "1.5555555555555554"
246+
(2.1 / 2.5).to_s.should == "0.8400000000000001"
247+
(3.5 / 6.0).to_s.should == "0.5833333333333334"
248+
(4.6 / 0.3).to_s.should == "15.333333333333332"
249+
(0.6 / 2.4).to_s.should == "0.25"
250+
(1.3 / 9.1).to_s.should == "0.14285714285714288"
251+
(0.3 / 5.0).to_s.should == "0.06"
252+
(5.0 / 4.2).to_s.should == "1.1904761904761905"
253+
(3.0 / 2.0).to_s.should == "1.5"
254+
(6.3 / 2.0).to_s.should == "3.15"
255+
(5.4 / 6.0).to_s.should == "0.9"
256+
(9.6 / 8.1).to_s.should == "1.1851851851851851"
257+
(8.7 / 1.6).to_s.should == "5.437499999999999"
258+
(1.9 / 7.8).to_s.should == "0.24358974358974358"
259+
(0.5 / 2.1).to_s.should == "0.23809523809523808"
260+
(9.3 / 5.8).to_s.should == "1.6034482758620692"
261+
(2.7 / 8.0).to_s.should == "0.3375"
262+
(9.7 / 7.8).to_s.should == "1.2435897435897436"
263+
(8.1 / 2.4).to_s.should == "3.375"
264+
(7.7 / 2.7).to_s.should == "2.8518518518518516"
265+
(7.9 / 1.7).to_s.should == "4.647058823529412"
266+
(6.5 / 8.2).to_s.should == "0.7926829268292683"
267+
(7.8 / 9.6).to_s.should == "0.8125"
268+
(2.2 / 4.6).to_s.should == "0.47826086956521746"
269+
(0.0 / 1.0).to_s.should == "0.0"
270+
(8.3 / 2.9).to_s.should == "2.8620689655172415"
271+
(3.1 / 6.1).to_s.should == "0.5081967213114754"
272+
(2.8 / 7.8).to_s.should == "0.358974358974359"
273+
(8.0 / 0.1).to_s.should == "80.0"
274+
(1.7 / 6.4).to_s.should == "0.265625"
275+
(1.8 / 5.4).to_s.should == "0.3333333333333333"
276+
(8.0 / 5.8).to_s.should == "1.3793103448275863"
277+
(5.2 / 4.1).to_s.should == "1.2682926829268295"
278+
(9.8 / 5.8).to_s.should == "1.6896551724137934"
279+
(5.4 / 9.5).to_s.should == "0.5684210526315789"
280+
(8.4 / 4.9).to_s.should == "1.7142857142857142"
281+
(1.7 / 3.5).to_s.should == "0.4857142857142857"
282+
(1.2 / 5.1).to_s.should == "0.23529411764705882"
283+
(1.4 / 2.0).to_s.should == "0.7"
284+
(4.8 / 8.0).to_s.should == "0.6"
285+
(9.0 / 2.5).to_s.should == "3.6"
286+
(0.2 / 0.6).to_s.should == "0.33333333333333337"
287+
(7.8 / 5.2).to_s.should == "1.5"
288+
(9.5 / 5.5).to_s.should == "1.7272727272727273"
289+
end
226290
end
227291
end
228292

0 commit comments

Comments
 (0)