Skip to content

Fix unused visited_clone variable in clone graph test verification#86

Merged
kobukuro merged 3 commits intofeat/add-clone-graph-solution-and-testsfrom
copilot/sub-pr-85
Feb 19, 2026
Merged

Fix unused visited_clone variable in clone graph test verification#86
kobukuro merged 3 commits intofeat/add-clone-graph-solution-and-testsfrom
copilot/sub-pr-85

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

The visited_clone set was populated but never used in the deep copy verification helper, leaving graph structure validation incomplete.

Changes:

  • Add assertion to verify clone maintains graph structure when revisiting nodes (cycles/shared references)
  • Update .gitignore to exclude Python cache files
def verify_nodes(orig, cln):
    # Avoid infinite loops
    if orig in visited_orig:
        # If we've seen this original node, we should have seen the clone too
        assert cln in visited_clone  # ← Added verification
        return
    visited_orig.add(orig)
    visited_clone.add(cln)

This ensures that when the original graph has cycles or shared node references, the clone preserves the same structural properties rather than creating duplicate nodes.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 19, 2026 05:52
Co-authored-by: kobukuro <9405082+kobukuro@users.noreply.github.com>
Co-authored-by: kobukuro <9405082+kobukuro@users.noreply.github.com>
@kobukuro kobukuro marked this pull request as ready for review February 19, 2026 05:54
Copilot AI review requested due to automatic review settings February 19, 2026 05:54
Copilot AI changed the title [WIP] Implement changes based on review feedback for Clone Graph Fix unused visited_clone variable in clone graph test verification Feb 19, 2026
Copilot AI requested a review from kobukuro February 19, 2026 05:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses review feedback on the Clone Graph problem by adding verification logic for the visited_clone variable that was previously unused. The changes include adding an assertion to verify that the cloned graph maintains the same structure as the original graph when cycles are encountered, and updating .gitignore to exclude Python cache files.

Changes:

  • Added assertion in test verification to check that when an original node is revisited, its corresponding clone has also been visited
  • Updated .gitignore to exclude __pycache__/ directories and *.pyc files

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
problems/medium/clone_graph_133/test_solution.py Added assertion to verify clone graph structure consistency when encountering previously visited nodes
.gitignore Added Python cache file patterns to prevent tracking compiled bytecode
Comments suppressed due to low confidence (1)

problems/medium/clone_graph_133/test_solution.py:26

  • This assertion verifies that if an original node has been visited, its corresponding clone has also been visited. However, it doesn't verify that the clone node is the correct clone for this original node. Consider this scenario: if the cloning incorrectly maps original node A to clone node X in one path and to clone node Y in another path, but Y was already visited from a different context, the assertion would incorrectly pass. A more robust check would maintain an explicit mapping dictionary (e.g., orig_to_clone = {}) and verify orig_to_clone[orig] is cln to ensure consistent pairing throughout the graph traversal.
                # If we've seen this original node, we should have seen the clone too
                assert cln in visited_clone

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kobukuro kobukuro merged commit 256c0f9 into feat/add-clone-graph-solution-and-tests Feb 19, 2026
7 checks passed
@kobukuro kobukuro deleted the copilot/sub-pr-85 branch February 19, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants