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_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
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_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'
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_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_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
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
def get_department_salary_tree(self) -> DepartmentSalaryTree: """Return the DepartmentSalaryTree that corresponds to self.current_organization. """ return create_department_salary_tree(self.current_organization)