Skip to content

Commit

Permalink
Extends D2HashableConnection's __eq__ method to also validate label
Browse files Browse the repository at this point in the history
  • Loading branch information
netsatan committed Apr 29, 2024
1 parent 1a7800c commit cf99f19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion specifipy/diagram_engines/hashable_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ def __hash__(self):
return hash((self.shape_1, self.shape_2, self.direction))

def __eq__(self, other) -> bool:
if (self.shape_1, self.shape_2, self.direction) == (
if (self.shape_1, self.shape_2, self.direction, self.label) == (
other.shape_1,
other.shape_2,
other.direction,
other.label,
):
return True
return False
15 changes: 15 additions & 0 deletions tests/test_diagram_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ def test_connections_uniqueness(self):
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
connection_2 = D2HashableConnection("a", "b", "some_label", Direction.TO)
assert connection_1 == connection_2

def test_connections_hash(self):
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
assert isinstance(connection_1.__hash__(), int)

def test_connections_not_equal(self):
connection_1 = D2HashableConnection("a", "b", "some_label", Direction.TO)
connection_2 = D2HashableConnection("a", "b", "some_label2", Direction.TO)
connection_3 = D2HashableConnection("a1", "b", "some_label", Direction.TO)
connection_4 = D2HashableConnection("a", "b1", "some_label", Direction.TO)
connection_5 = D2HashableConnection("a", "b", "some_label", Direction.FROM)
assert connection_1 != connection_2
assert connection_1 != connection_3
assert connection_1 != connection_4
assert connection_1 != connection_5

0 comments on commit cf99f19

Please sign in to comment.