def test_kth_is_in_ll_somewhere(): ll = LinkedList([1, 2, 3, 4]) assert ll.kth_from_end(0) == 4 assert ll.kth_from_end(1) == 3 assert ll.kth_from_end(3) == 1
def test_ll_is_size_one(): ll = LinkedList([100]) assert ll.kth_from_end(0) == 100
def test_k_is_equal_to_list_length(): ll = LinkedList([1, 2, 3]) val = 3 with pytest.raises(Exception) as context: ll.kth_from_end(val) assert str(context.value) == f'Invalid index: {val} is out of range on linked list'
def test_k_is_negative(): ll = LinkedList() val = -1 with pytest.raises(Exception) as context: ll.kth_from_end(val) assert str(context.value) == f'Invalid index: {val} is out of range on linked list'
def test_k_is_greater_than_list_length(): ll = LinkedList() val = 1 with pytest.raises(Exception) as context: ll.kth_from_end(val) assert str(context.value) == f'Invalid index: {val} is out of range on linked list'