def test_get_organization_head() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Employee(3, "Bigg Boss", "CEO", 50000, 60) e1.become_subordinate(e2) e2.become_subordinate(e3) assert e1.get_organization_head().name == 'Bigg Boss'
def test_swap_up_repeated() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 30) e3 = Leader(3, "Sofia", "Manager", 25000, 30, "Grunts Department") e4 = Employee(4, "Senya", "Grunt Alpha", 15000, 30) e5 = Employee(5, "Sylvia", "Grunt Beta", 10000, 30) e6 = Employee(6, "Scarlett", "Grunt Gamma", 5000, 30) e7 = Employee(7, "Samantha", "Grunt Epsilon", 2500, 100) e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e4) e6.become_subordinate(e5) e7.become_subordinate(e6) new_e7 = e7.swap_up() assert new_e7.get_superior() == e5 assert new_e7.salary == 5000 assert new_e7.position == "Grunt Gamma" for i in range(4): new_e7 = new_e7.swap_up() assert isinstance(new_e7, Leader) assert new_e7.get_superior() is None assert new_e7.salary == 500000 assert new_e7.position == "CEO" assert new_e7.get_department_name() == "Some Corp." new_subs = new_e7.get_direct_subordinates() assert new_subs[0].name == "Sarah" assert new_subs[1].name == "Sandra"
def test_get_all_subordinates() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Employee(3, "Bigg Boss", "CEO", 50000, 60) e1.become_subordinate(e2) e2.become_subordinate(e3) assert e3.get_all_subordinates()[0].name == 'Emma Ployee' assert e3.get_all_subordinates()[1].name == 'Sue Perior'
def test_get_closest_common_superior_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Some Corp.") e1.become_subordinate(e3) e2.become_subordinate(e3) superior = e1.get_closest_common_superior(3) assert superior.eid == 3
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_get_department_leader() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) assert e1.get_department_leader() is None e2 = Leader(2, "Sue Perior", "Manager", 20000, 30, "Department") e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Company") e1.become_subordinate(e2) e2.become_subordinate(e3) assert e1.get_department_leader().name == 'Sue Perior' assert e2.get_department_leader().name == 'Sue Perior'
def test_get_emp() -> None: e1 = Employee(1, "Boss", "CEO", 50000, 50) assert e1.get_employee(0) is None e2 = Employee(2, "Sue", "Manager", 20000, 50) e2.become_subordinate(e1) assert e1.get_employee(2).name == "Sue" e3 = Employee(3, "Emma", "Worker", 10000, 50) e3.become_subordinate(e2) assert e1.get_employee(3).name == "Emma"
def test_get_higher_paid_employees_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Some Corp.") e1.become_subordinate(e2) e2.become_subordinate(e3) more_than = e2.get_higher_paid_employees() assert len(more_than) == 1 assert more_than[0].name == 'Bigg Boss'
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_get_employee() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Some Corp.") e1.become_subordinate(e2) e2.become_subordinate(e3) assert e3.get_employee(1) is e1 assert e1.get_employee(1) is e1 assert e2.get_employee(3) is None
def test_get_org_head() -> None: e1 = Employee(1, "Boss", "CEO", 50000, 50) assert e1.get_organization_head().eid == 1 e2 = Employee(2, "Sue", "Manager", 20000, 50) e2.become_subordinate(e1) assert e2.get_organization_head().eid == 1 e3 = Employee(3, "Emma", "Worker", 10000, 50) e3.become_subordinate(e2) assert e3.get_organization_head().eid == 1
def test_get_sup() -> 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 e3 = Employee(3, "Emma", "Worker", 10000, 50) e3.become_subordinate(e2) assert e3.get_superior().eid == 2
def test_get_department_name() -> None: e2 = Employee(3, 'Joe', 'Worker', 10000, 50) assert e2.get_department_name() == '' l = Leader(1, 'Lena', 'LEADER', 100000, 100, 'Department') assert l.get_department_name() == 'Department' e1 = Employee(2, 'Mama', 'Anna', 50000, 100) e1.become_subordinate(l) assert e1.get_department_name() == 'Department' e2.become_subordinate(e1) assert e2.get_department_name() == 'Department'
def test_get_employees_paid_more_than_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Some Corp.") e1.become_subordinate(e2) e2.become_subordinate(e3) more_than_10000 = e3.get_employees_paid_more_than(10000) assert len(more_than_10000) == 2 assert more_than_10000[0].name == 'Sue Perior' assert more_than_10000[1].name == 'Bigg Boss'
def test_get_highest_rated_subordinate_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) assert e1.get_position_in_hierarchy() == 'Worker' e2 = Leader(2, "Sue Perior", "Manager", 20000, 30, "Department") e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Company") e1.become_subordinate(e2) e2.become_subordinate(e3) assert e3.get_highest_rated_subordinate().name == 'Sue Perior' e1.become_subordinate(e3) assert e3.get_highest_rated_subordinate().name == 'Emma Ployee'
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_swap_up_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Leader(2, "Sue Perior", "Manager", 20000, 30, "Department") e3 = Leader(3, "Bigg Boss", "CEO", 50000, 60, "Company") e1.become_subordinate(e2) e2.become_subordinate(e3) new_e1 = e1.swap_up() assert isinstance(new_e1, Leader) new_e2 = new_e1.get_direct_subordinates()[0] assert isinstance(new_e2, Employee) assert new_e1.position == 'Manager' assert new_e1.eid == 1 assert e3.get_direct_subordinates()[0] is new_e1
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_become_subordinate() -> None: a = Employee(1, 'Alpha', 'Slave', 80, 80) b = Employee(2, 'Beta', 'Worker', 90, 90) c = Employee(3, 'Charlie', 'God', 100, 100) a._subordinates = [b] b._superior = a c.become_subordinate(a) assert c._superior == a assert c._subordinates == [] assert a._subordinates[1] == c b.become_subordinate(None) assert b._superior == None assert b._subordinates == [] assert len(a._subordinates) == 1 assert a._subordinates[0] == c
def test_get_closest_common_superior() -> None: e = Employee(1, 'Name1', 'Pos1', 10, 10) e1 = Employee(2, 'Name2', 'Pos2', 10, 10) e3 = Employee(3, 'Name3', 'Pos3', 10, 10) e1.become_subordinate(e) e3.become_subordinate(e) assert e1.get_closest_common_superior(3).name == e.name e4 = Employee(4, 'Name4', 'Pos4', 10, 10) e4.become_subordinate(e1) assert e4.get_closest_common_superior(3).name == e.name e5 = Employee(5, 'Name5', 'Pos5', 10, 10) e5.become_subordinate(e1) e6 = Employee(6, 'Name6', 'Pos6', 10, 10) e6.become_subordinate(e5) assert e5.get_closest_common_superior(4).name == 'Name2' assert e1.get_closest_common_superior(1) == e
def test_become_each_other() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 30) e3 = Employee(3, "Sofia", "Manager", 25000, 40) e2.become_subordinate(e1) e3.become_subordinate(e2) assert e3.get_department_name() == 'Some Corp.' lol = e2.become_leader('chloeisamazingandneedschicken') assert isinstance(lol.get_employee(2), Leader) assert e3.get_department_name() == 'chloeisamazingandneedschicken' lol = e1.become_employee() assert isinstance(lol.get_employee(1), Employee) assert isinstance(lol.get_employee(1), Leader) == False assert lol.get_employee(1).get_department_name() == '' assert len(lol.get_employee(1).get_all_subordinates()) == 2 assert lol.get_employee(2).get_department_name() == \ 'chloeisamazingandneedschicken'
def test_get_position_in_hierarchy() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Leader(2, "Sue Perior", "Manager", 20000, 30, "Dept E") e3 = Leader(3, "Robocop", "Worker", 20000, 30, "Dept D") e4 = Leader(4, "Sarah", "Worker", 20000, 30, "Dept C") e5 = Leader(5, "Sofia", "Secretary", 20000, 30, "Dept B") e6 = Employee(6, "Terry", "COO", 20000, 30) e7 = Leader(7, "Sarah", "CEO", 20000, 30, "Dept A") e1.become_subordinate(e2) e2.become_subordinate(e3) e3.become_subordinate(e4) e4.become_subordinate(e5) e5.become_subordinate(e6) e6.become_subordinate(e7) assert e1.get_position_in_hierarchy() == "Worker, Dept E, Dept D, Dept C," \ " Dept B, Dept A" assert e5.get_position_in_hierarchy() == "Secretary, Dept B, Dept A" assert e7.get_position_in_hierarchy() == "CEO, Dept A"
def test_obtain_subordinates_1_2() -> None: e1 = Employee(1, "1", "CEO", 15000, 1) e2 = Employee(2, "2", "Sub", 25000, 2) e3 = Employee(3, "3", "Sub", 50000, 3) e5 = Employee(5, "5", "Sub", 15000, 5) e6 = Employee(6, "6", "Sub", 30000, 6) e40 = Employee(40, "40", "Sub", 30000, 40) e2.become_subordinate(e1) e3.become_subordinate(e1) e6.become_subordinate(e3) e40.become_subordinate(e2) e5.become_subordinate(e2) head = e6.obtain_subordinates([1, 2]) assert head.name == '3' assert len(head.get_direct_subordinates()) == 3 assert head.get_direct_subordinates()[0].eid == 5 assert head.get_direct_subordinates()[1].eid == 6 assert head.get_direct_subordinates()[2].eid == 40
def test_create_department_salary_tree() -> None: e1 = Leader(1, "Emma Ployee", "Worker", 15000, 50, 'Marketing') e2 = Employee(2, "Sue Perior", "Manager", 25000, 30) e3 = Employee(3, "Bigg Boss", "CEO", 50000, 60) e4 = Leader(4, "Emma Watson", "Manager", 30000, 50, 'Sales') e5 = Leader(5, "The Rock", "Worker", 15000, 15, 'Management') e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e3) o = Organization(e1) dst = create_department_salary_tree(o) assert dst.department_name == 'Marketing' assert dst.salary == 30000.0 assert len(dst.subdepartments) == 2 assert dst.subdepartments[0].department_name == 'Sales' assert dst.subdepartments[0].salary == 30000.0 assert dst.subdepartments[1].department_name == 'Management' assert dst.subdepartments[1].salary == 15000.0
def test_create_department_salary_tree_no_leaders() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 15000, 50) e2 = Employee(2, "Sue Perior", "Manager", 25000, 30) e3 = Employee(3, "Bigg Boss", "CEO", 50000, 60) e4 = Employee(4, "Emma Watson", "Manager", 30000, 50) e5 = Employee(5, "The Rock", "Worker", 15000, 15) e2.become_subordinate(e1) e3.become_subordinate(e1) e4.become_subordinate(e3) e5.become_subordinate(e3) o = Organization(e1) result = create_department_salary_tree(o) assert result is None
def test_fire_head() -> None: o = Organization() 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) o.add_employee(e1) assert o.get_head() == e1 o.fire_employee(1) assert o.get_head() == e3 o.fire_employee(3) assert o.get_head() == e5 o.fire_employee(4) assert o.get_head() == e5 o.fire_employee(5) assert o.get_head() == e6
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_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_get_dept_emp() -> None: e = Leader(1, 'Name1', 'Pos1', 10000, 50, 'BigDept') e1 = Employee(2, 'Name2', 'Pos2', 1000, 50) e2 = Employee(3, 'Name3', 'Pos2', 1000, 50) e1.become_subordinate(e) e2.become_subordinate(e) e3 = Employee(4, 'Name4', 'Pos2', 1000, 50) e3.become_subordinate(e1) e4 = Leader(5, 'Name5', 'Pos3', 10000, 50, 'SmallDept1') e4.become_subordinate(e) e5 = Leader(6, 'Name6', 'Pos4', 10000, 50, 'SmallDept2') e5.become_subordinate(e2) assert len(e.get_department_employees()) == 6
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