Esempio n. 1
0
    def test_insert(self):
        xx = [
            1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432',
            '324saf'
        ]
        lt = Zlist(xx)

        with self.assertRaises(ListError) as ex:
            lt.insert(lt.get_size() + 1, 111)

        xx2 = xx[:]
        for i in range(10):
            xx2.insert(i, i)
            lt.insert(i, i)
            self.assertEqual(xx2[i], lt.value_at(i))

        lt2 = Zlist()
        # print(lt2.get_size())
        lt2.insert(0, 1)
        # print(lt2.get_size())
        self.assertEqual(lt2.front(), 1)
        lt2.pop_back()
        # print(lt2.get_size())
        with self.assertRaises(ListError) as ex:
            lt2.insert(1, 1)
        pass
Esempio n. 2
0
 def test_pop_back(self):
     xx = [
         1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432',
         '324saf'
     ]
     lt = Zlist(xx)
     len_xx = len(xx)
     for i in range(len_xx):
         # print(lt.pop_back(), xx[len_xx-i-1])
         lt_val = lt.pop_back()
         # print("test:", lt_val, xx[len_xx-i-1])
         self.assertEqual(lt_val, xx[len_xx - i - 1])
         self.assertEqual(lt.get_size(), len(xx) - i - 1)
     self.assertEqual(lt.pop_back(), None)