def test_salallocate1(self): SALst.init() DCapALst.init() DCapALst.add(DeptT.civil, 10) DCapALst.add(DeptT.software, 10) DCapALst.add(DeptT.mechanical, 10) DCapALst.add(DeptT.engphys, 10) DCapALst.add(DeptT.materials, 10) DCapALst.add(DeptT.electrical, 10) DCapALst.add(DeptT.chemical, 10) sinfo2 = SInfoT("first2", "last2", GenT.male, 4.0, SeqADT([DeptT.materials, DeptT.civil]), True) sinfo1 = SInfoT("first", "last", GenT.female, 2.0, SeqADT([DeptT.materials, DeptT.chemical]), True) sinfo3 = SInfoT("first3", "last3", GenT.male, 3.9, SeqADT([DeptT.civil, DeptT.materials]), True) sinfo4 = SInfoT("first4", "last4", GenT.male, 5.0, SeqADT([DeptT.materials, DeptT.engphys]), True) sinfo5 = SInfoT("first5", "last5", GenT.male, 7.0, SeqADT([DeptT.engphys, DeptT.chemical]), True) SALst.init() SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) SALst.add("stdnt3", sinfo3) SALst.add("stdnt4", sinfo4) SALst.add("stdnt5", sinfo5) SALst.allocate() assert AALst.lst_alloc(DeptT.materials) == ['stdnt4', 'stdnt2']
def test_allocate_proper(self): SALst.init() macid = "macid" info = SInfoT("firstname", "lastname", GenT.male, 4.2, SeqADT([DeptT.civil, DeptT.chemical, DeptT.materials]), False) macid2 = "macid2" info2 = SInfoT( "fn", "ln", GenT.female, 5.5, SeqADT([DeptT.software, DeptT.chemical, DeptT.materials]), False) macid3 = "macid3" info3 = SInfoT( "f", "l", GenT.female, 10.5, SeqADT([DeptT.software, DeptT.chemical, DeptT.materials]), True) SALst.add(macid, info) SALst.add(macid2, info2) SALst.add(macid3, info3) DCapALst.init() DCapALst.add(DeptT.software, 1) DCapALst.add(DeptT.chemical, 1) DCapALst.add(DeptT.civil, 1) SALst.allocate() assert AALst.lst_alloc(DeptT.civil) == ["macid"] assert AALst.lst_alloc(DeptT.software) == ["macid3"] assert AALst.lst_alloc(DeptT.chemical) == ["macid2"]
def test_salsort1(self): SALst.init() DCapALst.init() DCapALst.add(DeptT.civil, 10) DCapALst.add(DeptT.software, 10) DCapALst.add(DeptT.mechanical, 10) DCapALst.add(DeptT.engphys, 10) DCapALst.add(DeptT.materials, 10) DCapALst.add(DeptT.electrical, 10) DCapALst.add(DeptT.chemical, 10) sinfo2 = SInfoT("first2", "last2", GenT.male, 4.0, SeqADT([DeptT.materials, DeptT.civil]), True) sinfo1 = SInfoT("first", "last", GenT.female, 2.0, SeqADT([DeptT.materials, DeptT.chemical]), True) sinfo3 = SInfoT("first3", "last3", GenT.male, 3.9, SeqADT([DeptT.civil, DeptT.materials]), True) sinfo4 = SInfoT("first4", "last4", GenT.male, 5.0, SeqADT([DeptT.materials, DeptT.engphys]), True) sinfo5 = SInfoT("first5", "last5", GenT.male, 7.0, SeqADT([DeptT.engphys, DeptT.chemical]), True) SALst.init() SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) SALst.add("stdnt3", sinfo3) SALst.add("stdnt4", sinfo4) SALst.add("stdnt5", sinfo5) res = SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) assert res == ['stdnt5', 'stdnt4', 'stdnt2']
def test_salaverage(self): SALst.init() DCapALst.init() DCapALst.add(DeptT.civil, 10) DCapALst.add(DeptT.software, 10) DCapALst.add(DeptT.mechanical, 10) DCapALst.add(DeptT.engphys, 10) DCapALst.add(DeptT.materials, 10) DCapALst.add(DeptT.electrical, 10) DCapALst.add(DeptT.chemical, 10) sinfo2 = SInfoT("first2", "last2", GenT.male, 4.0, SeqADT([DeptT.materials, DeptT.civil]), True) sinfo1 = SInfoT("first", "last", GenT.female, 2.0, SeqADT([DeptT.materials, DeptT.chemical]), True) sinfo3 = SInfoT("first3", "last3", GenT.male, 3.9, SeqADT([DeptT.civil, DeptT.materials]), False) sinfo4 = SInfoT("first4", "last4", GenT.male, 5.0, SeqADT([DeptT.materials, DeptT.engphys]), True) sinfo5 = SInfoT("first5", "last5", GenT.male, 7.0, SeqADT([DeptT.engphys, DeptT.chemical]), True) SALst.init() SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) SALst.add("stdnt3", sinfo3) SALst.add("stdnt4", sinfo4) SALst.add("stdnt5", sinfo5) res = SALst.average(lambda x: x.gender == GenT.male) assert res == 4.975
def test_SALst(): sinfo = SInfoT('Bob', 'Tran', GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) sinfo1 = SInfoT('fname', 'lname', GenT.female, 8.2, SeqADT([DeptT.engphys, DeptT.mechanical]), False) sinfo2 = SInfoT('ay', 't', GenT.female, 8.1, SeqADT([DeptT.materials, DeptT.software]), True) SALst.init() SALst.add_stdnt('tranj52', sinfo) with pytest.raises(KeyError): SALst.add_stdnt('tranj52', sinfo) with pytest.raises(KeyError): SALst.remove('test') assert SALst.elm('tranj52') is True assert ((SALst.info('tranj52')).fname) == 'Bob' SALst.add_stdnt('kazia3', sinfo1) SALst.add_stdnt('friasg', sinfo2) assert SALst.sort(lambda x: x.freechoice) == ['tranj52', 'friasg'] assert SALst.average(lambda x: x.freechoice) == 10.05 with pytest.raises(ValueError): assert SALst.average(lambda x: x.gpa > 15) DCapALst.add(DeptT.civil, 8) DCapALst.add(DeptT.engphys, 5) DCapALst.add(DeptT.electrical, 0) SALst.allocate() assert AALst.lst_alloc(DeptT.engphys) == ['kazia3'] assert AALst.lst_alloc(DeptT.materials) == ['friasg']
def test_sort(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 8.0, SeqADT([DeptT.civil, DeptT.chemical]), True) sinfo2 = SInfoT( "srgseg", "lahdtst", GenT.female, 12.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), True) sinfo3 = SInfoT( "fufahf", "aijsf", GenT.female, 2.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), True) sinfo4 = SInfoT( "aggsg", "aijsagsgf", GenT.female, 6.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), False) SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) SALst.add("stdnt3", sinfo3) SALst.add("stdnt4", sinfo4) assert SALst.sort(lambda t: t.freechoice) == [ 'stdnt2', 'stdnt1', 'stdnt3' ] assert SALst.sort(lambda t: t.gpa >= 4.0) == [ 'stdnt2', 'stdnt1', 'stdnt4' ] assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == [ 'stdnt2', 'stdnt1' ]
class TestSALst: s1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) s2 = SInfoT("tory", "lory", GenT.female, 5.9, SeqADT([DeptT.software, DeptT.civil]), False) s3 = SInfoT( "Charlie", "Brown", GenT.male, 3.1, SeqADT( [DeptT.engphys, DeptT.software, DeptT.chemical, DeptT.materials]), True) s4 = SInfoT("John", "Smith", GenT.male, 7.1, [ DeptT.mechanical, DeptT.electrical, DeptT.materials, DeptT.mechanical, DeptT.electrical ], True) X1 = [("macid", s1), ("jane", s2)] X2 = [("jane", s2)] S1 = [("macid", s1), ("jsmith", s4), ("jane", s2), ("brownc", s3)] S2 = [("macid", s1), ("jsmith", s4)] def test_init(self): SALst.init() assert SALst.s == [] def test_add(self): SALst.add("macid", TestSALst.s1) SALst.add("jane", TestSALst.s2) assert SALst.s != [] assert SALst.s == TestSALst.X1 def test_add_raises_KeyError(self): with raises(KeyError): SALst.add("macid", TestSALst.s1) def test_remove(self): SALst.remove("macid") assert SALst.s == TestSALst.X2 def test_remove_raises_KeyError(self): with raises(KeyError): SALst.remove("tony") def test_elm(self): assert SALst.elm("jane") assert not SALst.elm("macid") def test_info(self): assert SALst.info("jane") == TestSALst.s2 def test_info_raises_KeyError(self): with raises(KeyError): SALst.info("tony") def test_sort_all(self): SALst.add("macid", TestSALst.s1) SALst.add("brownc", TestSALst.s3) SALst.add("jsmith", TestSALst.s4) SALst.sort(True) assert SALst.s == TestSALst.S1
def test_end_not(self): dept = [ 'civil', 'chemical', 'electrical', 'mechanical', 'software', 'materials', 'engphys' ] seqA = SeqADT(dept) element = seqA.next() assert not seqA.end()
def test_info(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 12.0, SeqADT([]), True) sinfo2 = SInfoT("", "", GenT.male, 11.4, SeqADT([]), False) SALst.add("Joe", sinfo1) SALst.add("Grant", sinfo2) assert SALst.info("Joe") == sinfo1 assert SALst.info("Grant") == sinfo2
def test_end_over_end(self): seqADT6 = SeqADT([1, "Hello", 2]) seqADT6.next() seqADT6.next() seqADT6.next() with pytest.raises(StopIteration): seqADT6.next() seqADT6.end()
def test_start(self): dept = [ 'civil', 'chemical', 'electrical', 'mechanical', 'software', 'materials', 'engphys' ] seqA = SeqADT(dept) seqA.start() assert seqA.i == 0
def test_info_raises_exception_when_nonempty(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 12.0, SeqADT([]), True) sinfo2 = SInfoT("", "", GenT.male, 11.4, SeqADT([]), False) SALst.add("Joe", sinfo1) SALst.add("Grant", sinfo2) with raises(KeyError): SALst.info("Bob")
def test_remove(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([]), True) sinfo2 = SInfoT("Frank", "Su", GenT.male, 11.4, SeqADT([]), False) SALst.add("Billy", sinfo1) SALst.add("Rob", sinfo2) SALst.remove("Billy") assert SALst.s[0][0] == "Rob" assert SALst.s[0][1] == sinfo2
def test_average(self): SALst.init() sinfo_1 = SInfoT('first', 'last', GenT.male, 8.0, SeqADT([DeptT.chemical, DeptT.civil]), True) SALst.add('ridhwan', sinfo_1) sinfo_2 = SInfoT('first', 'last', GenT.male, 8.5, SeqADT([DeptT.chemical, DeptT.civil]), True) SALst.add('youngboy', sinfo_2) assert SALst.average(lambda x: x.gender == GenT.male) == 8.25
def test_add_KeyError_exception_macid(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) sinfo2 = SInfoT( "dthhd", "dthdt", GenT.female, 8.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), True) SALst.add("stdnt1", sinfo1) with raises(KeyError): SALst.add("stdnt1", sinfo2)
def test_add(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 12.0, SeqADT([]), True) sinfo2 = SInfoT("", "", GenT.male, 11.4, SeqADT([]), False) SALst.add("Frank", sinfo1) SALst.add("Bob", sinfo2) assert SALst.s[0][0] == "Frank" assert SALst.s[0][1] == sinfo1 assert SALst.s[1][0] == "Bob" assert SALst.s[1][1] == sinfo2
def test_remove_raises_keyerror_when_notempty(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([]), True) sinfo2 = SInfoT("Frank", "Su", GenT.male, 11.4, SeqADT([]), False) SALst.add("Frank", sinfo1) SALst.add("Bob", sinfo2) with raises(KeyError): SALst.remove("Billy") with raises(KeyError): SALst.remove("John")
def test_add(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) sinfo2 = SInfoT( "first", "last", GenT.female, 8.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), True) SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) assert SALst.s["stdnt1"] == sinfo1 assert SALst.s["stdnt2"] == sinfo2
def test_elm_not_there(self): t = SALst t.init() m = "patelh75" m1 = "hero1" i = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) i1 = SInfoT("fsdfirst", "lasdfst", GenT.female, 11.0, SeqADT([DeptT.software, DeptT.chemical]), False) t.add(m, i) assert t.elm(m1) == False
def test_sort_nofreechoice(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 12, SeqADT([]), False) sinfo2 = SInfoT("", "", GenT.male, 11.8, SeqADT([]), False) sinfo3 = SInfoT("", "", GenT.male, 10, SeqADT([]), False) sinfo4 = SInfoT("", "", GenT.male, 9, SeqADT([]), False) SALst.add("Frank", sinfo1) SALst.add("Bob", sinfo2) SALst.add("Billy", sinfo3) SALst.add("Robin", sinfo4) assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == []
def test_sort_under_4gpa(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 3.99, SeqADT([]), True) sinfo2 = SInfoT("", "", GenT.male, 3.76, SeqADT([]), False) sinfo3 = SInfoT("", "", GenT.male, 2.3, SeqADT([]), True) sinfo4 = SInfoT("", "", GenT.male, 1.88, SeqADT([]), False) SALst.add("Frank", sinfo1) SALst.add("Bob", sinfo2) SALst.add("Billy", sinfo3) SALst.add("Robin", sinfo4) assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == []
def test_remove(self): SALst.init() sinfo1 = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) sinfo2 = SInfoT( "dthdt", "dthdt", GenT.female, 8.0, SeqADT([DeptT.materials, DeptT.engphys, DeptT.electrical]), True) SALst.add("stdnt1", sinfo1) SALst.add("stdnt2", sinfo2) SALst.remove("stdnt1") assert not SALst.elm("stdnt1")
def test_sort(self): SALst.init() sinfo_1 = SInfoT('first', 'last', GenT.male, 11.5, SeqADT([DeptT.software, DeptT.civil]), True) SALst.add('hey', sinfo_1) sinfo_2 = SInfoT('first', 'last', GenT.male, 11.5, SeqADT([DeptT.software, DeptT.civil]), True) SALst.add('hi', sinfo_2) assert SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0) == [ 'hey', 'hi' ]
def test_info_not_there(self): t = SALst t.init() m = "patelh75" m1 = "hero1" i = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) i1 = SInfoT("fsdfirst", "lasdfst", GenT.female, 11.0, SeqADT([DeptT.software, DeptT.chemical]), False) t.add(m, i) with pytest.raises(ValueError): t.info(m1)
def test_add_another(self): t = SALst t.init() m = "patelh75" m1 = "hero1" i = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) i1 = SInfoT("fsdfirst", "lasdfst", GenT.female, 11.0, SeqADT([DeptT.software, DeptT.chemical]), False) t.add(m, i) t.add(m1, i1) assert (t.s == [{"macid": m, "info": i}, {"macid": m1, "info": i1}])
def test_StdntAllocTypes(): x = ['a', 'b', 'c', 'd'] test = SeqADT(x) assert test.next() == 'a' assert test.next() == 'b' assert test.next() == 'c' assert test.next() == 'd' assert test.end() is True with pytest.raises(StopIteration): test.next() test.start() assert test.next() == 'a'
def test_average_2(self): sinfo5 = SInfoT("Cat", "Gonzal", GenT.female, 8, SeqADT([DeptT.software, DeptT.chemical]), True) sinfo6 = SInfoT("Pedram", "Yazdinia", GenT.male, 8, SeqADT([DeptT.software, DeptT.chemical]), False) sinfo3 = SInfoT("Dom", "Buswoki", GenT.male, 10, SeqADT([DeptT.software, DeptT.chemical]), False) SALst.add("gonzalc", sinfo5) SALst.add("yazdiniap", sinfo6) SALst.add("buswoki", sinfo3) assert SALst.average(lambda x: x.gender == GenT.male) == 9
def test_average(self): SALst.init() sinfo1 = SInfoT("", "", GenT.male, 4.82, SeqADT([]), True) sinfo2 = SInfoT("", "", GenT.female, 8.9, SeqADT([]), True) sinfo3 = SInfoT("", "", GenT.female, 2.8, SeqADT([]), True) sinfo4 = SInfoT("", "", GenT.male, 11.88, SeqADT([]), True) SALst.add("Frank", sinfo1) SALst.add("Bob", sinfo2) SALst.add("Billy", sinfo3) SALst.add("Robin", sinfo4) assert SALst.average( lambda x: x.gender == GenT.male) == 8.350000000000001 assert SALst.average(lambda x: x.gender == GenT.female) == 5.85
def test_exception_next(self): seqADT3 = SeqADT(["Hey", True, 8]) seqADT3.next() seqADT3.next() seqADT3.next() with pytest.raises(StopIteration): seqADT3.next()
def test_remove_already_removed(self): t = SALst t.init() m = "patelh75" m1 = "hero1" i = SInfoT("first", "last", GenT.male, 12.0, SeqADT([DeptT.civil, DeptT.chemical]), True) i1 = SInfoT("fsdfirst", "lasdfst", GenT.female, 11.0, SeqADT([DeptT.software, DeptT.chemical]), False) t.add(m, i) t.add(m1, i1) t.remove(m1) with pytest.raises(KeyError): t.remove(m1)