-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdip_test.py
More file actions
47 lines (38 loc) · 1.5 KB
/
dip_test.py
File metadata and controls
47 lines (38 loc) · 1.5 KB
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
"""Demonstrate Dependency Inversion Principle."""
from dip.dip_common import Person
from dip.dip_violate import Relationships as VRelationships
from dip.dip_violate import Research as VResearch
from dip.dip_comply import Relationships as CRelationships
from dip.dip_comply import Research as CResearch
def test_violate_research_on() -> None:
"""Verify `Research` while in violation of DIP."""
parent = Person("Jayamma")
child_1 = Person("Adedayo")
child_2 = Person("Abebi")
grandparent = Person("Kwento")
relationships = VRelationships()
relationships.add(parent, child_1)
relationships.add(parent, child_2)
relationships.add(grandparent, parent)
research = VResearch(relationships)
assert list(research.report_on("Jayamma")) == [
"Jayamma is a parent of Adedayo",
"Jayamma is a parent of Abebi",
"Jayamma is a child of Kwento",
]
def test_comply_research_on() -> None:
"""Verify `Research` works after being refactored to comply with DIP."""
parent = Person("Jayamma")
child_1 = Person("Adedayo")
child_2 = Person("Abebi")
grandparent = Person("Kwento")
relationships = CRelationships()
relationships.add(parent, child_1)
relationships.add(parent, child_2)
relationships.add(grandparent, parent)
research = CResearch(relationships)
assert list(research.report_on("Jayamma")) == [
"Jayamma is a parent of Adedayo",
"Jayamma is a parent of Abebi",
"Jayamma is a child of Kwento",
]