Skip to content

Commit

Permalink
csm.__eq__ now generically checks all node and edge attributes (#648)
Browse files Browse the repository at this point in the history
csm.__eq__ now generically checks all node and edge attributes

Co-authored-by: vhirtham <[email protected]>
  • Loading branch information
marscher and vhirtham authored Nov 17, 2021
1 parent e50da66 commit 895e03e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 12 additions & 0 deletions weldx/tests/transformations/test_cs_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,18 @@ def test_comparison_wrong_type():
assert (csm != 4) is True


def test_comparison_data():
csm1 = tf.CoordinateSystemManager("root", "csm")
csm2 = tf.CoordinateSystemManager("root", "csm")
data = np.arange(12).reshape((4, 3))
csm1.assign_data(data, data_name="foo", reference_system="root")
csm2.assign_data(data, data_name="foo", reference_system="root")

assert csm1 == csm2
csm2.assign_data(data, data_name="bar", reference_system="root")
assert csm1 != csm2


# test_time_union ----------------------------------------------------------------------


Expand Down
13 changes: 7 additions & 6 deletions weldx/transformations/cs_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def __repr__(self):

def __eq__(self, other: Any):
"""Test equality of CSM instances."""
# todo: also check data -> add tests
if not isinstance(other, self.__class__):
return False

Expand All @@ -175,17 +174,19 @@ def __eq__(self, other: Any):
for node in graph_0.nodes:
if node not in graph_1.nodes:
return False
n0 = graph_0.nodes[node]
n1 = graph_1.nodes[node]
if not util.compare_nested(n0, n1):
return False

# check edges
for edge in graph_0.edges:
if edge not in graph_1.edges:
return False

# check coordinate systems
for edge in graph_0.edges:
lcs_0 = self.graph.edges[(edge[0], edge[1])]["transformation"]
lcs_1 = other.graph.edges[(edge[0], edge[1])]["transformation"]
if lcs_0 != lcs_1:
e0 = graph_0.edges[edge]
e1 = graph_1.edges[edge]
if not util.compare_nested(e0, e1):
return False

return True
Expand Down

0 comments on commit 895e03e

Please sign in to comment.