def test_LinkedListT_prepend(self): ll = LinkedListT() ll.prepend(5) self.assertEqual(ll.length, 1) self.assertTrue(ll.contains(5)) ll.prepend(1) ll.prepend(2) self.assertEqual(ll.length, 3) self.assertTrue(ll.contains(1)) self.assertTrue(ll.contains(2)) self.assertFalse(ll.contains(0))
def test_LinkedListT_remove(self): ll = LinkedListT() ll.prepend(5) self.assertEqual(ll.length, 1) self.assertTrue(ll.contains(5)) ll.remove(5) self.assertEqual(ll.length, 0) self.assertFalse(ll.contains(5)) ll.prepend(1) ll.prepend(2) self.assertEqual(ll.length, 2) self.assertFalse(ll.contains(5)) self.assertTrue(ll.contains(1)) self.assertTrue(ll.contains(2)) ll.remove(1) ll.remove(2) self.assertEqual(ll.length, 0) self.assertFalse(ll.contains(1)) self.assertFalse(ll.contains(2))
def test_LinkedListT_is_palindrome(self): ll = LinkedListT(2) self.assertFalse(ll.isPalindrome()) ll = LinkedListT() for i in range(0,3): ll.prepend(i) for i in range(2, -1, -1): ll.prepend(i) self.assertTrue(ll.isPalindrome()) lt = LinkedListT() for i in range(0,3): lt.prepend(i) lt.append(i) self.assertTrue(lt.isPalindrome())