def test_should_increase_quality(self, cfg): # given cl = Classifier(cfg=cfg) assert cl.q == 0.5 # when cl.increase_quality() # then assert cl.q == 0.525
def expected_case(cl: Classifier, p0: Perception, time: int) -> Optional[Classifier]: diff = cl.mark.get_differences(p0) if diff.specificity == 0: cl.increase_quality() return None no_spec = len(cl.specified_unchanging_attributes) no_spec_new = diff.specificity child = cl.copy_from(cl, time) if no_spec >= cl.cfg.u_max: while no_spec >= cl.cfg.u_max: res = cl.generalize_unchanging_condition_attribute() assert res is True no_spec -= 1 while no_spec + no_spec_new > cl.cfg.u_max: if random.random() < 0.5: diff.generalize_specific_attribute_randomly() no_spec_new -= 1 else: if cl.generalize_unchanging_condition_attribute(): no_spec -= 1 else: while no_spec + no_spec_new > cl.cfg.u_max: diff.generalize_specific_attribute_randomly() no_spec_new -= 1 child.condition.specialize_with_condition(diff) if child.q < 0.5: child.q = 0.5 return child