def draw_parameter(self, random): return self.Parameter( p_hour=dist.uniform_float(random, 0, 1), p_minute=dist.uniform_float(random, 0, 1), p_second=dist.uniform_float(random, 0, 1), month=dist.non_empty_subset(random, list(range(1, 13))), naive_chance=dist.uniform_float(random, 0, 0.5), timezones=self.timezones and dist.non_empty_subset(random, self.timezones), )
def produce_parameter(self, random): return self.Parameter( p_hour=dist.uniform_float(random, 0, 1), p_minute=dist.uniform_float(random, 0, 1), p_second=dist.uniform_float(random, 0, 1), month=dist.non_empty_subset(random, list(range(1, 13))), naive_chance=dist.uniform_float(random, 0, 0.5), utc_chance=dist.uniform_float(random, 0, 1), timezones=dist.non_empty_subset( random, list(map(pytz.timezone, pytz.all_timezones))), naive_options=dist.non_empty_subset(random, self.naive_options))
def draw_parameter(self, random): locales = dist.non_empty_subset(random, self.locales) n = 1 + geometric(random, 0.1) return [ self.gen_example(random, locales) for _ in hrange(n) ]
def produce_parameter(self, random): return self.Parameter( p_hour=dist.uniform_float(random, 0, 1), p_minute=dist.uniform_float(random, 0, 1), p_second=dist.uniform_float(random, 0, 1), month=dist.non_empty_subset(random, list(range(1, 13))), naive_chance=dist.uniform_float(random, 0, 0.5), utc_chance=dist.uniform_float(random, 0, 1), timezones=dist.non_empty_subset( random, list( map(pytz.timezone, pytz.all_timezones)) ), naive_options=dist.non_empty_subset(random, self.naive_options ) )
def produce_parameter(self, random): indices = list(range(len(self.element_strategies))) enabled = dist.non_empty_subset(random, indices, activation_chance=(1.0 / len(indices))) return self.Parameter( enabled_children=enabled, child_parameters=[ self.element_strategies[i].draw_parameter(random) if i in enabled else None for i in indices ])
def produce_parameter(self, random): indices = list(range(len(self.element_strategies))) enabled = dist.non_empty_subset( random, indices, ) return self.Parameter( enabled_children=enabled, child_parameters=[ self.element_strategies[i].draw_parameter(random) if i in enabled else None for i in indices ] )
def test_non_empty_of_empty_errors(): with pytest.raises(ValueError): dist.non_empty_subset(random, [])
def produce_parameter(self, random): return dist.non_empty_subset( random, tuple(range(self.start, self.end + 1)), activation_chance=min(0.5, 3.0 / (self.end - self.start + 1)) )
def test_non_empty_of_10(): assert dist.non_empty_subset(random, range(10))
def test_non_empty_of_one_always_returns_it(): assert dist.non_empty_subset(random, [1]) == [1] assert dist.non_empty_subset(random, [2]) == [2]
def test_non_empty_of_three(): assert dist.non_empty_subset(random, [1, 2, 3])
def produce_parameter(self, random): return dist.non_empty_subset(random, range(len(self.elements)))
def test_non_empty_with_explicit_activation_chance(): assert len( dist.non_empty_subset(random, range(100), activation_chance=0.99)) > 2
def draw_parameter(self, random): return dist.non_empty_subset(random, self.locales)
def produce_parameter(self, random): return dist.non_empty_subset(random, self.locales)
def test_non_empty_with_explicit_activation_chance(): assert len(dist.non_empty_subset( random, range(100), activation_chance=0.99)) > 2