Closed emmacgodfrey closed 3 years ago
You have a good falsifying example with
xs=[0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -2],
The next step is to figure out exactly which one of these items is causing the bad behavior. Do this by using
xs=[0]
xs=[0, 0]
xs=[0,0,0]
...
until you find the particular insert that is problematic. Then you'll be able to debug that particular insert in isolation.
Or, if you're feeling really savvy, you don't have to do a linear search to find the problematic insert; you could do a binary search to save yourself a bit of time.
Hi @mikeizbicki ,
Yes, sorry I should have included that in the initial issue. The bug occurs at the very end of the list insertion (i.e. trying to insert -2). I have tried to debug with various print statements, and I still can't figure it out.
>>> heap = Heap()
>>> heap.insert_list([0,0,0,0,0,0,0,0,0,-1,-1,0,0,0,0])
>>> str(heap)
'(-1 - (-1 - (0 - (0 - - ) - (0 - - ) ) - (0 - (0 - - ) - (0 - - ) ) ) - (0 - (0 - (0 - - ) - (0 - - ) ) - (0 - (0 - - ) - (0 - - ) ) ) )'
>>> heap.insert_list([-2])
>>> str(heap)
'(-2 - (-1 - (0 - (-1 - (0 - - ) - ) - (0 - - ) ) - (0 - (0 - - ) - (0 - - ) ) ) - (0 - (0 - (0 - - ) - (0 - - ) ) - (0 - (0 - - ) - (0 - - ) ) ) )'
Somehow the -1 is moving further down in the heap...any thoughts?
Found one of the bugs that was causing this failed test case. Thanks!
Hi @mikeizbicki,
I am trying to finish up the homework for this week, and I have encountered a very frustrating bug.
When I run the test cases, the first error I get is the following:
Upon testing this error manually, I agree that the heap is not satisfied. More specifically, this is the tree that I obtain.
Aside from this case, I keep trying to insert lists of different sizes and compositions and my function seems to work.
For instance,
I am stuck.
This is my code for my insert function. Any suggestions would be appreciated.
Thanks,
Emma