Remove wrap mode for NeighborList
This commit is contained in:
parent
d50af52d1a
commit
8d5fdf2833
@ -65,7 +65,7 @@ class NeighborList(collections.abc.Sequence):
|
||||
_mode: The current mode.
|
||||
"""
|
||||
|
||||
Modes = enum('Modes', ['block', 'wrap', 'exception'])
|
||||
Modes = enum('Modes', ['block', 'exception'])
|
||||
|
||||
def __init__(self, items=None, default=_UNSET, mode=Modes.exception):
|
||||
"""Constructor.
|
||||
@ -75,7 +75,6 @@ class NeighborList(collections.abc.Sequence):
|
||||
_default: The initially selected value.
|
||||
_mode: Behavior when the first/last item is reached.
|
||||
Modes.block: Stay on the selected item
|
||||
Modes.wrap: Wrap around to the other end
|
||||
Modes.exception: Raise an IndexError.
|
||||
"""
|
||||
if not isinstance(mode, self.Modes):
|
||||
@ -143,10 +142,6 @@ class NeighborList(collections.abc.Sequence):
|
||||
except IndexError:
|
||||
if self._mode == self.Modes.block:
|
||||
new = self.curitem()
|
||||
elif self._mode == self.Modes.wrap:
|
||||
self._idx += offset
|
||||
self._idx %= len(self.items)
|
||||
new = self.curitem()
|
||||
elif self._mode == self.Modes.exception: # pragma: no branch
|
||||
raise
|
||||
else:
|
||||
|
@ -172,14 +172,6 @@ class TestSingleItem:
|
||||
def neighborlist(self):
|
||||
return usertypes.NeighborList([1], default=1)
|
||||
|
||||
def test_first_wrap(self, neighborlist):
|
||||
"""Test out of bounds previtem() with mode=wrap."""
|
||||
neighborlist._mode = usertypes.NeighborList.Modes.wrap
|
||||
neighborlist.firstitem()
|
||||
assert neighborlist._idx == 0
|
||||
assert neighborlist.previtem() == 1
|
||||
assert neighborlist._idx == 0
|
||||
|
||||
def test_first_block(self, neighborlist):
|
||||
"""Test out of bounds previtem() with mode=block."""
|
||||
neighborlist._mode = usertypes.NeighborList.Modes.block
|
||||
@ -197,14 +189,6 @@ class TestSingleItem:
|
||||
neighborlist.previtem()
|
||||
assert neighborlist._idx == 0
|
||||
|
||||
def test_last_wrap(self, neighborlist):
|
||||
"""Test out of bounds nextitem() with mode=wrap."""
|
||||
neighborlist._mode = usertypes.NeighborList.Modes.wrap
|
||||
neighborlist.lastitem()
|
||||
assert neighborlist._idx == 0
|
||||
assert neighborlist.nextitem() == 1
|
||||
assert neighborlist._idx == 0
|
||||
|
||||
def test_last_block(self, neighborlist):
|
||||
"""Test out of bounds nextitem() with mode=block."""
|
||||
neighborlist._mode = usertypes.NeighborList.Modes.block
|
||||
@ -248,30 +232,6 @@ class TestBlockMode:
|
||||
assert neighborlist._idx == 4
|
||||
|
||||
|
||||
class TestWrapMode:
|
||||
|
||||
"""Tests with mode=wrap."""
|
||||
|
||||
@pytest.fixture
|
||||
def neighborlist(self):
|
||||
return usertypes.NeighborList(
|
||||
[1, 2, 3, 4, 5], default=3, mode=usertypes.NeighborList.Modes.wrap)
|
||||
|
||||
def test_first(self, neighborlist):
|
||||
"""Test out of bounds previtem()."""
|
||||
neighborlist.firstitem()
|
||||
assert neighborlist._idx == 0
|
||||
assert neighborlist.previtem() == 5
|
||||
assert neighborlist._idx == 4
|
||||
|
||||
def test_last(self, neighborlist):
|
||||
"""Test out of bounds nextitem()."""
|
||||
neighborlist.lastitem()
|
||||
assert neighborlist._idx == 4
|
||||
assert neighborlist.nextitem() == 1
|
||||
assert neighborlist._idx == 0
|
||||
|
||||
|
||||
class TestExceptionMode:
|
||||
|
||||
"""Tests with mode=exception."""
|
||||
|
Loading…
Reference in New Issue
Block a user