def test_order_simpler_tree():
    L1 = Leader(1, 'l82', 'L82-A', 4567, 1, 'A')  # change
    L2 = Leader(2, 'l83', 'L83-D', 4557, 2, 'D')
    L3 = Leader(3, 'l84', 'L82-F', 4367, 2, 'F')
    L4 = Leader(4, 'l85', 'L82-G', 4597, 1, 'G')
    L5 = Leader(5, 'l86', 'L82-H', 2567, 7, 'H')
    L6 = Leader(6, 'l39', 'L39-E', 2562, 7, 'E')  # change
    L10 = Leader(10, 'l39', 'L39-E', 2562, 1, 'E')  # change
    for item in [L2, L3, L4]:
        item.become_subordinate(L1)
    L10.become_subordinate(L2)
    for item in [L5, L6]:
        item.become_subordinate(L3)
    #L10.obtain_subordinates([1,99,98,90,3])
    L10.obtain_subordinates([1, 3])
    for item in [L6, L2, L3, L4, L5, L1, L10]:
        assert item.get_organization_head() == L2
        if item in [L1, L3]:
            assert item.get_superior() == L10
        elif item == L2:
            assert item.get_superior() is None
        else:
            assert item.get_superior() == L2
        if item in [L4, L5, L6, L1, L3]:
            assert item.get_direct_subordinates() == []
            assert item.get_all_subordinates() == []
        elif item == L2:
            assert item.get_direct_subordinates() == [L4, L5, L6, L10]
            assert item.get_all_subordinates() == [L1, L3, L4, L5, L6, L10]
        else:
            assert item is L10
            assert item.get_all_subordinates() == item.get_direct_subordinates(
            ) == [L1, L3]
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
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'
Ejemplo n.º 4
0
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_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
Ejemplo n.º 6
0
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_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
Ejemplo n.º 8
0
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"
Ejemplo n.º 9
0
from organization_hierarchy import Employee, Leader, merge
from typing import List
from e1_Sample_Non_Mutating_Test import increasing, increasing_salary, no_duplicate

e3 = Employee(3, 'e3', 'E3', 3999, 27)
L81 = Leader(81, 'l81', 'L81-B', 3399, 58, 'B')
e23 = Employee(23, 'e23', 'E23', 1999, 32)
L58 = Leader(58, 'l58', 'L58-C', 2799, 85, 'C')
e48 = Employee(48, 'e48', 'E48', 2699, 84)
e38 = Employee(38, 'e38', 'E38', 3299, 38)
L81.become_subordinate(e3)
e23.become_subordinate(e3)
L58.become_subordinate(L81)
e48.become_subordinate(L81)
e38.become_subordinate(L81)

L82 = Leader(82, 'l82', 'L82-A', 4567, 80, 'A')
L83 = Leader(83, 'l83', 'L83-D', 4557, 90, 'D')
L84 = Leader(84, 'l84', 'L82-F', 4367, 29, 'F')
L85 = Leader(85, 'l85', 'L82-G', 4597, 29, 'G')
L86 = Leader(86, 'l86', 'L82-H', 2567, 31, 'H')
L39 = Leader(39, 'l39', 'L39-E', 2562, 98, 'E')
L83.become_subordinate(L82)
L39.become_subordinate(L82)
L84.become_subordinate(L83)
L86.become_subordinate(L83)
L85.become_subordinate(L83)

e88 = Employee(88, "e88", 'E88', 4374, 88)
e41 = Employee(41, "e41", 'E41', 4234, 41)
e42 = Employee(42, "e42", 'E42', 4594, 42)
Ejemplo n.º 10
0
def generate():
    e3 = Employee(3, 'e3', 'E3', 3999, 27)
    L81 = Leader(81, 'l81', 'L81-B', 3399, 58, 'B')
    e23 = Employee(23, 'e23', 'E23', 1999, 32)
    L58 = Leader(58, 'l58', 'L58-C', 2799, 85, 'C')
    e48 = Employee(48, 'e48', 'E48', 2699, 84)
    e38 = Employee(38, 'e38', 'E38', 3299, 38)
    L81.become_subordinate(e3)
    e23.become_subordinate(e3)
    L58.become_subordinate(L81)
    e48.become_subordinate(L81)
    e38.become_subordinate(L81)

    L82 = Leader(82, 'l82', 'L82-A', 4567, 80, 'A')
    L83 = Leader(83, 'l83', 'L83-D', 4557, 90, 'D')
    L84 = Leader(84, 'l84', 'L82-F', 4367, 29, 'F')
    L85 = Leader(85, 'l85', 'L82-G', 4597, 29, 'G')
    L86 = Leader(86, 'l86', 'L82-H', 2567, 31, 'H')
    L39 = Leader(39, 'l39', 'L39-E', 2562, 98, 'E')
    L83.become_subordinate(L82)
    L39.become_subordinate(L82)
    L84.become_subordinate(L83)
    L86.become_subordinate(L83)
    L85.become_subordinate(L83)

    e88 = Employee(88, "e88", 'E88', 4374, 88)
    e41 = Employee(41, "e41", 'E41', 4234, 41)
    e42 = Employee(42, "e42", 'E42', 4594, 42)
    e43 = Employee(43, "e43", 'E43', 4104, 43)
    e51 = Employee(51, "e51", 'E51', 4568, 51)
    e61 = Employee(61, "e61", 'E61', 4372, 51)
    e61.become_subordinate(e41)
    e51.become_subordinate(e41)
    e42.become_subordinate(e88)
    e41.become_subordinate(e88)
    e43.become_subordinate(e88)

    L80 = Leader(80, "l80", 'L80-J', 4334, 88, 'J')
    e4 = Employee(4, 'e4', 'E4', 4444, 34)
    e5 = Employee(5, 'e5', 'E5', 4454, 35)
    e6 = Employee(6, 'e6', 'E6', 4464, 27)
    e5.become_subordinate(L80)
    e6.become_subordinate(L80)
    e4.become_subordinate(L80)

    e7 = Employee(7, "e7", 'E88', 4374, 27)
    L77 = Leader(77, 'l77', 'L77-I', 4567, 73, 'I')
    L78 = Leader(78, 'l78', 'L78-IB', 4557, 78, 'IB')
    L77.become_subordinate(e7)
    L78.become_subordinate(e7)

    L30 = Leader(30, 'l30', "L30-corp", 4278, 28, "corp")
    # e30=Leader(30,'l30',"L30-corp",4278,28)
    e3.become_subordinate(L30)
    L82.become_subordinate(L30)
    e88.become_subordinate(L30)
    L80.become_subordinate(L30)
    e7.become_subordinate(L30)

    single_e = Employee(55, "single", 'single_pos', 4, 7)
    single_l = Leader(55, "single", 'single_pos', 4, 7, 'No one cares')

    dictt = {}
    lst = [L30]
    lst.extend(L30.get_all_subordinates())
    for item in lst:
        dictt[item.name] = item
    dictt["single_e"] = single_e
    dictt["single_l"] = single_l
    return dictt