Esempio n. 1
0
 def do_draw(self, data):
     f = self.lower_bound + (
         self.upper_bound - self.lower_bound) * d.fractional_float(data)
     assume(self.lower_bound <= f <= self.upper_bound)
     assume(sign(self.lower_bound) <= sign(f) <= sign(self.upper_bound))
     # Special handling for bounds of -0.0
     for g in [self.lower_bound, self.upper_bound]:
         if f == g:
             f = math.copysign(f, g)
     return f
Esempio n. 2
0
    def do_draw(self, data):
        def draw_float_bytes(random, n):
            assert n == 8
            i = random.randint(0, 20)
            if i <= 2:
                f = random.choice(self.critical)
            else:
                f = random.random() * (self.upper_bound - self.lower_bound) + self.lower_bound
            return struct.pack(b"!d", f)

        f = struct.unpack(b"!d", bytes(data.draw_bytes(8, draw_float_bytes)))[0]
        assume(self.lower_bound <= f <= self.upper_bound)
        assume(sign(self.lower_bound) <= sign(f) <= sign(self.upper_bound))
        return f
Esempio n. 3
0
    def do_draw(self, data):
        def draw_float_bytes(random, n):
            assert n == 8
            i = random.randint(0, 20)
            if i <= 2:
                f = random.choice(self.critical)
            else:
                f = random.random() * (self.upper_bound -
                                       self.lower_bound) + self.lower_bound
            return struct.pack(b'!d', f)

        f = struct.unpack(b'!d', bytes(data.draw_bytes(8,
                                                       draw_float_bytes)))[0]
        assume(self.lower_bound <= f <= self.upper_bound)
        assume(sign(self.lower_bound) <= sign(f) <= sign(self.upper_bound))
        return f
Esempio n. 4
0
def float_order_key(k):
    return (sign(k), k)
def float_order_key(k):
    return (sign(k), k)
def test_sign_gives_good_type_error():
    x = 'foo'
    with pytest.raises(TypeError) as e:
        sign(x)
    assert repr(x) in e.value.args[0]
def test_sign_gives_good_type_error():
    x = 'foo'
    with pytest.raises(TypeError) as e:
        sign(x)
    assert repr(x) in e.value.args[0]