def test_get_first(self): l = DoublyLinkedList() self.assertRaises(IndexError, l.get_first) for i in range(50): l.add_first(i) self.assertEqual(l.get_first(), i)
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())
def test_remove_first(self): l = DoublyLinkedList() self.assertTrue(l.is_empty()) l.add('a') l.add('b') l.add('c') self.assertEqual(len(l), 3) l.remove_first() self.assertEqual(len(l), 2) self.assertEqual(l.get_first(), 'b') l.remove_first() self.assertEqual(len(l), 1) self.assertEqual(l.get_first(), 'c') l.remove_first() self.assertRaises(IndexError, l.remove_first) self.assertEqual(len(l), 0) self.assertTrue(l.is_empty())
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)