-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_simple_rule_engine_dict_adapter.py
48 lines (32 loc) · 1.93 KB
/
test_simple_rule_engine_dict_adapter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from unittest import TestCase
from services.adapter.simple_rule_engine_dict_adapter import SimpleRuleEngineDictAdapter
from services.util.json_file_util import JsonFileUtil
class TestSimpleRuleEngineAdapter(TestCase):
def test_rule_simple_decision(self):
json_file_util = JsonFileUtil(file_name_with_path="./examples/simple_decision.json")
decision_rule_dict = json_file_util.read_file()
rule_engine_adapter = SimpleRuleEngineDictAdapter(rule_dict=decision_rule_dict)
decision_rule = rule_engine_adapter.get_rule()
assert type(decision_rule).__name__ == "RuleDecision"
fact = dict(cibil_score=700, business_ownership="Owned by Self")
assert decision_rule.execute(token_dict=fact) == "GO"
def test_rule_simple_decision_when_any(self):
json_file_util = JsonFileUtil(file_name_with_path="./examples/simple_decision_when_any.json")
decision_rule_dict = json_file_util.read_file()
rule_engine_adapter = SimpleRuleEngineDictAdapter(rule_dict=decision_rule_dict)
decision_rule = rule_engine_adapter.get_rule()
assert type(decision_rule).__name__ == "RuleDecision"
fact = dict(age=35, pet="parrot")
assert decision_rule.execute(token_dict=fact) == "GO"
fact = dict(age=20, pet="dog")
assert decision_rule.execute(token_dict=fact) != "GO"
def test_rule_simple_score(self):
json_file_util = JsonFileUtil(file_name_with_path="./examples/simple_score.json")
score_rule_dict = json_file_util.read_file()
rule_engine_adapter = SimpleRuleEngineDictAdapter(rule_dict=score_rule_dict)
score_rule = rule_engine_adapter.get_rule()
assert type(score_rule).__name__ == "RuleScore"
fact = dict(age=40, pet="dog", domicile="TN")
assert score_rule.execute(token_dict=fact) == 5.0
fact = dict(age=40, pet="dog", domicile="KA")
assert score_rule.execute(token_dict=fact) == 7.5