def setUp(self) -> None: self.list = SinglyLinkedList() self.list.add_last(5) self.list.add_last(10) self.list.add_last(7) self.list.add_last(8) self.list.add_last(1)
def test_peek_last_empty(self): _list = SinglyLinkedList() self.assertIsNone(_list.peek_last())
def test_is_empty(self): _list = SinglyLinkedList() self.assertTrue(_list.is_empty)
def test_remove_first_from_empty(self): empty_list = SinglyLinkedList() with self.assertRaises(RuntimeError): empty_list.remove_first()
def test_add_last_empty(self): _list = SinglyLinkedList() _list.add_last(10) self.assertEqual([x for x in _list], [10])
def test_index_of_empty(self): _list = SinglyLinkedList() index = _list.indexof(4) self.assertEqual(index, -1)
def test_remove_at_index_high(self): _list = SinglyLinkedList() with self.assertRaises(IndexError): _list.remove(10)
def test_add_at_index_last(self): _list = SinglyLinkedList() _list.add_last(1) _list.add_last(10) _list.add(5, 2) self.assertEqual([x for x in _list], [1, 10, 5])
def test_add_at_index_first(self): _list = SinglyLinkedList() _list.add(1, 0) self.assertEqual([x for x in _list], [1])