示例#1
0
 def test_round_trip(self):
     test_data = [struct.unpack('<d', os.urandom(8))[0]
                  for _ in range(1000)]
     for value in test_data:
         print(value)
         round_tripped = hex_to_double(double_to_hex(value))
         if math.isnan(value):
             assert math.isnan(round_tripped)
         else:
             assert round_tripped == value
示例#2
0
 def test_round_trip(self):
     test_data = [
         struct.unpack('<d', os.urandom(8))[0] for _ in range(1000)
     ]
     for value in test_data:
         print(value)
         round_tripped = hex_to_double(double_to_hex(value))
         if math.isnan(value):
             assert math.isnan(round_tripped)
         else:
             assert round_tripped == value
示例#3
0
 def test_round_trip(self):
     test_data = [
         _pad_to(hex(struct.unpack('<Q', os.urandom(8))[0]), 16)
         for _ in range(1000)]
     # Python 2 uses an L suffix on long integer types, even in hex.
     for value in [v.rstrip('L') for v in test_data]:
         fromhex = hex_to_double(value)
         if math.isnan(fromhex):
             continue
         round_tripped = double_to_hex(fromhex)
         assert round_tripped == value
示例#4
0
 def test_round_trip(self):
     test_data = [
         _pad_to(hex(struct.unpack('<Q', os.urandom(8))[0]), 16)
         for _ in range(1000)
     ]
     # Python 2 uses an L suffix on long integer types, even in hex.
     for value in [v.rstrip('L') for v in test_data]:
         fromhex = hex_to_double(value)
         if math.isnan(fromhex):
             continue
         round_tripped = double_to_hex(fromhex)
         assert round_tripped == value
示例#5
0
 def test_negative_inf(self):
     expected = '0xfff0000000000000'
     result = double_to_hex(-float('inf'))
     assert result == expected
示例#6
0
 def test_inf(self):
     expected = '0x7ff0000000000000'
     result = double_to_hex(float('inf'))
     assert result == expected
示例#7
0
 def test_nan(self):
     round_tripped = hex_to_double(double_to_hex(float('nan')))
     assert math.isnan(round_tripped)
示例#8
0
 def test_negative_zero(self):
     expected = '0x8000000000000000'
     result = double_to_hex(-0.0)
     assert result == expected
示例#9
0
 def test_zero(self):
     expected = '0x0000000000000000'
     result = double_to_hex(0.0)
     assert result == expected
示例#10
0
 def test_negative_inf(self):
     expected = '0xfff0000000000000'
     result = double_to_hex(-float('inf'))
     assert result == expected
示例#11
0
 def test_inf(self):
     expected = '0x7ff0000000000000'
     result = double_to_hex(float('inf'))
     assert result == expected
示例#12
0
 def test_nan(self):
     round_tripped = hex_to_double(double_to_hex(float('nan')))
     assert math.isnan(round_tripped)
示例#13
0
 def test_negative_zero(self):
     expected = '0x8000000000000000'
     result = double_to_hex(-0.0)
     assert result == expected
示例#14
0
 def test_zero(self):
     expected = '0x0000000000000000'
     result = double_to_hex(0.0)
     assert result == expected