Ejemplo n.º 1
0
 def test_pairs(self):
     it = basicList.pairs()
     assert next(it) == basicList
     assert next(it) == ilinkedlist.new((2, 3, 4))
     assert next(it) == ilinkedlist.new((3, 4))
     assert next(it) == ilinkedlist.new((4, ))
     with pytest.raises(StopIteration):
         next(it)
Ejemplo n.º 2
0
 def test_setItem(self):
     assert basicList.setItem(1, 66) == ilinkedlist.new((1, 66, 3, 4))
Ejemplo n.º 3
0
 def test_rmul(self):
     assert 2 * basicList == ilinkedlist.new((1, 2, 3, 4, 1, 2, 3, 4))
Ejemplo n.º 4
0
 def test_getitemSlice(self):
     """Slicing works."""
     assert basicList[0:2] == ilinkedlist.new((1, 2))
Ejemplo n.º 5
0
 def test_pop(self):
     assert basicList.pop() == (1, ilinkedlist.new((2, 3, 4)))
     assert basicList.pop(2) == (3, ilinkedlist.new((1, 2, 4)))
Ejemplo n.º 6
0
 def test_remove(self):
     assert basicList.remove(3) == ilinkedlist.new((1, 2, 4))
     with pytest.raises(ValueError):
         basicList.remove(10)
Ejemplo n.º 7
0
 def test_delItemSliceStep(self):
     assert (ilinkedlist.new(
         (1, 10, 2, 20, 3, 30, 4)).delItem(slice(1, 6, 2)) == basicList)
Ejemplo n.º 8
0
 def test_delItem(self):
     assert basicList.delItem(1) == ilinkedlist.new((1, 3, 4))
Ejemplo n.º 9
0
 def test_member(self):
     assert ilinkedlist.new((-1, 0, 1, 2, 3, 4)).member(1) == basicList
Ejemplo n.º 10
0
 def test_add(self):
     """Concatenation."""
     assert (basicList + ilinkedlist.new((3, 4, 5)) == ilinkedlist.new(
         (1, 2, 3, 4, 3, 4, 5)))
Ejemplo n.º 11
0
 def test_gt(self):
     assert basicList > ilinkedlist.nil
     assert basicList > ilinkedlist.new((0, 1, -1))
Ejemplo n.º 12
0
 def test_lt(self):
     assert not (basicList < ilinkedlist.nil)
     assert basicList < ilinkedlist.new((0, 1, 3))
Ejemplo n.º 13
0
 def test_eq(self):
     """Equality."""
     assert basicList == ilinkedlist.new((1, 2, 3, 4))
     assert basicList != ilinkedlist.new((2, 1, 0))
Ejemplo n.º 14
0
 def test_tail(self):
     """Get the tail of a list."""
     assert basicList.tail(1) == ilinkedlist.new((2, 3, 4))
Ejemplo n.º 15
0
 def test_getitemSliceNegative(self):
     """Slicing works with negative numbers."""
     assert basicList[:-1] == ilinkedlist.new((1, 2, 3))
Ejemplo n.º 16
0
 def test_setItemSlice(self):
     assert (basicList.setItem(slice(1, 3),
                               (10, 11, 12)) == ilinkedlist.new(
                                   (1, 10, 11, 12, 4)))
Ejemplo n.º 17
0
 def test_setItemSliceStep(self):
     assert (ilinkedlist.new(
         (1, 2, 3, 4, 5, 6)).setItem(slice(1, 5, 2),
                                     (10, 20)) == ilinkedlist.new(
                                         (1, 10, 3, 20, 5, 6)))
Ejemplo n.º 18
0
 def test_memberEq(self):
     assert (basicList.member(2,
                              lambda x, elem: x < elem) == ilinkedlist.new(
                                  (3, 4)))
Ejemplo n.º 19
0
 def test_delItemSlice(self):
     assert (ilinkedlist.new(
         (1, 20, 30, 2, 3, 4)).delItem(slice(1, 3)) == basicList)
Ejemplo n.º 20
0
 def test_count(self):
     assert ilinkedlist.new((0, 0, 1, 1, 1)).count(1) == 3
Ejemplo n.º 21
0
 def test_insert(self):
     assert basicList.insert(1, 40) == ilinkedlist.new((1, 40, 2, 3, 4))
Ejemplo n.º 22
0
 def test_radd(self):
     assert (4, 5, 6) + basicList == ilinkedlist.new((4, 5, 6, 1, 2, 3, 4))
Ejemplo n.º 23
0
 def test_sort(self):
     assert ilinkedlist.new((4, 1, 3, 2)).sort() == basicList
Ejemplo n.º 24
0
 def test_mul(self):
     assert (basicList * 3 == ilinkedlist.new(
         (1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)))
Ejemplo n.º 25
0
 def test_splitAt(self):
     assert (basicList.splitAt(2) == (ilinkedlist.new(
         (1, 2)), ilinkedlist.new((3, 4))))
Ejemplo n.º 26
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# TODO:
# Consider adding functions from
# https://www.gnu.org/software/guile/manual/html_node/SRFI_002d1.html.

import pytest

import ilinkedlist

basicList = ilinkedlist.new((1, 2, 3, 4))
improperList = ilinkedlist.Pair(11, 93)


def test_new():
    """Make a linked list from an iterable."""
    assert tuple(basicList) == (1, 2, 3, 4)


def test_reverse():
    assert tuple(ilinkedlist.reverse((0, 1, 2))) == (2, 1, 0)


def test_isList():
    """isList returns False for a non-list."""
    assert ilinkedlist.isList(None) is False