question 235 Debugging & Logging · medium
Shrink a failing input
The first step of debugging is a small input that still shows the bug. Doing that by hand on a 500-row file is slow, so automate it. Write shrink_failure(items, fails): fails(some_list) is the caller's own test and returns True when the bug shows up for that list. Starting from items (for which fails is True), remove items one at a time, keeping each removal only if the bug still shows, and return what is left.
Function
shrink_failure(items, fails)Methodstart at position 0. Try the list without the item at the current position: if
fails is still True, keep that shorter list and stay at the same position; otherwise move to the next position. Stop at the end of the listReturnsa new list; the items left keep their original order
Must notchange
items