From c71c59feeb8edd975cc49c718dec8319e22ee2a4 Mon Sep 17 00:00:00 2001 From: eregon Date: Mon, 1 Apr 2019 20:35:10 +0000 Subject: Fix Float#to_s specs to not depend on the platform representation of doubles * AIX, Solaris, etc have a different binary representation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/float/to_s_spec.rb | 251 +++++++++++++++++++------------------- 1 file changed, 124 insertions(+), 127 deletions(-) (limited to 'spec') diff --git a/spec/ruby/core/float/to_s_spec.rb b/spec/ruby/core/float/to_s_spec.rb index 127132b567..db375bfc0e 100644 --- a/spec/ruby/core/float/to_s_spec.rb +++ b/spec/ruby/core/float/to_s_spec.rb @@ -97,133 +97,130 @@ describe "Float#to_s" do end describe "matches" do - ruby_version_is "2.4" do # For unpack1 - it "random examples in all ranges" do - # 50.times do - # bytes = (0...8).map { rand(256) } - # string = bytes.pack('C8') - # float = string.unpack('D').first - # puts " #{bytes.pack('C8').inspect}.unpack1('D').to_s.should == #{float.to_s.inspect}" - # end - - "\x97\x15\xC1| \xF5\x19\xAD".unpack1('D').to_s.should == "-1.9910613439044092e-91" - "\xBF\xF0\x14\xAD\xDF\x17q\xD1".unpack1('D').to_s.should == "-2.075408637901046e+84" - "\xDF\xBD\xC0\x89\xDA\x1F&$".unpack1('D').to_s.should == "1.5219626883645564e-134" - "|0\xBB".unpack1('D').to_s.should == "-2.4921382721208654e-23" - "\x94\x01\xB1\x87\x10\x9B#\x88".unpack1('D').to_s.should == "-1.8555672851958583e-269" - "\x90H\xFF\\S\x01)\x89".unpack1('D').to_s.should == "-1.5509713490195968e-264" - "HW@\x13\x85&=)".unpack1('D').to_s.should == "4.848496966571536e-110" - "\x14\xDB\\\x10\x93\x9C\xD66".unpack1('D').to_s.should == "1.5842813502410472e-44" - "\x9D8p>\xFF\x9B[\xF3".unpack1('D').to_s.should == "-4.826061446912647e+247" - "c\x9D}\t]\xF9pg".unpack1('D').to_s.should == "1.8907034486212682e+190" - "\xA51\xC9WJ\xB5a^".unpack1('D').to_s.should == "4.422435231445608e+146" - "\x8BL\x90\xCB\xEARf\f".unpack1('D').to_s.should == "6.235963569982745e-249" - end - - it "random examples in human ranges" do - # 50.times do - # formatted = '' - # rand(1..3).times do - # formatted << rand(10).to_s - # end - # formatted << '.' - # rand(1..9).times do - # formatted << rand(10).to_s - # end - # float = formatted.to_f - # string = [float].pack('D') - # puts " #{string.inspect}.unpack1('D').to_s.should == #{float.to_s.inspect}" - # end - - ";\x01M\x84\r\xF7M@".unpack1('D').to_s.should == "59.9301" - "\xAE\xD3HKe|\x8A@".unpack1('D').to_s.should == "847.54946" - "/\xDD$\x06\x81u8@".unpack1('D').to_s.should == "24.459" - "E\xD8\xF0\xF4JY\xF0?".unpack1('D').to_s.should == "1.0218" - "[\brP\xC2\xCC\x05@".unpack1('D').to_s.should == "2.72498" - "\xE6w\x9A\xCCx\xF6T@".unpack1('D').to_s.should == "83.851123" - "\xB4\xD4&\xC0C\xFD.@".unpack1('D').to_s.should == "15.494657521" - "\xCD\xCC\xCC\xCC\xCCLM@".unpack1('D').to_s.should == "58.6" - "\xA1\x84\x99\xB6\x7F\xE5\x13@".unpack1('D').to_s.should == "4.97412" - "\xD7\xA3p=\n\x9C\x80@".unpack1('D').to_s.should == "531.505" - "S\x96!\x8E\xF5\x0E\x8F@".unpack1('D').to_s.should == "993.8699" - "\xF1F\xE6\x91?\x18\xD7?".unpack1('D').to_s.should == "0.360855" - "=\n\xD7\xA3p=\x15@".unpack1('D').to_s.should == "5.31" - "\x90Ci\x147\xC74@".unpack1('D').to_s.should == "20.7781842" - "A\ft\xED\v\xE8\xB9?".unpack1('D').to_s.should == "0.101197" - "\x9A\x99\x99\x99\x999T@".unpack1('D').to_s.should == "80.9" - "\x00\x00\x00\x00\x00\x00\x1A@".unpack1('D').to_s.should == "6.5" - "\xD3J\xC6\xD6\x98\x8Es@".unpack1('D').to_s.should == "312.9123142" - "SQ\xE5I\fQ\x1E@".unpack1('D').to_s.should == "7.57914844" - "k]Q\xE7\xDDb\x1E@".unpack1('D').to_s.should == "7.59654962" - "\x1F\x85\xEBQ\xB8\xEAz@".unpack1('D').to_s.should == "430.67" - "\x00\x00\x00\x00\x00\x00\x14@".unpack1('D').to_s.should == "5.0" - "{\x14\xAEG\xE1\n}@".unpack1('D').to_s.should == "464.68" - "\x12\x83\xC0\xCA\xA1=V@".unpack1('D').to_s.should == "88.963" - "\x9Aw\x9C\xA2#y\e@".unpack1('D').to_s.should == "6.8683" - "(\x0F\v\xB5\xA6y\xFB?".unpack1('D').to_s.should == "1.7172" - "\xD5x\xE9&1H!@".unpack1('D').to_s.should == "8.641" - "w'Deh\x1Ab@".unpack1('D').to_s.should == "144.8252436" - ":X\xFF\xE70_\x04@".unpack1('D').to_s.should == "2.54648" - "E4\xB2\x12\x90\xCA\x1E@".unpack1('D').to_s.should == "7.69781522" - "fffff\xAA\x80@".unpack1('D').to_s.should == "533.3" - "\xCD\x92\x005\xB5p:@".unpack1('D').to_s.should == "26.440265" - "\xBE\x1D