3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-09 17:31:59 +00:00

pyosys/hashlib: equivalence operators

This commit is contained in:
Mohamed Gaber 2025-09-28 04:09:36 +03:00
parent 447a6cb3f0
commit c8404bf86b
No known key found for this signature in database
4 changed files with 62 additions and 18 deletions

View file

@ -26,4 +26,19 @@ the_great_or = constructor_test_1 | constructor_test_2 | constructor_test_3
assert set(the_great_or) == {"first", "key", "tomato", "im running"}
repr_test = eval(repr(the_great_or))
assert repr_test == the_great_or
assert repr_test == the_great_or # compare dicts
assert repr_test == {'tomato': 'tomato', 'first': 'second', 'key': 'value', 'im running': 'out of string ideas', } # compare dict with mapping
before = len(repr_test)
print(repr_test.popitem())
assert before - 1 == len(repr_test)
# test noncomparable
## if ys.CellType ever gets an == operator just disable this section
uncomparable_value = ys.Globals.yosys_celltypes.cell_types[ys.IdString("$not")]
x = ys.IdstringToCelltypeDict({ ys.IdString("\\a"): uncomparable_value})
y = ys.IdstringToCelltypeDict({ ys.IdString("\\a"): uncomparable_value})
assert x != y # not comparable

View file

@ -33,10 +33,10 @@ for cls in [StringSet, StringPool]:
C |= {"A", "B", "C"}
D |= {"C", "D", "E"}
c_symdiff_d = (C ^ D)
assert (c_symdiff_d) == {"A", "B", "D", "E"}
assert c_symdiff_d == {"A", "B", "D", "E"} # compare against iterable
repr_test = eval(repr(c_symdiff_d))
c_symdiff_d == repr_test
assert c_symdiff_d == repr_test # compare against self
print("Done.")