def test_index_of(self): l = DoublyLinkedList() self.assertRaises(ValueError, l.index_of, 'a') for i in range(5): l.add(1) self.assertEqual(l.index_of(1), 0) l.remove_last() l.add(2) self.assertEqual(l.index_of(2), 4) l.remove_first() l.add_first(2) self.assertEqual(l.index_of(1), 1)
def test_delete(self): l = DoublyLinkedList() self.assertRaises(ValueError, l.delete, 0) for i in range(5): l.add(i) self.assertTrue(l.contains(i)) l.delete(2) self.assertFalse(l.contains(2)) self.assertEqual(l.index_of(1), 1) self.assertEqual(l.index_of(3), 2) self.assertEqual(l.get_elements(), 4) l.delete(0) self.assertFalse(l.contains(0)) self.assertEqual(l.get_first(), 1) self.assertEqual(l.index_of(3), 1) self.assertEqual(l.get_elements(), 3) l.delete(4) self.assertFalse(l.contains(4)) self.assertEqual(l.get_last(), 3) self.assertEqual(l.get_first(), 1) self.assertRaises(ValueError, l.index_of, 4) self.assertEqual(l.get_elements(), 2) l.delete(1) self.assertFalse(l.contains(1)) self.assertEqual(l.get_first(), 3) self.assertEqual(l.get_last(), 3) self.assertEqual(l.get_elements(), 1) l.delete(3) self.assertTrue(l.is_empty()) self.assertEqual(l.get_elements(), 0)
def test_add(self): l = DoublyLinkedList() self.assertTrue(l.is_empty()) l.add(0) self.assertEqual(l.get_first(), 0) self.assertEqual(l.get_last(), 0) self.assertEqual(l.get_elements(), 1) l.add(1) self.assertEqual(l.get_last(), 1) self.assertNotEqual(l.get_first(), 1) self.assertEqual(l.get_first(), 0) self.assertEqual(l.get_elements(), 2) l.add(2) self.assertEqual(l.get_last(), 2) self.assertEqual(l.get_first(), 0) self.assertEqual(l.index_of(1), 1) self.assertEqual(l.get_elements(), 3) self.assertFalse(l.is_empty())