예제 #1
0
 def test_round_trip(self):
     test_data = [struct.unpack('<f', os.urandom(4))[0]
                  for _ in range(1000)]
     for value in test_data:
         round_tripped = hex_to_float(float_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 = [
         _pad_to(hex(struct.unpack('<I', os.urandom(4))[0]), 8)
         for _ in range(1000)]
     for value in test_data:
         fromhex = hex_to_float(value)
         if math.isnan(fromhex):
             continue
         round_tripped = float_to_hex(fromhex)
         assert round_tripped == value
예제 #3
0
 def test_negative_inf(self):
     result = hex_to_float('0xff800000')
     assert math.isinf(result)
     assert result < 0
예제 #4
0
 def test_inf(self):
     result = hex_to_float('0x7f800000')
     assert math.isinf(result)
     assert result > 0
예제 #5
0
 def test_nan(self):
     result = hex_to_float('0x7f800001')
     assert math.isnan(result)
예제 #6
0
 def test_negative_zero(self):
     expected = -0.0
     result = hex_to_float('0x80000000')
     assert result == expected
예제 #7
0
 def test_zero(self):
     expected = 0.0
     result = hex_to_float('0x00000000')
     assert result == expected
예제 #8
0
 def test_nan(self):
     round_tripped = hex_to_float(float_to_hex(float('nan')))
     assert math.isnan(round_tripped)