Esempio n. 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:
         round_tripped = bin_to_double(double_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('<Q', os.urandom(8))[0]), 64)
         for _ in range(1000)]
     for value in test_data:
         frombin = bin_to_double(value)
         if math.isnan(frombin):
             continue
         round_tripped = double_to_bin(frombin)
         assert round_tripped == value
Esempio n. 3
0
 def test_negative_inf(self):
     expected = '0b1111111111110000000000000000000000000000000000000000000000000000'
     result = double_to_bin(-float('inf'))
     assert result == expected
Esempio n. 4
0
 def test_inf(self):
     expected = '0b0111111111110000000000000000000000000000000000000000000000000000'
     result = double_to_bin(float('inf'))
     assert result == expected
Esempio n. 5
0
 def test_nan(self):
     round_tripped = bin_to_double(double_to_bin(float('nan')))
     assert math.isnan(round_tripped)
Esempio n. 6
0
 def test_negative_zero(self):
     expected = '0b1000000000000000000000000000000000000000000000000000000000000000'
     result = double_to_bin(-0.0)
     assert result == expected
Esempio n. 7
0
 def test_zero(self):
     expected = '0b0000000000000000000000000000000000000000000000000000000000000000'
     result = double_to_bin(0.0)
     assert result == expected