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_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_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_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'
示例#5
0
def test_get_all_subordinates_advanced() -> None:
    e1 = Employee(1, "Emma Ployee", "Worker", 10000, 50)
    e2 = Employee(2, "Sue Perior", "Manager", 20000, 30)
    e3 = Employee(3, "Robocop", "Worker", 20000, 30)
    e4 = Leader(4, "Sarah", "CEO", 20000, 30, "Some Corp.")
    e5 = Employee(5, "Sofia", "Worker", 20000, 30)
    e6 = Employee(6, "Terry", "Worker", 20000, 30)
    e7 = Employee(7, "Odysseus", "Worker", 20000, 30)
    e1.become_subordinate(e2)
    e3.become_subordinate(e2)
    e2.become_subordinate(e4)
    e5.become_subordinate(e2)
    e6.become_subordinate(e4)
    e7.become_subordinate(e4)
    assert e2.get_all_subordinates() == [e1, e3, e5]
    assert e4.get_all_subordinates() == [e1, e2, e3, e5, e6, e7]
    assert e1.get_all_subordinates() == []
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_become_sub() -> 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
    assert len(e1.get_direct_subordinates()) == 1
    e3 = Employee(3, "Emma", "Worker", 10000, 50)
    e3.become_subordinate(e2)
    assert e3.get_superior().eid == 2
    assert len(e1.get_direct_subordinates()) == 1
    assert len(e1.get_all_subordinates()) == 2
示例#8
0
def test_employee_general() -> None:
    e1 = Employee(1, "e1", "a", 1, 50)
    e2 = Employee(2, "e2", "a", 1, 50)
    e3 = Employee(3, "e3", "a", 1, 50)
    e4 = Employee(4, "e4", "a", 1, 50)
    e5 = Employee(5, "e5", "a", 1, 50)
    e6 = Employee(6, "e6", "a", 1, 50)
    e7 = Employee(7, "e7", "a", 1, 50)
    e7.become_subordinate(e5)
    e5.become_subordinate(e2)
    e4.become_subordinate(e2)
    e2.become_subordinate(e1)
    e3.become_subordinate(e1)
    e6.become_subordinate(e3)
    assert e6.get_all_subordinates() == []
    assert e2.get_all_subordinates() == [e4, e5, e7]
    assert e2.get_direct_subordinates() == [e4, e5]
    assert e7.get_organization_head() == e1
    assert e1.get_organization_head() == e1
    assert e7.get_closest_common_superior(4) == e2
    assert e2.get_closest_common_superior(4) == e2
    assert e2.get_closest_common_superior(7) == e2

    # assert e7.become_leader("seven") == e1
    assert len(e5.get_direct_subordinates()) == 1

    e7 = e5.get_direct_subordinates()[0]
    # assert isinstance(e7, Leader)
    assert e1.get_highest_rated_subordinate() == e2
    assert e5.get_highest_rated_subordinate().eid == 7
    # assert e7.get_department_leader() == e7

    # assert e2.become_leader('two') == e1
    e2 = e1.get_direct_subordinates()[0]
    assert e2.eid == 2

    assert e1.become_leader('one').eid == 1
    e1 = e2.become_leader(3)
示例#9
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 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)

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

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

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