Пример #1
0
def test_end_2():
    constructor_test = SeqADT(
        [DeptT.software, DeptT.electrical, DeptT.engphys])
    constructor_test.next()
    constructor_test.next()
    constructor_test.next()
    assert constructor_test.end() is True
Пример #2
0
 def test_seqadt_end(self):
     new_seq = SeqADT([0, 1, 2, 3])
     new_seq.next()
     new_seq.next()
     new_seq.next()
     end_bool = new_seq.end()
     assert end_bool is True
Пример #3
0
class TestSeqADT:
    def setup_method(self):
        self.seq = SeqADT([1, 2, 3])
        self.seq_empty = SeqADT([])

    def teardown_method(self):
        self.seq = None
        self.seq_empty = None

    def test_seq_init(self):
        assert (self.seq.s == [1, 2, 3])

    def test_seq_next(self):
        with pytest.raises(StopIteration):
            assert self.seq.next() == 1
            assert self.seq.next() == 2
            assert self.seq.next() == 3
            self.seq.next()

    def test_seq_start(self):
        assert self.seq.start() == 1

    def test_seq_end(self):
        assert self.seq.end() == False
        assert self.seq_empty.end() == True
Пример #4
0
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'
class TestSeqADT:
    def setup_method(self):
        self.new = SeqADT(["test1", "test2", "test3"])

    def teardown_method(self):
        self.new = None

    def test_empty(self):
        new = SeqADT([])
        with pytest.raises(StopIteration):
            new.next()

    def test_stop_iteration(self):
        new = SeqADT(["Test1"])
        new.next()
        with pytest.raises(StopIteration):
            new.next()

    def test_next(self):
        assert self.new.next() == "test1"

    def test_end_false(self):
        assert not self.new.end()

    def test_end_true(self):
        self.new.next()
        self.new.next()
        self.new.next()
        assert self.new.end()

    def test_start(self):
        self.new.next()
        self.new.start()
        assert self.new.next() == "test1"
Пример #6
0
class TestSeqADT:
    def setup_method(self, method):
        #setup the initial cases for every function
        self.sequence = SeqADT([DeptT.mechanical, DeptT.civil])
        self.empty = SeqADT([])

    def teardown_method(self, method):
        #teardown the initial cases
        self.sequence = None
        self.empty = None

    def test_init_method(self):
        #test for __init__ function
        assert self.sequence.seq == [DeptT.mechanical, DeptT.civil]
        assert self.sequence.count == 0

    def test_start_method(self):
        #test start function by testing count
        self.sequence.count = 4
        self.sequence.start()
        assert self.sequence.count == 0

    def test_next_method(self):
        # the first next
        assert self.sequence.next() == DeptT.mechanical
        assert self.sequence.count == 1

        # the second next
        self.sequence.next()
        assert self.sequence.next() == DeptT.civil
        assert self.sequence.count == 2

        # end with raise StopIteration
        with pytest.raises(StopIteration):
            self.sequence.next()

    def test_end_method(self):
        # test end function
        self.sequence.count = 2
        assert self.sequence.end()

    def test_init_empty(self):
        # test with empty list
        assert self.empty.seq == []
        assert self.empty.seq == 0

    def test_start_empty(self):
        # test start method with empty list
        self.empty.count = 2
        self.empty.start()
        assert self.empty.count == 0

    def test_next_empty(self):
        #test next method with empty list
        with pytest.raises(StopIteration):
            self.empty.next()

    def test_end_empty(self):
        #test end method with empty list
        assert self.empty.end()
Пример #7
0
 def test_end_not(self):
     dept = [
         'civil', 'chemical', 'electrical', 'mechanical', 'software',
         'materials', 'engphys'
     ]
     seqA = SeqADT(dept)
     element = seqA.next()
     assert not seqA.end()
Пример #8
0
 def test_next_raises_stopiteration(self):
     sequence = SeqADT([1, 2, 3])
     sequence.next()
     sequence.next()
     sequence.next()
     with raises(StopIteration):
         sequence.next()
Пример #9
0
 def test_exception_next(self):
     seqADT3 = SeqADT(["Hey", True, 8])
     seqADT3.next()
     seqADT3.next()
     seqADT3.next()
     with pytest.raises(StopIteration):
         seqADT3.next()
Пример #10
0
 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()
Пример #11
0
def test_next_except():
    constructor_test = SeqADT(
        [DeptT.software, DeptT.electrical, DeptT.engphys])
    constructor_test.next()
    constructor_test.next()
    constructor_test.next()
    with pytest.raises(Exception):
        constructor_test.next()
Пример #12
0
class TestSeqADT:
    def setup_method(self, method):
        self.test = SeqADT([DeptT.civil, DeptT.chemical])

    def teardown_method(self, method):
        self.test = None

    # test if init works
    def test_init(self):
        assert self.test.next() == DeptT.civil
        assert self.test.next() == DeptT.chemical

    # tests if start resets i
    def test_start(self):
        self.test.next()
        assert self.test.i == 1
        self.test.start()
        assert self.test.i == 0

    # tests if StopIteration error is raised
    def test_next_1(self):
        with pytest.raises(StopIteration):
            self.test.i = len(self.test.s)
            self.test.next()

    # tests if next() outputs correctly
    def test_next_2(self):
        assert self.test.next() == DeptT.civil
        assert self.test.next() == DeptT.chemical

    # tests if end() works
    def test_end_1(self):
        assert not self.test.end()

    # tests if end() works
    def test_end_2(self):
        self.test.i = len(self.test.s)
        assert self.test.end()
        self.test.i = len(self.test.s) + 1000
        assert self.test.end()
Пример #13
0
 def test_next(self):
     sequence = SeqADT([2, 4, 6])
     assert sequence.next() == 2
     assert sequence._SeqADT__i == 1
Пример #14
0
 def test_end_at_end(self):
     seqADT5 = SeqADT([1, "Hello", 2])
     seqADT5.next()
     seqADT5.next()
     seqADT5.next()
     assert seqADT5.end() == True
Пример #15
0
 def test_end_not_end(self):
     seqADT4 = SeqADT([1, "Hello", 2])
     seqADT4.next()
     seqADT4.next()
     assert seqADT4.end() == False
Пример #16
0
 def test_seq_next(self):
     val1 = SeqADT([10, 1])
     x = val1.next()
     assert x == 10
Пример #17
0
 def test_second_next_element_1(self):
     seqADT3 = SeqADT(["Hey", True, 8, 9])
     seqADT3.next()
     assert seqADT3.next() == True
Пример #18
0
 def test_first_next_element_0(self):
     seqADT2 = SeqADT(["Hey", 2, 3, 4, 5])
     assert seqADT2.next() == "Hey"
Пример #19
0
 def test_raises_stopiteration_seq_next(self):
     val2 = SeqADT([])
     with raises(StopIteration):
         val2.next()
Пример #20
0
class TestAll:
    def setup_method(self, method):
        self.sinfo1 = SInfoT("first", "last", GenT.male, 12.0,
                             SeqADT([DeptT.civil, DeptT.chemical]), True)
        self.sinfo2 = SInfoT("first1", "last", GenT.female, 7.0,
                             SeqADT([DeptT.civil, DeptT.chemical]), True)
        self.sinfo3 = SInfoT("first2", "last", GenT.male, 12.0,
                             SeqADT([DeptT.civil, DeptT.chemical]), False)
        self.sinfo4 = SInfoT("first3", "last", GenT.male, 12.0,
                             SeqADT([DeptT.civil, DeptT.chemical]), False)

        self.choices = SeqADT([DeptT.civil, DeptT.mechanical, DeptT.engphys])
        self.SeqADT_None = SeqADT(None)
        self.SeqADT_list = SeqADT([1, 2, 3, 4])
        self.DCapALst = DCapALst()
        self.SALst = SALst()

    def teardown_method(self, method):
        self.sinfo1 = None
        self.sinfo2 = None
        self.sinfo3 = None
        self.sinfo4 = None
        self.choices = None
        self.SeqADT_None = None
        self.SeqADT_list = None
        self.DCapALst = self.DCapALst.s.clear()
        self.SALst = self.SALst.s.clear()

    def test_SeqADT_init1(self):
        assert not self.SeqADT_None.s

    def test_SeqADT_init2(self):
        assert self.SeqADT_None.i == 0

    def test_SeqADT_init3(self):
        assert self.SeqADT_list.s == [1, 2, 3, 4]

    def test_SeqADT_start1(self):
        self.choices.start()
        assert self.choices.i == 0

    def test_SeqADT_start2(self):
        self.choices.next()
        self.choices.next()
        self.choices.start()
        assert self.choices.i == 0

    def test_SeqADT_next1(self):
        assert self.choices.next() == DeptT.civil

    def test_SeqADT_next2(self):
        self.choices.next()
        assert self.choices.next() == DeptT.mechanical

    def test_SeqADT_next3(self):
        self.choices.next()
        self.choices.next()
        assert self.choices.next() == DeptT.engphys

    def test_SeqADT_next4(self):
        with pytest.raises(StopIteration):
            self.choices.next()
            self.choices.next()
            self.choices.next()
            self.choices.next()

    def test_SeqADT_end1(self):
        assert not (self.choices.end())

    def test_SeqADT_end2(self):
        self.choices.next()
        self.choices.next()
        self.choices.next()
        assert self.choices.end()

    def test_DCapALst_init1(self):
        assert self.DCapALst.s == {}

    def test_DCapALst_add1(self):
        self.DCapALst.add(DeptT.civil, 10)
        self.DCapALst.add(DeptT.chemical, 20)
        assert self.DCapALst.s == {DeptT.civil: 10, DeptT.chemical: 20}

    def test_DCapALst_add2(self):
        with pytest.raises(KeyError):
            self.DCapALst.add(DeptT.civil, 10)
            self.DCapALst.add(DeptT.civil, 10)

    def test_DCapALst_remove1(self):
        self.DCapALst.add(DeptT.civil, 10)
        self.DCapALst.remove(DeptT.civil)
        assert self.DCapALst.s == {}

    def test_DCapALst_remove2(self):
        with pytest.raises(KeyError):
            self.DCapALst.remove(DeptT.mechanical)

    def test_DCapALst_elm(self):
        self.DCapALst.add(DeptT.civil, 10)
        assert self.DCapALst.elm(DeptT.civil)

    def test_DCapALst_capacity1(self):
        self.DCapALst.add(DeptT.civil, 10)
        assert self.DCapALst.capacity(DeptT.civil) == 10

    def test_DCapALst_capacity2(self):
        with pytest.raises(KeyError):
            self.DCapALst.capacity(DeptT.civil)

    def test_SALst_init1(self):
        assert self.SALst.s == {}

    def test_SALst_add1(self):
        self.SALst.add("student", ["test"])
        assert self.SALst.s == {"student": ["test"]}

    def test_SALst_add2(self):
        with pytest.raises(KeyError):
            self.SALst.add("student", ["test"])
            self.SALst.add("student", ["test"])

    def test_SALst_remove1(self):
        self.SALst.add("student", ["test"])
        self.SALst.remove("student")
        assert self.SALst.s == {}

    def test_SALst_remove2(self):
        with pytest.raises(KeyError):
            self.SALst.remove("student")

    def test_SALst_sort1(self):
        self.SALst.add("s1", self.sinfo1)
        self.SALst.add("s2", self.sinfo2)
        self.SALst.add("s3", self.sinfo3)
        self.SALst.add("s4", self.sinfo4)

        g = self.SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0)
        assert g == ["s1", "s2"]

    def test_SALst_sort2(self):
        g = self.SALst.sort(lambda t: t.freechoice and t.gpa >= 4.0)
        assert g == []

    def test_SALst_average1(self):
        self.SALst.add("s1", self.sinfo1)
        self.SALst.add("s2", self.sinfo2)
        self.SALst.add("s3", self.sinfo3)
        self.SALst.add("s4", self.sinfo4)

        assert self.SALst.average(lambda x: x.gender == GenT.male) == 12.0

    def test_SALst_average2(self):
        with pytest.raises(ValueError):
            self.SALst.add("s1", self.sinfo1)
            self.SALst.add("s3", self.sinfo3)
            self.SALst.add("s4", self.sinfo4)
            self.SALst.average(lambda x: x.gender == GenT.female)

    def test_SALst_allocate1(self):
        self.DCapALst.add(DeptT.chemical, 2)
        self.DCapALst.add(DeptT.civil, 2)
        self.SALst.add("s1", self.sinfo1)
        self.SALst.add("s2", self.sinfo2)
        self.SALst.add("s3", self.sinfo3)
        self.SALst.add("s4", self.sinfo4)

        self.SALst.allocate()
        assert AALst.lst_alloc(DeptT.civil) == ["s1", "s2"]

    def test_SALst_allocate2(self):
        self.DCapALst.add(DeptT.chemical, 2)
        self.DCapALst.add(DeptT.civil, 2)

        self.SALst.allocate()
        assert AALst.lst_alloc(DeptT.civil) == []

    def test_SAL_allocate3(self):
        with pytest.raises(RuntimeError):
            self.DCapALst.add(DeptT.civil, 0)
            self.DCapALst.add(DeptT.chemical, 0)
            self.SALst.add("s3", self.sinfo3)
            self.SALst.allocate()

    def test_SALst_allocate4(self):
        self.DCapALst.add(DeptT.chemical, 1)
        self.DCapALst.add(DeptT.civil, 2)
        self.SALst.add("s1", self.sinfo1)
        self.SALst.add("s2", self.sinfo2)
        self.SALst.add("s3", self.sinfo3)

        self.SALst.allocate()
        assert AALst.lst_alloc(DeptT.chemical) == ["s3"]
Пример #21
0
 def test_seqadt_next_excep(self):
     new_seq = SeqADT([])
     with pytest.raises(StopIteration):
         index = new_seq.next()
Пример #22
0
 def test_end(self):
     s = SeqADT([1, 2])
     s.next()
     s.next()
     assert s.end() == True
Пример #23
0
 def test_empty(self):
     empty = SeqADT([])
     with pytest.raises(StopIteration):
         empty.next()
Пример #24
0
 def test_seq_next(self):
     sequence = SeqADT([DeptT.civil, DeptT.software, DeptT.chemical])
     assert sequence.next() == DeptT.civil
     assert sequence.next() == DeptT.software
     assert sequence.next() == DeptT.chemical
 def test_stop_iteration(self):
     new = SeqADT(["Test1"])
     new.next()
     with pytest.raises(StopIteration):
         new.next()
Пример #26
0
 def test_seq_next_stop(self):
     sequence = SeqADT([])
     with raises(StopIteration):
         sequence.next()
Пример #27
0
 def test_empty_next(self):
     s = SeqADT([])
     with pytest.raises(StopIteration):
         s.next()
Пример #28
0
 def test_end(self):
     sequence = SeqADT([3, 5])
     assert not sequence.end()
     sequence.next()
     sequence.next()
     assert sequence.end()
Пример #29
0
 def test_next(self):
     s = SeqADT([1, 2, 3])
     s.next()
     s.next()
     assert s.next() == 3
Пример #30
0
 def test_seqadt_next_base(self):
     new_seq = SeqADT([0, 1, 2, 3])
     index = new_seq.next()
     assert index == 0