I am having trouble deciding the proper model to use for my “link_nodes” method. I utilized Floyd’s Cycle-Finding Algorithm to prevent loops, but when I run the unit test box a Value Error is generated. Is something wrong with the unit tests?
My assignment has been submitted and I have passed with 75/100. I would greatly appreciate any help before tomorrow to earn a full score.
Hi @MaxCoder46
Could you share the detailed error message? That would help us find the cause of the issue. This could be related to how the algorithm handles edge cases. Make sure you algorithm works fine in all cases!
Hope it helps! looking forward to helping you out!
Good morning.
Here is the error message. Thank you in advance for your assistance:
ValueError Traceback (most recent call last)
Cell In[40], line 1
----> 1 unittests.test_DoublyLinkedListFixed(DoublyLinkedListFixed)
File ~/work/unittests.py:230, in test_DoublyLinkedListFixed(learner_func)
228 cases.append(t)
229 return cases
→ 230 cases = g()
231 print_feedback(cases)
File ~/work/unittests.py:203, in test_DoublyLinkedListFixed..g()
201 for val in vals:
202 s.add_node(val)
→ 203 s.link_nodes(s.tail, s.head)
204 t = test_case()
205 time_limit = 1
Cell In[39], line 61
59 node1.next = None
60 node2.prev = None
—> 61 raise ValueError(“Linking these nodes would create a cycle.”)
63 # Update head and tail if necessary
64 if self.tail == node1:
ValueError: Linking these nodes would create a cycle.