Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
sowmya-rebbavarapu wants to merge1 commit intotrekhleb:master
base:master
Choose a base branch
Loading
fromsowmya-rebbavarapu:feat/linked-list-cycle

Conversation

sowmya-rebbavarapu
Copy link

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!

lazarljubenovic reacted with thumbs down emoji
@lazarljubenovic
Copy link

That's not a linked list anymore.

Copy link

@Imran-imtiaz48Imran-imtiaz48 left a 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: UsingbeforeEach to initialize a newLinkedList keeps tests isolated and reliable.

Suggestions/Improvements

  1. 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).
  2. Assertions:
    IfcreateCycle returns a value (such as success/failure), consider asserting it as well to make the effect of the function explicit.

  3. Comments:
    Your current comments are helpful! If possible, expand them a bit for maintainability, especially in less obvious scenarios.

  4. Consistency:
    The pattern and naming are consistent and align with best practices for unit testing in JavaScript.


lazarljubenovic reacted with thumbs down emoji
@lazarljubenovic
Copy link

What a waste of GPU cycles.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Imran-imtiaz48Imran-imtiaz48Imran-imtiaz48 left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@sowmya-rebbavarapu@lazarljubenovic@Imran-imtiaz48

[8]ページ先頭

©2009-2025 Movatter.jp