Question
Write a test case that fails when run on a buggy contains_non_satisfier. def contains_non_satisfier(obj: Union[int, list], predicate: Callable[[int], bool]) -> bool: Return whether obj contains
Write a test case that fails when run on a buggy contains_non_satisfier.
def contains_non_satisfier(obj: Union[int, list], predicate: Callable[[int], bool]) -> bool: """Return whether obj contains at least one element that does *not* satisfy predicate.
If obj is an int, returns True if obj does *not* satisfy predicate (i.e. predicate(obj) is False)
>>> def p(n: int) -> bool: ... return n < 10 >>> contains_non_satisfier(5, p) False >>> contains_non_satisfier(15, p) True >>> contains_non_satisfier([5, 2, [15, 7], 9], p) True """ if isinstance(obj, int): if not predicate(obj): return True else: return False list_of_ints = [x for x in obj if isinstance(x, int)] list_of_lists = [y for x in obj if isinstance(x, list) for y in x] obj = list_of_lists + list_of_ints if len([x for x in obj if predicate(x)]) != 0: return True return False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started