コード例 #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
コード例 #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
コード例 #3
0
 def test_negative_inf(self):
     result = bin_to_double('0b1111111111110000000000000000000000000000000000000000000000000000')
     assert math.isinf(result)
     assert result < 0
コード例 #4
0
 def test_inf(self):
     result = bin_to_double('0b0111111111110000000000000000000000000000000000000000000000000000')
     assert math.isinf(result)
     assert result > 0
コード例 #5
0
 def test_nan(self):
     result = bin_to_double('0b0111111111110000000000000000000000000000000000000000000000000001')
     assert math.isnan(result)
コード例 #6
0
 def test_negative_zero(self):
     expected = -0.0
     result = bin_to_double('0b1000000000000000000000000000000000000000000000000000000000000000')
     assert result == expected
コード例 #7
0
 def test_zero(self):
     expected = 0.0
     result = bin_to_double('0b0000000000000000000000000000000000000000000000000000000000000000')
     assert result == expected
コード例 #8
0
 def test_nan(self):
     round_tripped = bin_to_double(double_to_bin(float('nan')))
     assert math.isnan(round_tripped)