Пример #1
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
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()
Пример #3
0
 def __init__(self) -> None:
     """Initialize this OrganizationSimulator with an empty Organization.
     """
     self.current_organization = Organization()
     self.current_employee = None
     self.current_subordinates = []
     self.displaying_direct = True
Пример #4
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_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_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
Пример #7
0
def test_short_create() -> None:
    o = Organization()
    lin = Leader(1, 'Linda', 'Sewed', 10, 10, 'MyNew')
    o.add_employee(lin)
    assert o.get_head() == lin
    t = create_department_salary_tree(o)
    assert t.department_name == 'MyNew'
    assert size(t) == 1
Пример #8
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_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_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_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
Пример #14
0
def test_lead_emp_emp_lead() -> None:
    o = Organization()
    leads = create_leaders(4)
    emps = create_emps(4)
    o.add_employee(leads[0])
    o.add_employee(leads[1], 1)
    o.add_employee(emps[0], 1)
    o.add_employee(emps[1], 101)
    o.add_employee(leads[2], 102)
    o.add_employee(emps[2], 3)
    o.add_employee(leads[3], 1)
    tree = create_department_salary_tree(o)
    assert size(tree) == 4
    assert tree.department_name == 'Department1'
Пример #15
0
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_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]
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
Пример #18
0
def test_med_2_create() -> None:
    leads = create_leaders(4)
    emps = create_emps(5)
    o = Organization()
    e = leads[0]
    o.add_employee(e)
    o.add_employee(leads[1], 1)
    o.add_employee(leads[2], 1)
    o.add_employee(leads[3], 2)
    o.add_employee(emps[0], 4)
    o.add_employee(emps[1], 4)
    o.add_employee(emps[2], 2)
    o.add_employee(emps[3], 3)
    o.add_employee(emps[4], 104)
    d = create_department_salary_tree(o)
    assert size(d) == 4
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_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_employee_new_head_2() -> None:
    e1 = Leader(1, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e2 = Employee(2, "Sandra", "Secretary", 20000, 40)
    e3 = Employee(3, "Sofia", "Manager", 25000, 30)
    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 == 2
    assert head.get_direct_subordinates() == [e3]
    assert e3.get_superior() == head
def test_promote_employee_simple() -> None:
    e1 = Leader(1, "Sarah", "CEO", 500000, 89, "Some Corp.")
    e2 = Employee(2, "Sandra", "Secretary", 20000, 89)
    e3 = Employee(3, "Sofia", "Manager", 25000, 89)
    e4 = Employee(4, "Senya", "Grunt", 5000, 89)
    e5 = Employee(5, "Sylvia", "Grunt", 5000, 99)
    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.promote_employee(5)
    assert o.get_head().eid == 5
    assert len(o.get_head().get_direct_subordinates()) == 2
    assert o.get_head().get_direct_subordinates()[0].eid == 1
    assert o.get_head().get_direct_subordinates()[1].eid == 2
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_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_get_employees_with_position() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 50000, 30)
    e3 = Employee(3, "Robocop", "Worker", 20000, 30)
    e4 = Leader(4, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e5 = Employee(5, "Sofia", "Worker", 10000, 30)
    e6 = Employee(6, "Terry", "Worker", 5000, 30)
    e7 = Employee(7, "Odysseus", "Worker", 22000, 30)
    o = Organization()
    o.add_employee(e4)
    o.add_employee(e7, 4)
    o.add_employee(e6, 4)
    o.add_employee(e2, 4)
    o.add_employee(e1, 2)
    o.add_employee(e3, 2)
    o.add_employee(e5, 3)
    assert o.get_employees_with_position("Worker") == [e1, e3, e5, e6, e7]
    assert o.get_employees_with_position("Manager") == [e2]
    assert o.get_employees_with_position("CEO") == [e4]
def test_get_employee_advanced() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 50000, 30)
    e3 = Employee(3, "Robocop", "Worker", 20000, 30)
    e4 = Leader(4, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e5 = Employee(5, "Sofia", "Worker", 10000, 30)
    e6 = Employee(6, "Terry", "Worker", 5000, 30)
    e7 = Employee(7, "Odysseus", "Worker", 22000, 30)
    o = Organization()
    o.add_employee(e4)
    o.add_employee(e7, 4)
    o.add_employee(e6, 4)
    o.add_employee(e2, 4)
    o.add_employee(e1, 2)
    o.add_employee(e3, 2)
    o.add_employee(e5, 2)
    assert o.get_employee(1) is e1
    assert o.get_employee(4) is e4
    assert o.get_employee(12) is None
Пример #27
0
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_get_average_salary_position_filter() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 20000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 50000, 30)
    e3 = Employee(3, "Robocop", "Worker", 30000, 30)
    e4 = Leader(4, "Sarah", "CEO", 500000, 30, "Some Corp.")
    e5 = Employee(5, "Sofia", "Worker", 10000, 30)
    e6 = Employee(6, "Terry", "Worker", 20000, 30)
    e7 = Employee(7, "Odysseus", "Worker", 20000, 30)
    e8 = Employee(8, "Sparrow", "Contract Worker", 60000, 30)
    e9 = Employee(9, "Nick", "Contract Worker", 70000, 30)
    e10 = Employee(10, "Theseus", "Contract Worker", 80000, 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)
    o.add_employee(e6, 4)
    o.add_employee(e7, 4)
    o.add_employee(e8, 1)
    o.add_employee(e9, 1)
    o.add_employee(e10, 1)
    assert round(o.get_average_salary("Worker")) == 20000
Пример #29
0
def test_medium_create() -> None:
    o = Organization()
    l1 = create_lead(1)
    l2 = create_lead(2)
    l3 = create_lead(3)
    o.add_employee(l1)
    o.add_employee(l2, 1)
    o.add_employee(l3, 1)
    e4 = create_emp(4)
    e5 = create_emp(5)
    e6 = create_emp(6)
    e7 = create_emp(7)
    o.add_employee(e4, 2)
    o.add_employee(e5, 2)
    o.add_employee(e6, 3)
    o.add_employee(e7, 3)
    dept_hier = create_department_salary_tree(o)
    assert dept_hier.department_name == 'Dept1'
    subdepts = dept_hier.subdepartments
    assert len(subdepts) == 2
    salaries = [subdepts[0].salary, subdepts[1].salary]
    assert 2900.0 / 3 in salaries
    assert 4300.0 / 3 in salaries
    assert size(dept_hier) == 3
Пример #30
0
def test_empty_create() -> None:
    o = Organization()
    assert create_department_salary_tree(o) is None
    lin = Employee(1, 'Linda', 'Tailor', 10, 10)
    o.add_employee(lin)
    assert create_department_salary_tree(o) is None