Skip to content
Open
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
9 changes: 7 additions & 2 deletions src-python/amazon/ion/equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ def _structs_eq(a, b, comparison_func):
return False
if isinstance(a, (IonPyDict, Multimap)) and isinstance(b, (IonPyDict, Multimap)):
values_a = a.get_all_values(key)
values_b = b.get_all_values(key)
values_b = list(b.get_all_values(key))
if len(values_a) != len(values_b):
return False
for value_a in values_a:
if not any(comparison_func(value_a, value_b) for value_b in values_b):
for i, value_b in enumerate(values_b):
if comparison_func(value_a, value_b):
# Each field occurrence must match a distinct occurrence.
del values_b[i]
break
else:
return False
else:
if not comparison_func(a[key], b[key]):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,27 @@ def _generate_equiv_dicts(equivs):
)
def test_equivalence(p):
p.assertion()


@parametrize(
([1, 1, 2], [1, 2, 2], False),
([1, 1, 2], [2, 1, 1], True),
([[1], [1], [2]], [[1], [2], [2]], False),
([[1], [1], [2]], [[2], [1], [1]], True),
([float('nan'), float('nan'), 1.0], [float('nan'), 1.0, 1.0], False),
([float('nan'), float('nan'), 1.0], [1.0, float('nan'), float('nan')], True),
([0.0, 0.0, -0.0], [0.0, -0.0, -0.0], False),
)
def test_duplicate_field_multiplicity(p):
values_a, values_b, expected = p
a, b = IonPyDict(), IonPyDict()
for value in values_a:
a.add_item('field', value)
for value in values_b:
b.add_item('field', value)
items_a, items_b = a.items(), b.items()

assert ion_equals(a, b) is expected
assert ion_equals(b, a) is expected
assert a.items() == items_a
assert b.items() == items_b