Exemplo n.º 1
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end
     if start > end:
         raise ValueError(u'Invalid range [%d, %d]' % (start, end))
     self.template_upper_bound = infinitish(end - start + 1)
Exemplo n.º 2
0
 def __init__(self, function, args, kwargs):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__representation = None
     self.__function = function
     self.__args = args
     self.__kwargs = kwargs
Exemplo n.º 3
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end
     if start > end:
         raise ValueError('Invalid range [%d, %d]' % (start, end))
     self.template_upper_bound = infinitish(end - start + 1)
Exemplo n.º 4
0
 def __init__(self, function, args, kwargs):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__representation = None
     self.__function = function
     self.__args = args
     self.__kwargs = kwargs
Exemplo n.º 5
0
 def __init__(self, strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.element_strategies = strategies
     self.template_upper_bound = 1
     for e in self.element_strategies:
         self.template_upper_bound = safe_mul(e.template_upper_bound, self.template_upper_bound)
Exemplo n.º 6
0
 def __init__(self, function, args, kwargs):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__representation = None
     self.__function = function
     self.__args = tuple(map(tupleize, args))
     self.__kwargs = dict((k, tupleize(v)) for k, v in kwargs.items())
Exemplo n.º 7
0
 def __init__(self, strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.element_strategies = strategies
     self.template_upper_bound = 1
     for e in self.element_strategies:
         self.template_upper_bound = safe_mul(e.template_upper_bound,
                                              self.template_upper_bound)
Exemplo n.º 8
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     if not self.elements:
         raise ValueError(
             'SampledFromStrategy requires at least one element')
     self.size_lower_bound = len(elements)
     self.size_upper_bound = len(elements)
Exemplo n.º 9
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end
     if start > end:
         raise ValueError('Invalid range [%d, %d]' % (start, end))
     self.size_lower_bound = end - start + 1
     self.size_upper_bound = end - start + 1
Exemplo n.º 10
0
 def __init__(self, function, args, kwargs):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__representation = None
     self.__function = function
     self.__args = tuple(map(tupleize, args))
     self.__kwargs = dict(
         (k, tupleize(v)) for k, v in kwargs.items()
     )
Exemplo n.º 11
0
 def __init__(self, elements, min_size=0, max_size=float('inf')):
     SearchStrategy.__init__(self)
     self.min_size = min_size or 0
     self.max_size = max_size if max_size is not None else float('inf')
     assert 0 <= self.min_size <= self.max_size
     self.average_size = min(
         max(self.min_size * 2, self.min_size + 5),
         0.5 * (self.min_size + self.max_size),
     )
     self.element_strategy = elements
Exemplo n.º 12
0
 def __init__(self, lower_bound, upper_bound, width):
     SearchStrategy.__init__(self)
     assert isinstance(lower_bound, float)
     assert isinstance(upper_bound, float)
     assert 0 <= lower_bound < upper_bound
     assert math.copysign(1, lower_bound) == 1, "lower bound may not be -0.0"
     assert width in (16, 32, 64)
     self.lower_bound = lower_bound
     self.upper_bound = upper_bound
     self.width = width
Exemplo n.º 13
0
 def __init__(self, elements, min_size=0, max_size=float("inf")):
     SearchStrategy.__init__(self)
     self.min_size = min_size or 0
     self.max_size = max_size if max_size is not None else float("inf")
     assert 0 <= self.min_size <= self.max_size
     self.average_size = min(
         max(self.min_size * 2, self.min_size + 5),
         0.5 * (self.min_size + self.max_size),
     )
     self.element_strategy = elements
Exemplo n.º 14
0
 def __init__(self, elements, min_size=0, max_size=float('inf')):
     SearchStrategy.__init__(self)
     self.min_size = min_size or 0
     self.max_size = max_size or float('inf')
     assert 0 <= min_size <= max_size
     self.average_size = min(
         max(self.min_size * 2, self.min_size + 5),
         0.5 * (self.min_size + self.max_size),
     )
     self.element_strategy = elements
Exemplo n.º 15
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     try:
         s = set(self.elements)
         self.size_lower_bound = len(s)
         self.size_upper_bound = len(s)
     except TypeError:
         self.size_lower_bound = len(self.elements)
         self.size_upper_bound = len(self.elements)
Exemplo n.º 16
0
 def __init__(self, strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.tuple_type = tuple_type
     self.element_strategies = strategies
     self.size_lower_bound = 1
     self.size_upper_bound = 1
     for e in self.element_strategies:
         self.size_lower_bound *= e.size_lower_bound
         self.size_upper_bound *= e.size_upper_bound
Exemplo n.º 17
0
    def __init__(self, lower_bound, upper_bound):
        SearchStrategy.__init__(self)
        self.lower_bound = float(lower_bound)
        self.upper_bound = float(upper_bound)
        lb = float_order_key(self.lower_bound)
        ub = float_order_key(self.upper_bound)

        self.critical = [z for z in (-0.0, 0.0) if lb <= float_order_key(z) <= ub]
        self.critical.append(self.lower_bound)
        self.critical.append(self.upper_bound)
Exemplo n.º 18
0
    def __init__(self, allow_infinity, allow_nan):
        SearchStrategy.__init__(self)
        assert isinstance(allow_infinity, bool)
        assert isinstance(allow_nan, bool)
        self.allow_infinity = allow_infinity
        self.allow_nan = allow_nan

        self.nasty_floats = [f for f in NASTY_FLOATS if self.permitted(f)]
        weights = [0.2 * len(self.nasty_floats)] + [0.8] * len(self.nasty_floats)
        self.sampler = d.Sampler(weights)
Exemplo n.º 19
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end
     if start > end:
         raise ValueError('Invalid range [%d, %d]' % (start, end))
     self.size_lower_bound = end - start + 1
     if self.size_lower_bound >= EFFECTIVELY_INFINITE:
         self.size_lower_bound = float('inf')
     self.size_upper_bound = self.size_lower_bound
Exemplo n.º 20
0
    def __init__(self, strategies, average_length=50.0):
        SearchStrategy.__init__(self)

        self.average_length = average_length
        strategies = tuple(strategies)
        if strategies:
            self.element_strategy = one_of_strategies(strategies)
        else:
            self.element_strategy = None
            self.size_upper_bound = 1
            self.size_lower_bound = 1
Exemplo n.º 21
0
 def __init__(self,
              strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.tuple_type = tuple_type
     self.element_strategies = strategies
     self.size_lower_bound = 1
     self.size_upper_bound = 1
     for e in self.element_strategies:
         self.size_lower_bound *= e.size_lower_bound
         self.size_upper_bound *= e.size_upper_bound
Exemplo n.º 22
0
    def __init__(self, lower_bound, upper_bound):
        SearchStrategy.__init__(self)
        self.lower_bound = float(lower_bound)
        self.upper_bound = float(upper_bound)
        assert not math.isinf(self.upper_bound - self.lower_bound)
        lb = float_order_key(self.lower_bound)
        ub = float_order_key(self.upper_bound)

        self.critical = [z for z in (-0.0, 0.0) if lb <= float_order_key(z) <= ub]
        self.critical.append(self.lower_bound)
        self.critical.append(self.upper_bound)
Exemplo n.º 23
0
    def __init__(self,
                 strategies, average_length=50.0):
        SearchStrategy.__init__(self)

        self.average_length = average_length
        strategies = tuple(strategies)
        if strategies:
            self.element_strategy = one_of_strategies(strategies)
        else:
            self.element_strategy = None
            self.size_upper_bound = 1
            self.size_lower_bound = 1
Exemplo n.º 24
0
    def __init__(
        self,
        strategies, average_length=50.0, min_size=0, max_size=float('inf')
    ):
        SearchStrategy.__init__(self)

        assert average_length > 0
        self.average_length = average_length
        strategies = tuple(strategies)
        self.min_size = min_size or 0
        self.max_size = max_size or float('inf')
        self.element_strategy = one_of_strategies(strategies)
Exemplo n.º 25
0
    def __init__(
        self,
        strategies, average_length=50.0, min_size=0, max_size=float('inf')
    ):
        SearchStrategy.__init__(self)

        assert average_length > 0
        self.average_length = average_length
        strategies = tuple(strategies)
        self.min_size = min_size or 0
        self.max_size = max_size or float('inf')
        self.element_strategy = one_of_strategies(strategies)
Exemplo n.º 26
0
    def __init__(self, strategies, average_length=50.0, min_size=0, max_size=float("inf")):
        SearchStrategy.__init__(self)

        assert average_length > 0
        self.average_length = average_length
        strategies = tuple(strategies)
        self.min_size = min_size or 0
        self.max_size = max_size
        if strategies:
            self.element_strategy = one_of_strategies(strategies)
        else:
            self.element_strategy = None
            self.template_upper_bound = 1
Exemplo n.º 27
0
    def __init__(self, allow_infinity, allow_nan, width):
        SearchStrategy.__init__(self)
        assert isinstance(allow_infinity, bool)
        assert isinstance(allow_nan, bool)
        assert width in (16, 32, 64)
        self.allow_infinity = allow_infinity
        self.allow_nan = allow_nan
        self.width = width

        self.nasty_floats = [
            float_of(f, self.width) for f in NASTY_FLOATS if self.permitted(f)
        ]
        weights = [0.2 * len(self.nasty_floats)] + [0.8] * len(self.nasty_floats)
        self.sampler = d.Sampler(weights)
Exemplo n.º 28
0
    def __init__(self, machine):
        SearchStrategy.__init__(self)
        self.machine = machine
        self.rules = list(machine.rules())

        # The order is a bit arbitrary. Primarily we're trying to group rules
        # that write to the same location together, and to put rules with no
        # target first as they have less effect on the structure. We order from
        # fewer to more arguments on grounds that it will plausibly need less
        # data. This probably won't work especially well and we could be
        # smarter about it, but it's better than just doing it in definition
        # order.
        self.rules.sort(key=lambda rule: (
            sorted(rule.targets), len(rule.arguments),
            rule.function.__name__,
        ))
Exemplo n.º 29
0
    def __init__(
        self,
        strategies, average_length=50.0, min_size=0, max_size=float(u'inf')
    ):
        SearchStrategy.__init__(self)

        assert average_length > 0
        self.average_length = average_length
        strategies = tuple(strategies)
        self.min_size = min_size or 0
        self.max_size = max_size
        if strategies:
            self.element_strategy = one_of_strategies(strategies)
        else:
            self.element_strategy = None
            self.template_upper_bound = 1
Exemplo n.º 30
0
    def __init__(self, machine):
        SearchStrategy.__init__(self)
        self.machine = machine
        self.rules = list(machine.rules())

        # The order is a bit arbitrary. Primarily we're trying to group rules
        # that write to the same location together, and to put rules with no
        # target first as they have less effect on the structure. We order from
        # fewer to more arguments on grounds that it will plausibly need less
        # data. This probably won't work especially well and we could be
        # smarter about it, but it's better than just doing it in definition
        # order.
        self.rules.sort(key=lambda rule: (
            sorted(rule.targets),
            len(rule.arguments),
            rule.function.__name__,
        ))
Exemplo n.º 31
0
 def __init__(self, value):
     SearchStrategy.__init__(self)
     self.value = value
Exemplo n.º 32
0
 def __init__(self, strategy):
     SearchStrategy.__init__(self)
     self.wrapped_strategy = strategy
Exemplo n.º 33
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end
Exemplo n.º 34
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = d.check_sample(elements)
     assert self.elements
Exemplo n.º 35
0
 def __init__(self, strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.element_strategies = strategies
Exemplo n.º 36
0
 def __init__(self, definition):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__in_repr = False
     self.__is_empty = None
     self.__definition = definition
Exemplo n.º 37
0
 def __init__(self):
     SearchStrategy.__init__(self)
     self.int_strategy = RandomGeometricIntStrategy()
Exemplo n.º 38
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     self.template_upper_bound = len(self.elements)
     assert self.elements
Exemplo n.º 39
0
 def __init__(self,
              strategies, tuple_type):
     SearchStrategy.__init__(self)
     strategies = tuple(strategies)
     self.element_strategies = strategies
Exemplo n.º 40
0
 def __init__(self, strategy):
     SearchStrategy.__init__(self)
     self.wrapped_strategy = strategy
     self.template_upper_bound = self.wrapped_strategy.template_upper_bound
Exemplo n.º 41
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     self.template_upper_bound = len(self.elements)
     assert self.elements
Exemplo n.º 42
0
 def __init__(self, value):
     SearchStrategy.__init__(self)
     self.value = value
Exemplo n.º 43
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     assert self.elements
Exemplo n.º 44
0
 def __init__(self, strategy):
     SearchStrategy.__init__(self)
     self.wrapped_strategy = strategy
Exemplo n.º 45
0
 def __init__(self, allow_infinity, allow_nan):
     SearchStrategy.__init__(self)
     assert isinstance(allow_infinity, bool)
     assert isinstance(allow_nan, bool)
     self.allow_infinity = allow_infinity
     self.allow_nan = allow_nan
Exemplo n.º 46
0
 def __init__(self, lower_bound, upper_bound):
     SearchStrategy.__init__(self)
     self.lower_bound = float(lower_bound)
     self.upper_bound = float(upper_bound)
Exemplo n.º 47
0
 def __init__(self, definition):
     SearchStrategy.__init__(self)
     self.__wrapped_strategy = None
     self.__in_repr = False
     self.__is_empty = None
     self.__definition = definition
Exemplo n.º 48
0
 def __init__(self):
     SearchStrategy.__init__(self)
     self.int_strategy = RandomGeometricIntStrategy()
Exemplo n.º 49
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = d.check_sample(elements, 'sampled_from')
     assert self.elements
Exemplo n.º 50
0
 def __init__(self, allow_infinity, allow_nan):
     SearchStrategy.__init__(self)
     assert isinstance(allow_infinity, bool)
     assert isinstance(allow_nan, bool)
     self.allow_infinity = allow_infinity
     self.allow_nan = allow_nan
Exemplo n.º 51
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = tuple(elements)
     assert self.elements
Exemplo n.º 52
0
 def __init__(self, lower_bound, upper_bound):
     SearchStrategy.__init__(self)
     self.lower_bound = float(lower_bound)
     self.upper_bound = float(upper_bound)
Exemplo n.º 53
0
 def __init__(self, start, end):
     SearchStrategy.__init__(self)
     self.start = start
     self.end = end