diff options
author | 2020-12-15 22:42:59 -0700 | |
---|---|---|
committer | 2020-12-15 22:42:59 -0700 | |
commit | 9ba3e03c9ba5c3f6dd2db4042a6223bcaa094acb (patch) | |
tree | 801a1a2bb63ad46e1b8e8380d5b6b94a2fb0ecb6 /tests | |
parent | bash: use := operator with while loop regex matching (diff) | |
download | snakeoil-9ba3e03c9ba5c3f6dd2db4042a6223bcaa094acb.tar.gz snakeoil-9ba3e03c9ba5c3f6dd2db4042a6223bcaa094acb.tar.bz2 snakeoil-9ba3e03c9ba5c3f6dd2db4042a6223bcaa094acb.zip |
mappings: add initial OrderedFrozenSet implementation
Which is an immutable OrderedSet.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/module/test_mappings.py | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/tests/module/test_mappings.py b/tests/module/test_mappings.py index 7196a96..b8abc17 100644 --- a/tests/module/test_mappings.py +++ b/tests/module/test_mappings.py @@ -288,16 +288,68 @@ class TestImmutableDict: assert initial_hash == hash(d) -class TestOrderedSet: +class TestOrderedFrozenSet: def test_magic_methods(self): - s = mappings.OrderedSet(range(9)) + s = mappings.OrderedFrozenSet(range(9)) for x in range(9): assert x in s assert len(s) == 9 assert s == set(range(9)) assert str(s) == str(set(range(9))) assert repr(s) == str(s) + assert hash(s) + + def test_ordering(self): + s = mappings.OrderedFrozenSet('set') + assert 'set' == ''.join(s) + s = mappings.OrderedFrozenSet('setordered') + assert 'setord' == ''.join(s) + + def test_immmutability(self): + s = mappings.OrderedFrozenSet(range(9)) + assert len(s) == 9 + with pytest.raises(AttributeError): + s.add(9) + with pytest.raises(AttributeError): + s.discard(0) + with pytest.raises(AttributeError): + s.update(range(5)) + + def test_intersection(self): + s = mappings.OrderedFrozenSet(range(9)) + new = s.intersection({1, 9}) + assert new == mappings.OrderedFrozenSet({1}) + assert new == s & {1, 9} + assert isinstance(new, mappings.OrderedFrozenSet) + + def test_union(self): + s = mappings.OrderedFrozenSet(range(9)) + new = s.union({9}) + assert new == mappings.OrderedFrozenSet(range(10)) + assert new == s | {9} + assert isinstance(new, mappings.OrderedFrozenSet) + + def test_difference(self): + s = mappings.OrderedFrozenSet(range(9)) + new = s.difference({8}) + assert new == mappings.OrderedFrozenSet(range(8)) + assert new == s - {8} + assert isinstance(new, mappings.OrderedFrozenSet) + + def test_symmetric_difference(self): + s = mappings.OrderedFrozenSet(range(9)) + new = s.symmetric_difference({0, 9}) + assert new == mappings.OrderedFrozenSet(range(1, 10)) + assert new == s ^ {0, 9} + assert isinstance(new, mappings.OrderedFrozenSet) + + +class TestOrderedSet: + + def test_hash(self): + with pytest.raises(TypeError): + assert hash(mappings.OrderedSet('set')) def test_add(self): s = mappings.OrderedSet() @@ -340,13 +392,6 @@ class TestOrderedSet: s.update(range(9)) assert len(s) == 9 - def test_ordering(self): - s = mappings.OrderedSet() - s.update('set') - assert 'set' == ''.join(s) - s.update('ordered') - assert 'setord' == ''.join(s) - class TestStackedDict: |