def test_obtain_employees() -> None: o = Organization() e1 = Leader(1, 'Holly', '', 1, 1, 'Department') o.add_employee(e1) e2 = Employee(2, 'Ivan', '', 1, 1) o.add_employee(e2, 1) e3 = Employee(3, 'Kevin', '', 1, 1) o.add_employee(e3, 2) e4 = Employee(4, 'Joe', 'Mama', 1, 100) o.add_employee(e4, 2) e5 = Employee(5, 'Linda', '', 1, 1) o.add_employee(e5, 4) assert e1.get_direct_subordinates() == [e2] assert e2.get_superior() == e1 assert e2.get_direct_subordinates() == [e3, e4] assert e3.get_superior() == e2 assert e4.get_superior() == e2 assert e3.get_direct_subordinates() == [] assert e4.get_direct_subordinates() == [e5] assert e5.get_superior() == e4 e4.obtain_subordinates([2]) assert o.get_head() == e1 assert e1.get_direct_subordinates() == [e3, e4] assert e3.get_superior() == e1 assert e4.get_superior() == e1 assert e3.get_direct_subordinates() == [] assert e4.get_direct_subordinates() == [e2, e5] assert e2.get_superior() == e4 assert e5.get_superior() == e4
def test_remove_subordinate_id() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e1.become_subordinate(e2) assert e2.get_direct_subordinates()[0].eid == 1 e2.remove_subordinate_id(1) assert e2.get_direct_subordinates() == [] assert e1.get_superior() is e2
def test_become_subordinate() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e1.become_subordinate(e2) assert e1.get_superior().eid == 2 assert e2.get_direct_subordinates()[0].eid == 1 e1.become_subordinate(None) assert e1.get_superior() is None assert e2.get_direct_subordinates() == []
def test_direct_subs() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Employee(3, "Cowor Ker", "Worker", 10000, 50) assert e2.get_direct_subordinates() == [] e3.become_subordinate(e2) e1.become_subordinate(e2) lst = e2.get_direct_subordinates() assert len(lst) == 2 assert lst[0].eid == 1 assert lst[1].eid == 3
def test_become_sub() -> None: e1 = Employee(1, "Boss", "CEO", 50000, 50) assert e1.get_superior() is None e2 = Employee(2, "Sue", "Manager", 20000, 50) e2.become_subordinate(e1) assert e2.get_superior().eid == 1 assert len(e1.get_direct_subordinates()) == 1 e3 = Employee(3, "Emma", "Worker", 10000, 50) e3.become_subordinate(e2) assert e3.get_superior().eid == 2 assert len(e1.get_direct_subordinates()) == 1 assert len(e1.get_all_subordinates()) == 2
def test_get_direct_subordinates_advanced() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Employee(3, "Robocop", "Worker", 20000, 30) e4 = Leader(4, "Sarah", "CEO", 20000, 30, "Some Corp.") e5 = Employee(5, "Sofia", "Worker", 20000, 30) e6 = Employee(6, "Terry", "Worker", 20000, 30) e7 = Employee(7, "Odysseus", "Worker", 20000, 30) e1.become_subordinate(e2) e3.become_subordinate(e2) e2.become_subordinate(e4) e5.become_subordinate(e2) e6.become_subordinate(e4) e7.become_subordinate(e4) assert e2.get_direct_subordinates() == [e1, e3, e5] assert e4.get_direct_subordinates() == [e2, e6, e7] assert e1.get_direct_subordinates() == []
def test_line_obtain_subs() -> None: o = Organization() e1 = Employee(1, '', '', 1, 1) o.add_employee(e1) e2 = Employee(2, '', '', 1, 1) o.add_employee(e2, 1) e3 = Employee(3, '', '', 1, 1) o.add_employee(e3, 1) e4 = Employee(4, '', '', 1, 1) o.add_employee(e4, 3) e5 = Employee(5, '', '', 1, 1) o.add_employee(e5, 4) assert e2 in e1.get_direct_subordinates() assert e3 in e1.get_direct_subordinates() assert not e5 in e1.get_direct_subordinates() assert e5 in e1.get_all_subordinates() assert len(e2.get_all_subordinates()) == 0 e2.obtain_subordinates([3, 4]) assert not e3 in e1.get_direct_subordinates() assert e2 in e1.get_direct_subordinates() assert e3 in e2.get_direct_subordinates() assert e4 in e2.get_direct_subordinates() assert e5 in e1.get_direct_subordinates() assert e3 in e2.get_direct_subordinates() assert e4 in e2.get_direct_subordinates()
def test_init() -> None: e = Employee(1, "Emma Ployee", "Worker", 10000, 50) assert e.eid == 1 assert e.name == "Emma Ployee" assert e.position == "Worker" assert e.salary == 10000 assert e.rating == 50 assert e.get_direct_subordinates() == [] assert e.get_superior() is None
def test_remove_sub() -> None: e1 = Employee(5, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(7, "Sue Perior", "Manager", 20000, 30) e3 = Employee(8, "Cowor Ker", "Worker", 10000, 50) e3.become_subordinate(e2) e1.become_subordinate(e2) assert len(e2.get_direct_subordinates()) == 2 e2.remove_subordinate_id(5) assert e1.get_superior() == e2 assert len(e2.get_direct_subordinates()) == 1 e1.become_subordinate(e3) assert len(e2.get_all_subordinates()) == 2 e2.remove_subordinate_id(5) assert len(e2.get_direct_subordinates()) == 1 assert e1.get_superior() == e3 e1.become_subordinate(e3) assert len(e2.get_all_subordinates()) == 2 e2.remove_subordinate_id(8) assert len(e2.get_all_subordinates()) == 0 assert e1.get_superior() == e3
def test_fire_under_tie_simple() -> None: e1 = Employee(1, '', '', 10, 10) e2 = Employee(2, '', '', 10, 20) e3 = Employee(3, '', '', 10, 20) o = Organization() o.add_employee(e1) o.add_employee(e3, 1) o.add_employee(e2, 1) o.fire_under_rating(20) assert o.get_head() == e2 assert e2.get_direct_subordinates() == [e3] assert e3.get_superior() == e2
def test_employee_general() -> None: e1 = Employee(1, "e1", "a", 1, 50) e2 = Employee(2, "e2", "a", 1, 50) e3 = Employee(3, "e3", "a", 1, 50) e4 = Employee(4, "e4", "a", 1, 50) e5 = Employee(5, "e5", "a", 1, 50) e6 = Employee(6, "e6", "a", 1, 50) e7 = Employee(7, "e7", "a", 1, 50) e7.become_subordinate(e5) e5.become_subordinate(e2) e4.become_subordinate(e2) e2.become_subordinate(e1) e3.become_subordinate(e1) e6.become_subordinate(e3) assert e6.get_all_subordinates() == [] assert e2.get_all_subordinates() == [e4, e5, e7] assert e2.get_direct_subordinates() == [e4, e5] assert e7.get_organization_head() == e1 assert e1.get_organization_head() == e1 assert e7.get_closest_common_superior(4) == e2 assert e2.get_closest_common_superior(4) == e2 assert e2.get_closest_common_superior(7) == e2 # assert e7.become_leader("seven") == e1 assert len(e5.get_direct_subordinates()) == 1 e7 = e5.get_direct_subordinates()[0] # assert isinstance(e7, Leader) assert e1.get_highest_rated_subordinate() == e2 assert e5.get_highest_rated_subordinate().eid == 7 # assert e7.get_department_leader() == e7 # assert e2.become_leader('two') == e1 e2 = e1.get_direct_subordinates()[0] assert e2.eid == 2 assert e1.become_leader('one').eid == 1 e1 = e2.become_leader(3)
def test_obtain_sub_head_being_obtained() -> None: e1 = Employee(1, "e1", "a", 1, 1) e2 = Employee(2, "e2", "a", 1, 2) e3 = Employee(3, "e3", "a", 1, 3) e4 = Employee(4, "e4", "a", 1, 4) e5 = Employee(5, "e5", "a", 1, 5) e6 = Employee(6, "e6", "a", 1, 6) e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e3) e6.become_subordinate(e5) assert e5.obtain_subordinates([1, 3]) == e5 assert e5.get_direct_subordinates() == [e1, e2, e3, e4, e6]
def test_obtain_sub_already_sub_anotha_one() -> None: #dj khaled e1 = Employee(1, "e1", "a", 1, 50) e2 = Employee(2, "e2", "a", 1, 50) e3 = Employee(3, "e3", "a", 1, 50) e4 = Employee(4, "e4", "a", 1, 50) e5 = Employee(5, "e5", "a", 1, 50) e6 = Employee(6, "e6", "a", 1, 50) e7 = Employee(7, "e7", "a", 1, 50) e2.become_subordinate(e1) e3.become_subordinate(e2) e4.become_subordinate(e2) e5.become_subordinate(e4) e6.become_subordinate(e4) e7.become_subordinate(e5) assert e2.obtain_subordinates([4, 6]) == e1 assert e2.get_direct_subordinates() == [e3, e4, e5, e6]
def test_fire_under_tie_advanced() -> None: e1 = Employee(1, '', '', 10, 10) e2 = Employee(2, '', '', 10, 10) e3 = Employee(3, '', '', 10, 20) e4 = Employee(4, '', '', 10, 10) e5 = Employee(5, '', '', 10, 20) o = Organization() o.add_employee(e1) o.add_employee(e5, 1) o.add_employee(e2, 5) o.add_employee(e4, 1) o.add_employee(e3, 4) o.fire_under_rating(20) assert o.get_head() == e5 assert e5.get_direct_subordinates() == [e3] assert e3.get_superior() == e5
def test_fire_under_rating_advanced() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 10, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 20) e3 = Employee(3, "Sofia", "Manager", 25000, 30) e4 = Employee(4, "Senya", "Grunt", 5000, 40) e5 = Employee(5, "Sylvia", "Grunt", 5000, 50) o = Organization() o.add_employee(e1) o.add_employee(e2, 1) o.add_employee(e3, 1) o.add_employee(e4, 2) o.add_employee(e5, 3) o.fire_under_rating(35) assert o.get_head() == e5 assert e5.get_direct_subordinates() == [e4] assert e4.get_superior() == e5
def test_fire_lowest_rated_employee_basic() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 99, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 89) e3 = Employee(3, "Sofia", "Manager", 25000, 79) e4 = Employee(4, "Senya", "Grunt", 5000, 69) e5 = Employee(5, "Sylvia", "Grunt", 5000, 59) o = Organization() o.add_employee(e1) o.add_employee(e2, 1) o.add_employee(e3, 1) o.add_employee(e4, 3) o.add_employee(e5, 3) o.fire_lowest_rated_employee() assert e3.get_direct_subordinates() == [e4] o.fire_lowest_rated_employee() o.fire_lowest_rated_employee() assert e1.get_direct_subordinates() == [e2]
def test_obtain_subordinates_simple() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 30) e3 = Employee(3, "Sofia", "Manager", 25000, 40) e4 = Employee(4, "Senya", "Grunt", 5000, 30) e5 = Employee(5, "Sylvia", "Grunt", 5000, 40) e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e3) new_head = e2.obtain_subordinates([3, 5]) assert new_head == e1 assert e2.get_direct_subordinates() == [e3, e5] assert e1.get_direct_subordinates() == [e2, e4] assert e3.get_superior() == e2 assert e5.get_superior() == e2 assert e2.get_superior() == e1 assert e4.get_superior() == e1
def test_obtain_subordinates_different_head() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 30) e3 = Employee(3, "Sofia", "Manager", 25000, 40) e4 = Employee(4, "Senya", "Grunt", 5000, 30) e5 = Employee(5, "Sylvia", "Grunt", 5000, 40) e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e3) new_head = e2.obtain_subordinates([1, 3]) assert new_head.eid == 5 # assert isinstance(new_head, Leader) new_subs = e2.get_direct_subordinates() assert new_subs[0].eid == 1 assert new_subs[1].eid == 3 assert new_head.get_direct_subordinates() == [e2, e4] assert new_subs[0].get_superior() == e2 assert new_subs[1].get_superior() == e2 assert e4.get_superior() == new_head assert e2.get_superior() == new_head
def test_add_subordinate() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e2.add_subordinate(e1) assert e2.get_direct_subordinates()[0].eid == 1 assert e1.get_superior() is None
def test_get_direct_subordinates() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e1.become_subordinate(e2) assert e2.get_direct_subordinates()[0].name == 'Emma Ployee'