Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork30.8k
Add cycle creation utility and detection tests for Linked List (Fixes #583)#2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lazarljubenovic commentedMay 24, 2025
That's not a linked list anymore. |
Imran-imtiaz48 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great job on this test suite! Here are some specific observations and suggestions:
Positives
- Test Coverage: The tests cover a good range of scenarios, including:
- No cycle in the linked list
- Correct cycle creation and detection
- Handling invalid positions for cycle creation (out-of-bounds and negative)
- Readability: Test cases are clear and descriptive, making it easy to understand the intention behind each scenario.
- Setup: Using
beforeEach
to initialize a newLinkedList
keeps tests isolated and reliable.
Suggestions/Improvements
Edge Cases:
Consider adding tests for these edge cases:- An empty list (should return false for cycle detection).
- A list with a single node (cycle vs. no cycle).
- Creating a cycle at position 0 (head node).
Assertions:
IfcreateCycle
returns a value (such as success/failure), consider asserting it as well to make the effect of the function explicit.Comments:
Your current comments are helpful! If possible, expand them a bit for maintainability, especially in less obvious scenarios.Consistency:
The pattern and naming are consistent and align with best practices for unit testing in JavaScript.
lazarljubenovic commentedJun 27, 2025
What a waste of GPU cycles. |
Description:
This pull request adds the ability to create a cycle in the linked list by linking the tail node to any node at a specified position. It includes:
A utility function createCycle(list, position) that links the last node to the node at the given position to form a cycle.
Unit tests to verify cycle creation and detection using the existing detectCycle function.
Tests cover normal cases, invalid positions, and no-cycle scenarios.
This addresses the feature request in issue#583 opened by@chrisVillanueva, enabling users to create and detect cycles within linked lists for more comprehensive linked list operations.
Please review the implementation and tests. Looking forward to your feedback!