Esempio n. 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 = bin_to_float(float_to_bin(value))
         if math.isnan(value):
             assert math.isnan(round_tripped)
         else:
             assert round_tripped == value
Esempio n. 2
0
 def test_round_trip(self):
     test_data = [
         _pad_to(bin(struct.unpack('<I', os.urandom(4))[0]), 32)
         for _ in range(1000)]
     for value in test_data:
         frombin = bin_to_float(value)
         if math.isnan(frombin):
             continue
         round_tripped = float_to_bin(frombin)
         assert round_tripped == value
Esempio n. 3
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 = bin_to_float(float_to_bin(value))
         if math.isnan(value):
             assert math.isnan(round_tripped)
         else:
             assert round_tripped == value
Esempio n. 4
0
 def test_round_trip(self):
     test_data = [
         _pad_to(bin(struct.unpack('<I', os.urandom(4))[0]), 32)
         for _ in range(1000)
     ]
     for value in test_data:
         frombin = bin_to_float(value)
         if math.isnan(frombin):
             continue
         round_tripped = float_to_bin(frombin)
         assert round_tripped == value
Esempio n. 5
0
 def test_negative_inf(self):
     expected = '0b11111111100000000000000000000000'
     result = float_to_bin(-float('inf'))
     assert result == expected
Esempio n. 6
0
 def test_inf(self):
     expected = '0b01111111100000000000000000000000'
     result = float_to_bin(float('inf'))
     assert result == expected
Esempio n. 7
0
 def test_nan(self):
     round_tripped = bin_to_float(float_to_bin(float('nan')))
     assert math.isnan(round_tripped)
Esempio n. 8
0
 def test_negative_zero(self):
     expected = '0b10000000000000000000000000000000'
     result = float_to_bin(-0.0)
     assert result == expected
Esempio n. 9
0
 def test_zero(self):
     expected = '0b00000000000000000000000000000000'
     result = float_to_bin(0.0)
     assert result == expected
Esempio n. 10
0
 def test_negative_inf(self):
     expected = '0b11111111100000000000000000000000'
     result = float_to_bin(-float('inf'))
     assert result == expected
Esempio n. 11
0
 def test_inf(self):
     expected = '0b01111111100000000000000000000000'
     result = float_to_bin(float('inf'))
     assert result == expected
Esempio n. 12
0
 def test_nan(self):
     round_tripped = bin_to_float(float_to_bin(float('nan')))
     assert math.isnan(round_tripped)
Esempio n. 13
0
 def test_negative_zero(self):
     expected = '0b10000000000000000000000000000000'
     result = float_to_bin(-0.0)
     assert result == expected
Esempio n. 14
0
 def test_zero(self):
     expected = '0b00000000000000000000000000000000'
     result = float_to_bin(0.0)
     assert result == expected