Skip to content

Commit

Permalink
test: adding unit test for specific edge cases
Browse files Browse the repository at this point in the history
Signed-off-by: Lee, Kin Long Kelvin <[email protected]>
  • Loading branch information
laserkelvin committed Dec 17, 2024
1 parent 6845ae3 commit 47da9ad
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions matsciml/datasets/tests/test_edge_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from __future__ import annotations

import pytest
import numpy as np

from matsciml.datasets.utils import Edge


def test_non_self_interaction():
"""
These two nodes edges should not be equivalent, since they
are not self-interactions and the images are different
"""
a = Edge(src=0, dst=10, image=np.array([-1, 0, 0]))
b = Edge(src=0, dst=10, image=np.array([1, 0, 0]))
assert a != b


def test_self_interaction_image():
"""
These two edges are mirror images of one another since
the src/dst are the same node.
"""
a = Edge(src=0, dst=0, image=np.array([-1, 0, 0]))
b = Edge(src=0, dst=0, image=np.array([1, 0, 0]))
assert a == b


@pytest.mark.parametrize("is_undirected", [True, False])
def test_directed_edges(is_undirected):
"""
These two are the same edge in the undirected case,
but are different if treating directed graphs
"""
a = Edge(src=5, dst=10, image=np.array([0, 0, 0]), is_undirected=is_undirected)
b = Edge(src=10, dst=5, image=np.array([0, 0, 0]), is_undirected=is_undirected)
if is_undirected:
assert a == b
else:
assert a != b

0 comments on commit 47da9ad

Please sign in to comment.