Esempio n. 1
0
def test_department_salary_tree_simple() -> None:
    e1 = Leader(1, "Sarah", "CEO", 300000, 89, "Some Corp.")
    e2 = Leader(2, "Sandra", "Secretary", 20000, 89, "Finance")
    e3 = Employee(3, "Sofia", "Manager", 300000, 89)
    e4 = Leader(4, "Senya", "HR Head", 5000, 89, "Human Resources")
    e5 = Employee(5, "Sylvia", "Secretary", 300000, 99)
    e6 = Employee(6, "Selena", "Grunt", 5000, 99)
    e7 = Employee(7, "Sophie", "Grunt", 5000, 99)
    o = Organization()
    o.add_employee(e1)
    o.add_employee(e2, 1)
    o.add_employee(e3, 1)
    o.add_employee(e4, 1)
    o.add_employee(e5, 1)
    o.add_employee(e6, 4)
    o.add_employee(e7, 4)
    tree = create_department_salary_tree(o)
    assert int(tree.salary) == 300000
    assert tree.department_name == "Some Corp."
    assert len(tree.subdepartments) == 2
    assert int(tree.subdepartments[0].salary) == 20000
    assert tree.subdepartments[0].department_name == "Finance"
    assert len(tree.subdepartments[0].subdepartments) == 0
    assert int(tree.subdepartments[1].salary) == 5000
    assert tree.subdepartments[1].department_name == "Human Resources"
    assert len(tree.subdepartments[1].subdepartments) == 0
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_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
Esempio n. 4
0
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_lt() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 20000, 30)
    e3 = Employee(1, "Evil Clone", "Worker", 10000, 50)
    assert e1 < e2
    assert not e2 < e1
    assert not e3 < e1
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_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
Esempio n. 8
0
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
Esempio n. 9
0
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_average_salary_simple() -> None:
    o = Organization()
    assert o.get_average_salary() == 0.0
    e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 20000, 30)
    o.add_employee(e2)
    o.add_employee(e1, 2)
    assert o.get_average_salary() == 15000.0
Esempio n. 11
0
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_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
Esempio n. 13
0
def test_avg_sal() -> None:
    org = Organization()
    assert org.get_average_salary() == 0.0
    e = Employee(1, 'Boss', 'CEO', 50000, 50)
    org.add_employee(e)
    e1 = Employee(2, 'Sarah', 'Keyboardist', 100000, 100)
    org.add_employee(e1, 1)
    assert org.get_average_salary() == 75000
    assert org.get_average_salary('Keyboardist') == 100000
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'
Esempio n. 15
0
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
Esempio n. 17
0
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_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"
Esempio n. 19
0
def test_get_emp() -> None:
    org2 = Organization(None)
    assert org2.get_employee(1) is None
    e = Employee(1, 'Boss', 'CEO', 50000, 50)
    org = Organization(e)
    assert org.get_employee(1).name == 'Boss'
    e1 = Employee(2, 'Man', 'Manager', 20000, 50)
    e.add_subordinate(e1)
    assert org.get_employee(2).name == 'Man'
    assert org.get_employee(3) is None
Esempio n. 20
0
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_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_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_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_get_average_salary_advanced() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 50000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 50000, 30)
    e3 = Employee(3, "Robocop", "Worker", 50000, 30)
    e4 = Leader(4, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e5 = Employee(5, "Sofia", "Worker", 50000, 30)
    o = Organization()
    o.add_employee(e4)
    o.add_employee(e2, 4)
    o.add_employee(e1, 2)
    o.add_employee(e3, 2)
    o.add_employee(e5, 2)
    assert round(o.get_average_salary()) == 140000
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_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_get_next_free_id() -> None:
    dans = Organization()
    dans.add_employee(Employee(1, 'Dan', 'Iel', 1, 1))
    dans.add_employee(Employee(2, 'Dan', 'Iel', 1, 1), 1)
    dans.add_employee(Employee(3, 'Dan', 'Iel', 1, 1), 1)
    dans.add_employee(Employee(4, 'Dan', 'Iel', 1, 1), 3)
    dans.add_employee(Employee(6, 'Dan', 'Iel', 1, 1), 3)
    dans.add_employee(Employee(100, 'Dan', 'Iel', 1, 1), 6)
    dans.add_employee(Employee(5, 'Dan', 'Iel', 1, 1), 2)
    dans.add_employee(Employee(8, 'Dan', 'Iel', 1, 1), 100)
    dans.add_employee(Employee(13, 'Dan', 'Iel', 1, 1), 2)
    dans.add_employee(Employee(27, 'Dan', 'Iel', 1, 1), 13)
    assert dans.get_next_free_id() not in [1, 2, 3, 4, 5, 6, 8, 13, 27, 100]
def test_get_all_subs() -> 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)
    assert (e2.get_all_subordinates() == [])
    e3.become_subordinate(e2)
    e1.become_subordinate(e2)
    e4 = Employee(2, "First Last", "Worker", 5, 50)
    e4.become_subordinate(e3)
    lst = e2.get_all_subordinates()
    assert len(lst) == 3
    assert lst[0].eid == 2
    assert lst[1].eid == 5
    assert lst[2].eid == 8
def test_fire_under_rating_simple() -> 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_under_rating(99)
    assert o.get_head() == e1
    assert e1.get_direct_subordinates() == [e2]