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_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_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_add_emp() -> None: org = Organization() e = Employee(1, 'Boss', 'CEO', 50000, 50) assert org.get_employee(1) is None org.add_employee(e) assert org.get_employee(1).name == 'Boss' e1 = Employee(2, 'Sarah', 'Keyboardist', 1000000, 100) org.add_employee(e1, 1) assert org.get_employee(2).name == 'Sarah' assert e1.get_superior() == e assert len(e.get_all_subordinates()) == 1 e2 = Employee(3, 'John', 'Doe', 10, 10) org.add_employee(e2, 2) assert org.get_employee(3).name == 'John' assert e2.get_superior() == e1
def test_fire_lowest_rated_employee_tie() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 99, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 99) e3 = Employee(3, "Sofia", "Manager", 25000, 89) e4 = Employee(4, "Senya", "Grunt", 5000, 89) e5 = Employee(5, "Sylvia", "Grunt", 5000, 89) 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 e1.get_direct_subordinates() == [e2, e4, e5] assert e4.get_superior() == e1 assert e5.get_superior() == e1
def test_add_sub() -> None: e1 = Employee(5, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(7, "Sue Perior", "Manager", 20000, 30) assert len(e1.get_all_subordinates()) == 0 e1.add_subordinate(e2) assert len(e1.get_all_subordinates()) == 1 assert e2.get_superior() is None
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_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_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_fire_employee_new_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) 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_employee(1) head = o.get_head() assert head.eid == 3 assert head.get_direct_subordinates() == [e2, e4, e5] assert e2.get_superior() == head assert e4.get_superior() == head assert e5.get_superior() == head
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_add_employee_simple() -> None: o = Organization() e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) o.add_employee(e2) assert o.get_head() is e2 o.add_employee(e1, 2) assert o.get_employee(1) is e1 assert e1.get_superior() is e2 e3 = Employee(3, "Bruce Wayne", "Philanthropist", 0, 100) o.add_employee(e3) assert o.get_head() == 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_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_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_employee_new_head() -> None: e1 = Leader(1, "Sarah", "CEO", 500000, 1, "Some Corp.") e2 = Employee(2, "Sandra", "Secretary", 20000, 99) e3 = Employee(3, "Sofia", "Manager", 25000, 89) e4 = Employee(4, "Senya", "Grunt", 5000, 89) e5 = Employee(5, "Sylvia", "Grunt", 5000, 89) e6 = Employee(6, "Savannah", "Wedding Officiate", 5000, 50) 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.add_employee(e6, 2) o.fire_lowest_rated_employee() assert o.get_head().eid == 2 assert o.get_head().get_direct_subordinates() == [e3, e6] assert e3.get_superior() == e2
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_superior_simple() -> None: e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50) assert e1.get_superior() is None e2 = Employee(2, "Sue Perior", "Manager", 20000, 30) e1.become_subordinate(e2) assert e1.get_superior().name == 'Sue Perior'