Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding eq method to collection #41

Open
wants to merge 2 commits into
base: pipeline
Choose a base branch
from

Conversation

Peyman-N
Copy link
Member

@Peyman-N Peyman-N commented Jul 3, 2024

No description provided.

@Peyman-N Peyman-N requested a review from apdavison July 3, 2024 13:23
@Peyman-N Peyman-N linked an issue Jul 3, 2024 that may be closed by this pull request
Copy link
Member

@apdavison apdavison left a comment

Choose a reason for hiding this comment

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

The code looks fine (some suggestions for streamlining it), but the tests are failing.

@Peyman-N Peyman-N requested a review from apdavison July 4, 2024 14:23
@Peyman-N
Copy link
Member Author

Peyman-N commented Jul 4, 2024

The code looks fine (some suggestions for streamlining it), but the tests are failing.

I was trying to add a test too but it seems there was a problem with the test.
The test was a simple line added to the old tests present; After this line I added :

assert collection == new_collection

It should have been correct if the code for the test was running the new version, but that was not the case.

Copy link
Member

@apdavison apdavison left a comment

Choose a reason for hiding this comment

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

Tests still needed.


def __eq__(self, other: Node) -> bool:

for property in self.properties:
Copy link
Member

Choose a reason for hiding this comment

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

also need to check equality self._type_ and self.id (if it is defined, i.e., for LinkedMetadata, but not for EmbeddedMetadata, and if it is not None)

def __eq__(self, other):

# The current implementation assumes that nodes in both graphs are connected with the same link number.
for node_id in self.nodes:
Copy link
Member

Choose a reason for hiding this comment

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

also need to check that there are no extra nodes in other that are not present in self.

@@ -34,6 +34,18 @@ def __len__(self):

def __iter__(self):
return iter(self.nodes.values())

def __eq__(self, other):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a preliminary check that the len() of both collections are the same? If they're different, we can return False quickly without needing to check all the nodes.

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.

Add __eq__ and related methods to Node and Collection
2 participants