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

Add __hash__ method to DAGSet #4

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ def _check_category_and_dimension(self):
raise ValueError(f"{identifier} has no category or geom_dimension tags assigned.")

def __eq__(self, other):
return self.handle == other.handle
return self.model == other.model and self.handle == other.handle

def __hash__(self):
return hash((self.handle, id(self.model)))

def __repr__(self):
return f'{type(self).__name__} {self.id}, {self.num_triangles()} triangles'
Expand Down
30 changes: 29 additions & 1 deletion test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def test_group_merge(request):
new_group = dagmc.Group.create(model, 'mat:fuel')
assert orig_group != new_group


# check that we can update a set ID
assert new_group.id == -1
new_group.id = 100
Expand Down Expand Up @@ -126,6 +125,21 @@ def test_volume(request):
assert v1 not in model.groups['mat:fuel']


def test_hash(request):
test_file = str(request.path.parent / 'fuel_pin.h5m')
model = dagmc.DAGModel(test_file)

s = set(model.volumes)
d = {group: group.name for group in model.groups.values()}

# check that an entry for the same volume with a different model can be entered
# into the dict
model1 = dagmc.DAGModel(test_file)

d.update({group: group.name for group in model1.groups.values()})

assert len(d) == len(model.groups) + len(model1.groups)

def test_compressed_coords(request, capfd):
test_file = str(request.path.parent / 'fuel_pin.h5m')
groups = dagmc.DAGModel(test_file).groups
Expand All @@ -145,6 +159,7 @@ def test_compressed_coords(request, capfd):
assert (conn_map[tris[0]].size == 3)
assert (coords[conn_map[tris[0]]].size == 9)


def test_coords(request, capfd):
test_file = str(request.path.parent / 'fuel_pin.h5m')
model = dagmc.DAGModel(test_file)
Expand Down Expand Up @@ -226,3 +241,16 @@ def test_missing_tags(cls):
handle = model.mb.create_meshset()
with pytest.raises(ValueError):
cls(model, handle)


def test_eq(request):
test_file = str(request.path.parent / 'fuel_pin.h5m')
model1 = dagmc.DAGModel(test_file)
model2 = dagmc.DAGModel(test_file)

model1_v0 = model1.volumes[1]
model2_v0 = model2.volumes[1]

assert model1_v0.handle == model2_v0.handle

assert model1_v0 != model2_v0
Loading