def test_tries_each_parameter_at_least_min_index_times(): source = ParameterSource(context=BuildContext(random.Random()), strategy=strategy(int), min_tries=5) i = 0 for x in source.examples(): i += 1 if i > 500: break if i % 2: source.mark_bad() # The last index may not have been fully populated assert all(c >= 5 for c in source.counts[:-1])
def test_negative_is_not_too_far_off_mean(): source = ParameterSource( random=random.Random(), strategy=integers(), ) positive = 0 i = 0 for example in source.examples(): if example >= 0: positive += 1 i += 1 if i >= N_EXAMPLES: break assert 0.3 <= float(positive) / N_EXAMPLES <= 0.7
def test_tries_each_parameter_at_least_min_index_times(): source = ParameterSource( context=BuildContext(random.Random()), strategy=strategy(int), min_tries=5 ) i = 0 for x in source.examples(): i += 1 if i > 500: break if i % 2: source.mark_bad() # The last index may not have been fully populated assert all(c >= 5 for c in source.counts[:-1])
def test_marking_negative_avoids_similar_examples(): positive = 0 k = 10 for _ in hrange(k): source = ParameterSource( random=random.Random(), strategy=integers(), ) n = N_EXAMPLES // k for example in islice(source.examples(), n): if example >= 0: positive += 1 else: source.mark_bad() assert float(positive) / N_EXAMPLES >= 0.7
def test_marking_negative_avoids_similar_examples(): source = ParameterSource( context=BuildContext(random.Random()), strategy=strategy(int), ) positive = 0 i = 0 for example in source.examples(): if example >= 0: positive += 1 else: source.mark_bad() i += 1 if i >= N_EXAMPLES: break assert float(positive) / N_EXAMPLES >= 0.8
def test_marking_negative_avoids_similar_examples(): source = ParameterSource( context=BuildContext(random.Random()), strategy=strategy(int), ) positive = 0 i = 0 for example in source.examples(): if example >= 0: positive += 1 else: source.mark_bad() i += 1 if i >= N_EXAMPLES: break assert float(positive) / N_EXAMPLES >= 0.8
def test_can_grow_the_set_of_available_parameters_if_doing_badly(): runs = 10 number_grown = 0 for _ in hrange(runs): source = ParameterSource( context=BuildContext(random.Random()), strategy=strategy(int), min_parameters=1, ) i = 0 for example in source.examples(): if example < 0: source.mark_bad() i += 1 if i >= 100: break if len(source.parameters) > 1: number_grown += 1 assert len(source.parameters) < 100
def test_can_grow_the_set_of_available_parameters_if_doing_badly(): runs = 10 number_grown = 0 for _ in hrange(runs): source = ParameterSource( context=BuildContext(random.Random()), strategy=strategy(int), min_parameters=1, ) i = 0 for example in source.examples(): if example < 0: source.mark_bad() i += 1 if i >= 100: break if len(source.parameters) > 1: number_grown += 1 assert len(source.parameters) < 100