Skip to content

Commit

Permalink
Implement setlist.reverse and add tests, fix #125
Browse files Browse the repository at this point in the history
  • Loading branch information
mlenzen committed Jul 1, 2020
1 parent 4ebaf8c commit 7a02ba0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions collections_extended/setlists.py
Expand Up @@ -432,6 +432,12 @@ def remove_all(self, elems_to_delete):
"""
self._delete_all(elems_to_delete, raise_errors=True)

def reverse(self):
"""Reverse the setlist in-place."""
self._list.reverse()
for index, item in enumerate(self._list):
self._dict[item] = index

# Implement MutableSet

def add(self, item):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_setlists.py
Expand Up @@ -596,3 +596,9 @@ def test_swap():
sl.swap(-1, 1)
assert_internal_structure(sl)
assert sl == setlist('afbdec')


def test_reverse():
sl = setlist('abcdef')
sl.reverse()
assert sl == setlist('fedcba')

0 comments on commit 7a02ba0

Please sign in to comment.