Пример #1
0
def test_verify_probability_defaults_float_to_simple_probability(mocker):
    mocker.patch.object(probability_samplers.SimpleProbability,
                        '__init__',
                        return_value=None)
    probability_samplers.verify_probability(0.5)

    probability_samplers.SimpleProbability.__init__.assert_called_once_with(
        0.5)
Пример #2
0
 def __init__(self,
              modifier: modifiers.Modifier,
              probability: Union[float, int,
                                 probability_samplers.SamplingProbability],
              attribute_filter: filters.Filter = None):
     super().__init__(modifier, attribute_filter)
     self.probability = probability_samplers.verify_probability(probability)
Пример #3
0
def test_verify_probability_check_list_of_probabilities():
    p_list = [
        probability_samplers.HouseholdProbability(0.5),
        probability_samplers.ActivityProbability([''], 0.5),
        probability_samplers.SimpleProbability(0.5), 0.2
    ]
    verified_p_list = probability_samplers.verify_probability(p_list)

    assert p_list[:-1] == verified_p_list[:-1]
    assert isinstance(verified_p_list[-1],
                      probability_samplers.SimpleProbability)
    assert verified_p_list[-1].p(None) == 0.2
Пример #4
0
 def __init__(self, probability):
     super().__init__()
     self.probability = probability_samplers.verify_probability(
         probability, (probability_samplers.HouseholdProbability))