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
def test_value_at(self): xx = [ 1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432', '324saf' ] lt1 = Zlist(xx) lt2 = Zlist() for i in range(len(xx)): # print(lt1.value_at(i), xx[i]) self.assertEqual(lt1.value_at(i), xx[i]) with self.assertRaises(ListError) as ex: lt1.value_at(len(xx)) for i in range(3): with self.assertRaises(ListError) as ex: lt2.value_at(i)
def test_push_bask(self): xx = [ 1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432', '324saf' ] lt1 = Zlist() for i in range(len(xx)): lt1.push_back(xx[i]) self.assertEqual(xx[i], lt1.value_at(i)) self.assertEqual(lt1.get_size(), i + 1)
def test_push_front(self): lt1 = Zlist() xx = [ 1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432', '324saf' ] for i in range(len(xx)): lt1.push_front(xx[i]) self.assertEqual(lt1.value_at(0), xx[i]) self.assertEqual(lt1.get_size(), i + 1)
def test_reverse(self): xx = [ 1, 2, 2, 3, 3223, 4, 32, 5, 43, 543, 5, 4, 645, 64, '', '32432', '324saf' ] lt = Zlist(xx) lt.reverse() xx.reverse() for i in range(len(xx)): # print(lt.value_at(i), xx[i]) self.assertEqual(lt.value_at(i), xx[i])