def test_kth_negative(): link_list = LinkedList() link_list.insert(1) link_list.insert(2) link_list.insert(3) link_list.insert(4) with pytest.raises(Exception): link_list.kthFromEnd(-4)
def test_kth_greater_than_ll_length(): link_list = LinkedList() link_list.insert(1) link_list.insert(2) link_list.insert(3) link_list.insert(4) with pytest.raises(Exception): link_list.kthFromEnd(5)
def test_kth_equal_to_ll_length(): link_list = LinkedList() link_list.insert(1) link_list.insert(2) link_list.insert(3) link_list.insert(4) with pytest.raises(Exception): link_list.kthFromEnd(4)
def test_kth_middle_value(): link_list = LinkedList() link_list.insert(1) link_list.insert(10) link_list.insert(100) link_list.insert(1000) actual = link_list.kthFromEnd(2) expected = 100 assert actual == expected
def test_kth_size_one(): link_list = LinkedList() link_list.insert(1) actual = link_list.kthFromEnd(0) expected = 1 assert actual == expected
def test_nine(): ll = LinkedList(Node(1, Node(2, Node(3, Node(4, Node(5)))))) actual = ll.kthFromEnd(5) expected = 'Same length' assert actual == expected
def test_eight(): ll = LinkedList(Node(1, Node(2, Node(3, Node(4, Node(5)))))) actual = ll.kthFromEnd(0) expected = 5 assert actual == expected
def test_twelve(): ll = LinkedList(Node(1, Node(2, Node(3, Node(4, Node(5)))))) actual = ll.kthFromEnd(3) expected = 2 assert actual == expected
def test_eleven(): ll = LinkedList(Node(1)) actual = ll.kthFromEnd(0) expected = 1 assert actual == expected
def test_ten(): ll = LinkedList(Node(1, Node(2, Node(3, Node(4, Node(5)))))) actual = ll.kthFromEnd(-1) expected = 'Negative numbers not allowed' assert actual == expected