Exemple #1
0
 def test_nested_bytes_when_class_is_float(self, obj):
     float_obj = Float(bytes(obj))
     # NaN has several different binary representations.
     assume(not math.isnan(float_obj.value))
     bytes1 = bytes(obj)
     bytes2 = bytes(float_obj)
     self.assertEqual(bytes1, bytes2)
Exemple #2
0
    def test_negative_bits_raises_ValueError_for_float_from_int(
            self, x_and_bits, negative_bits):

        x, _ = x_and_bits
        assume(not math.isnan(x) and not math.isinf(x))
        i = int(x)

        with self.assertRaises(ValueError):
            Float(i, negative_bits)
Exemple #3
0
    def test_invalid_bits_raises_ValueError_for_float_from_int(
            self, x_and_bits):
        x, bits = x_and_bits
        # x must be a numerical value so that it can be converted to int.
        assume(not math.isnan(x) and not math.isinf(x))
        i = int(x)

        with self.assertRaises(ValueError):
            Float(i, bits)
Exemple #4
0
    def test_float_from_int_sets_attributes_correctly(self, x_and_bits):
        x, bits = x_and_bits
        # x must be a numerical value so that it can be converted to int.
        assume(not math.isnan(x) and not math.isinf(x))
        i = int(x)
        float_ = Float(i, bits)

        self.assertEqual(float_.value, i)
        self.assertEqual(float_.bits, 32)
Exemple #5
0
    def test_float_from_float_sets_attributes_correctly(self, x_and_bits):
        x, bits = x_and_bits
        float_ = Float(x, bits)

        if math.isnan(x):
            self.assertTrue(math.isnan(float_.value))
        else:
            self.assertEqual(float_.value, x)

        self.assertEqual(float_.bits, 32)
Exemple #6
0
 def test_default_float(self):
     parameter = dummy_parameter_from_line(
         default='1.2e3', format_='real32')
     self.assertEqual(parameter.default, Float(1.2e3))
Exemple #7
0
 def test_min_max_float(self):
     parameter = dummy_parameter_from_line(
         min_value='-1.23e-4', max_value='4.56e7', format_='real32')
     self.assertEqual(parameter.min_value, Float(-1.23e-4))
     self.assertEqual(parameter.max_value, Float(4.56e7))
Exemple #8
0
 def test_float_with_too_large_value_raises_ValueError(self):
     with self.assertRaises(ValueError):
         Float(1E50)
     with self.assertRaises(ValueError):
         Float(-1E50)
Exemple #9
0
 def test_bits_default_value(self):
     self.assertEqual(Uint(1).bits, 8)
     self.assertEqual(Sint(-1).bits, 8)
     self.assertEqual(Float(1.0).bits, 32)
     self.assertEqual(Float(1).bits, 32)
     self.assertEqual(Bin(1).bits, 8)
Exemple #10
0
 def test_float_sets_small_value_to_0(self):
     self.assertEqual(Float(1E-50).value, 0)
     self.assertEqual(Float(-1E-50).value, 0)