示例#1
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']
示例#2
0
 def test_sort_no_student_meet_requirement(self):
     SALst.init()
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 4.0,
                          SeqADT([DeptT.civil]), False))
     student_t2 = ('macid2',
                   SInfoT('fname2', 'lname2', GenT.male, 7.0,
                          SeqADT([DeptT.civil]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == []
示例#3
0
 def test_average_raises_valueerror(self):
     SALst.init()
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 4.0,
                          SeqADT([DeptT.civil]), True))
     student_t2 = ('macid3',
                   SInfoT('fname3', 'lname3', GenT.male, 12.0,
                          SeqADT([DeptT.civil]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     with pytest.raises(ValueError):
         SALst.average(lambda x: x.gender == GenT.female)
示例#4
0
class SInfoT(NamedTuple):
    fname: str
    lname: str
    gender: GenT
    gpa: float
    choices: type(SeqADT(DeptT))
    freechoice: bool
示例#5
0
 def test_info(self):
     SALst.init()
     student_t = ('macid1',
                  SInfoT('fname1', 'lname1', GenT.male, 4.0,
                         SeqADT([DeptT.civil]), True))
     SALst.s.append(student_t)
     assert SALst.info('macid1') == student_t[1]
示例#6
0
 def test_average(self):
     SALst.init()
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 4.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.female, 7.0,
                          SeqADT([DeptT.civil]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     SALst.s.append(student_t3)
     expected_male_avg = 8.0
     tested_male_avg = SALst.average(lambda x: x.gender == GenT.male)
     assert abs(expected_male_avg - tested_male_avg) < 0.000001
示例#7
0
 def test_add_raises_keyerror(self):
     SALst.init()
     student_t = ('macid1',
                  SInfoT('fname1', 'lname1', GenT.male, 4.0,
                         SeqADT([DeptT.civil]), True))
     SALst.s.append(student_t)
     with pytest.raises(KeyError):
         SALst.add('macid1', ())
示例#8
0
 def test_add(self):
     SALst.init()
     student_t = ('macid1',
                  SInfoT('fname1', 'lname1', GenT.male, 4.0,
                         SeqADT([DeptT.civil]), True))
     SALst.add(student_t[0], student_t[1])
     assert SALst.s[0][0] == student_t[0]
     assert SALst.s[0][1] == student_t[1]
示例#9
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()
示例#10
0
 def test_sort(self):
     SALst.init()
     student_t1 = ('macid1',
                   SInfoT('fname1', 'lname1', GenT.male, 4.0,
                          SeqADT([DeptT.civil]), True))
     student_t2 = ('macid2',
                   SInfoT('fname2', 'lname2', GenT.male, 3.0,
                          SeqADT([DeptT.civil]), True))
     student_t3 = ('macid3',
                   SInfoT('fname3', 'lname3', GenT.male, 12.0,
                          SeqADT([DeptT.civil]), False))
     student_t4 = ('macid4',
                   SInfoT('fname4', 'lname4', GenT.male, 7.0,
                          SeqADT([DeptT.civil]), False))
     SALst.s.append(student_t1)
     SALst.s.append(student_t2)
     SALst.s.append(student_t3)
     SALst.s.append(student_t4)
     assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == [
         'macid1'
     ]
     assert SALst.sort(lambda t: not t.freechoice and t.gpa >= 4.0) == [
         'macid3', 'macid4'
     ]
示例#11
0
    def load_stdnt_data(s):
        SALst.init()
        stdnt_data = open(s, "r")
        stdnt_data = stdnt_data.read()
        stdnt_data = stdnt_data.replace(",", "")
        stdnt_data = stdnt_data.replace("[", "")
        stdnt_data = stdnt_data.replace("]", "")
        stdnt_data = stdnt_data.splitlines()

        for student in stdnt_data:
            stdnt_info = student.split()
            macid = stdnt_info[0]
            f_name = stdnt_info[2]
            l_name = stdnt_info[3]
            if (stdnt_info[3] == "male"):
                gender = GenT.male
            else:
                gender = GenT.female
            gpa = float(stdnt_info[4])
            choices = []
            for i in range(5, len(stdnt_info) - 1):
                if stdnt_info[i] == "civil":
                    choices.append(DeptT.civil)
                if stdnt_info[i] == "chemical":
                    choices.append(DeptT.chemical)
                if stdnt_info[i] == "electrical":
                    choices.append(DeptT.electrical)
                if stdnt_info[i] == "mechanical":
                    choices.append(DeptT.mechanical)
                if stdnt_info[i] == "software":
                    choices.append(DeptT.software)
                if stdnt_info[i] == "materials":
                    choices.append(DeptT.materials)
                if stdnt_info[i] == "engphys":
                    choices.append(DeptT.engphys)
            if (stdnt_info[-1] == "True"):
                free_choice = True
            else:
                free_choice = False

            info = SInfoT(f_name, l_name, gender, gpa, SeqADT(choices),
                          free_choice)
            SALst.add(macid, info)
示例#12
0
 def test_end(self):
     seq = SeqADT([])
     seq2 = SeqADT([DeptT.civil])
     assert seq.end()
     assert not seq2.end()
示例#13
0
 def test_next_raises_stop_iteration(self):
     seq = SeqADT([])
     with pytest.raises(StopIteration):
         seq.next()
示例#14
0
 def test_next(self):
     seq = SeqADT([DeptT.civil, DeptT.chemical])
     assert seq.next() == DeptT.civil
     assert seq.next() == DeptT.chemical
示例#15
0
 def test_start(self):
     seq = SeqADT([DeptT.civil])
     seq.next()
     seq.start()
     assert vars(seq) == {'_SeqADT__i': 0, '_SeqADT__s': [DeptT.civil]}
示例#16
0
 def test_constructor(self):
     seq = SeqADT([DeptT.civil, DeptT.chemical])
     assert vars(seq) == {
         '_SeqADT__i': 0,
         '_SeqADT__s': [DeptT.civil, DeptT.chemical]
     }