예제 #1
0
    def load_dcap_data(s):
        DCapALst.init()
        dept_data = open(s, "r")
        dept_data = dept_data.read()
        dept_data = dept_data.replace(",", "")
        dept_data = dept_data.splitline()

        for dept_and_cap in dept_data:
            dept_info = dept_and_cap.split()
            if dept_info[0] == "civil":
                dept = DeptT.civil
            if dept_info[0] == "chemical":
                dept = DeptT.chemical
            if dept_info[0] == "electrical":
                dept = DeptT.electrical
            if dept_info[0] == "mechanical":
                dept = DeptT.mechanical
            if dept_info[0] == "software":
                dept = DeptT.software
            if dept_info[0] == "materials":
                dept = DeptT.materials
            if dept_info[0] == "engphys":
                dept = DeptT.engphys

            cap = int(dept_info[1])
            DCapALst.add(dept, cap)
예제 #2
0
 def test_allocate(self):
     AALst.init()
     DCapALst.init()
     SALst.init()
     DCapALst.s.append((DeptT.civil, 2))
     DCapALst.s.append((DeptT.chemical, 2))
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 3.0,
                          SeqADT([DeptT.civil, DeptT.chemical]), True))
     student_t2 = ('macid2',
                   SInfoT('fname2', 'lname2', GenT.male, 12.0,
                          SeqADT([DeptT.civil, DeptT.chemical]), False))
     student_t3 = ('macid3',
                   SInfoT('fname3', 'lname3', GenT.male, 4.0,
                          SeqADT([DeptT.civil, DeptT.chemical]), True))
     student_t4 = ('macid4',
                   SInfoT('fname4', 'lname4', GenT.male, 7.0,
                          SeqADT([DeptT.civil, DeptT.chemical]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     SALst.s.append(student_t3)
     SALst.s.append(student_t4)
     SALst.allocate()
     assert AALst.lst_alloc(DeptT.civil) == ['macid3', 'macid2']
     assert AALst.lst_alloc(DeptT.chemical) == ['macid4']
예제 #3
0
 def test_allocate_raises_runtimeerror(self):
     AALst.init()
     DCapALst.init()
     SALst.init()
     DCapALst.s.append((DeptT.civil, 2))
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 6.0,
                          SeqADT([DeptT.civil]), True))
     student_t2 = ('macid2',
                   SInfoT('fname2', 'lname2', GenT.male, 12.0,
                          SeqADT([DeptT.civil]), False))
     student_t3 = ('macid3',
                   SInfoT('fname3', 'lname3', GenT.male, 4.0,
                          SeqADT([DeptT.civil]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     SALst.s.append(student_t3)
     with pytest.raises(RuntimeError):
         SALst.allocate()
예제 #4
0
def load_dcap_data(s):
    with open(s, 'r') as dept_capacity:
        contents = dept_capacity.readlines()

    DCapALst.init()

    dept_dict = {
        'civil': DeptT.civil,
        'chemical': DeptT.chemical,
        'software': DeptT.software,
        'electrical': DeptT.electrical,
        'engphys': DeptT.engphys,
        'materials': DeptT.materials,
        'mechanical': DeptT.mechanical
    }

    for line in contents:
        dept_info = line.replace(' ', '').split(',')
        dept = dept_dict.get(dept_info[0])
        cap = int(dept_info[1])
        DCapALst.add(dept, cap)
예제 #5
0
    def allocate():
        AALst.init()

        f = SALst.sort(lambda t: (t.freechoice) and t.gpa >= 4.0)
        for m in f:
            ch = SALst.info(m).choices
            AALst.add_stdnt(ch.next(), m)

        s = SALst.sort(lambda t: (not t.freechoice) and t.gpa >= 4.0)
        for m in s:
            ch = SALst.info(m).choices
            alloc = False
            while (not alloc) and (not ch.end()):
                d = ch.next()
                if AALst.num_alloc(d) < DCapALst.capacity(d):
                    AALst.add_stdnt(d, m)
                    alloc = True
            if not alloc:
                raise RuntimeError
예제 #6
0
    def allocate():
        AALst.init()
        freechoice_stdnts = SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0)
        other_stdnts = SALst.sort(
            lambda t: not (t.freechoice) and t.gpa >= 4.0)

        for macid in freechoice_stdnts:
            choices = SALst.info(macid).choices
            AALst.add_stdnt(choices.next(), macid)

        for macid in other_stdnts:
            choices = SALst.info(macid).choices
            allocated = False
            while (not (allocated) and not (choices.end())):
                dept = choices.next()
                if AALst.num_alloc(dept) < DCapALst.capacity(dept):
                    AALst.add_stdnt(dept, macid)
                    allocated = True
            if not (allocated):
                raise RuntimeError
예제 #7
0
 def test_capacity_raises_keyerror(self):
     DCapALst.init()
     with pytest.raises(KeyError):
         DCapALst.capacity(DeptT.chemical)
예제 #8
0
 def test_capacity(self):
     DCapALst.init()
     DCapALst.add(DeptT.civil, 5)
     assert DCapALst.capacity(DeptT.civil) == 5
예제 #9
0
 def test_remove_raises_keyerror(self):
     DCapALst.init()
     with pytest.raises(KeyError):
         DCapALst.remove(DeptT.chemical)
예제 #10
0
 def test_remove(self):
     DCapALst.init()
     DCapALst.add(DeptT.civil, 5)
     DCapALst.remove(DeptT.civil)
     assert DCapALst.s == []
예제 #11
0
 def test_add_raises_keyerror(self):
     DCapALst.init()
     DCapALst.s.append((DeptT.chemical, 3))
     with pytest.raises(KeyError):
         DCapALst.add(DeptT.chemical, 5)
예제 #12
0
 def test_add(self):
     DCapALst.init()
     DCapALst.add(DeptT.civil, 5)
     assert DCapALst.s[0][0] == DeptT.civil
     assert DCapALst.s[0][1] == 5
예제 #13
0
 def test_elm(self):
     DCapALst.init()
     DCapALst.s.append((DeptT.chemical, 5))
     assert not DCapALst.elm(DeptT.civil)
     assert DCapALst.elm(DeptT.chemical)
예제 #14
0
 def test_init(self):
     DCapALst.init()
     assert DCapALst.s == []