def rule_match_xor(): contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) test("Rule XOR 1", xor_rule.match("world"), True) test("Rule XOR 2", xor_rule.match("help"), True) test("Rule XOR 3", xor_rule.match("hello"), False) test("Rule XOR 4", xor_rule.match("animal"), False)
def rule_match_and(): greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) # between 3 & 10 test("Rule AND 1", and_rule.match(7), True) test("Rule AND 2", and_rule.match(0), False) test("Rule AND 3", and_rule.match(15), False)
def rule_match_not(): not_rule = Rule(RuleType.NOT, Rule(RuleType.IS, 6)) # not 6 test("Rule NOT 1", not_rule.match(3), True) test("Rule NOT 2", not_rule.match(6), False)
def rule_match_contain(): contain_rule = Rule(RuleType.CONTAIN, 'h') # contains letter h test("Rule CONTAIN 1", contain_rule.match("hello"), True) test("Rule CONTAIN 2", contain_rule.match("world"), False)
def rule_match_or(): greater_rule = Rule(RuleType.GREATER, 3) or_rule = Rule(RuleType.OR, [Rule(RuleType.IS, 3), greater_rule]) # >= 3 test("Rule OR 1", or_rule.match(3), True) test("Rule OR 2", or_rule.match(5), True) test("Rule OR 3", or_rule.match(-3), False)
def rule_match_less(): less_rule = Rule(RuleType.LESS, 10) # less than 10 test("Rule LESS 1", less_rule.match(1), True) test("Rule LESS 2", less_rule.match(12), False)
def rule_match_greater(): greater_rule = Rule(RuleType.GREATER, 3) # greater than 3 test("Rule GREATER 1", greater_rule.match(5), True) test("Rule GREATER 2", Rule(RuleType.GREATER, 3).match(1), False)