def test_add_front3(self):
        """Check that add_front() works on SLL with many elements."""

        old_sll = sll.SLL(20, sll.SLL('A', sll.SLL('omega')))
        new_sll = sll.add_front(old_sll, 'M')
        expected = ['M', 20, 'A', 'omega']

        self.assertEqual(sll.__str__(new_sll), str(expected))
    def test_find4(self):
        """Check that find() works on an non-empty SLL with NO FIND."""

        my_sll = sll.SLL('A',
                         sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M')))))
        find = sll.find(my_sll, 'X')
        msg = "Expected to not find 'X' in SLL '%s', succeeded?" % sll.__str__(
            my_sll)
        self.assertTrue(find is None, msg)
    def test_length(self):
        """Check that length() works."""

        my_sll = sll.SLL('M')
        my_sll = sll.SLL('q', my_sll)
        my_sll = sll.SLL(20, my_sll)
        my_sll = sll.SLL('A', my_sll)
        expected_len = 4

        self.assertEqual(sll.length(my_sll), expected_len)
    def test_add_after3(self):
        """Check that add_after() works on an SLL with NO found value."""

        my_sll = sll.SLL('A',
                         sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M')))))
        result = sll.add_after(my_sll, 21, 100)
        expected = None
        msg = ("Expected add_after('%s', 21, 100) to return None, got '%s'" %
               (sll.__str__(my_sll), sll.__str__(result)))
        self.assertTrue(sll.__str__(result) == sll.__str__(expected), msg)
    def test___str__(self):
        """Check that __str__() works."""

        my_sll = sll.SLL('M')
        my_sll = sll.SLL('q', my_sll)
        my_sll = sll.SLL(20, my_sll)
        my_sll = sll.SLL('A', my_sll)
        expected = ['A', 20, 'q', 'M']

        self.assertEqual(sll.__str__(my_sll), str(expected))
    def test_map_fun(self):
        """Check the map_fun() function."""

        my_sll = sll.SLL(1, sll.SLL(2, sll.SLL(3, sll.SLL(5, sll.SLL(100)))))
        func = lambda x, y: x + y
        result = sll.map_fun(my_sll, func, 1)
        expected = sll.SLL(2, sll.SLL(3, sll.SLL(4, sll.SLL(6, sll.SLL(101)))))
        msg = (
            "Expected map_fun('%s', func, 1) to return '%s', got '%s'" %
            (sll.__str__(my_sll), sll.__str__(expected), sll.__str__(result)))
        self.assertTrue(sll.__str__(result) == sll.__str__(expected), msg)
    def test_remove3(self):
        """Check that remove() works on an SLL with NO found value."""

        my_sll = sll.SLL('A',
                         sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M')))))
        result = sll.remove(my_sll, 22)
        expected = my_sll
        msg = (
            "Expected remove('%s', 21, 100) to return '%s', got '%s'" %
            (sll.__str__(my_sll), sll.__str__(expected), sll.__str__(result)))
        self.assertTrue(sll.__str__(result) == sll.__str__(expected), msg)
    def test_remove_last2(self):
        """Check that remove_last() works on a non-empty SLL."""

        my_sll = sll.SLL('A',
                         sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M')))))
        result = sll.remove_last(my_sll)
        expected = sll.SLL('A', sll.SLL(20, sll.SLL('q', sll.SLL(20))))
        msg = (
            "Expected remove_last('%s') to return '%s', got '%s'" %
            (sll.__str__(my_sll), sll.__str__(expected), sll.__str__(result)))
        self.assertTrue(sll.__str__(result) == sll.__str__(expected), msg)
    def test_length3(self):
        """Check that length() works."""

        my_sll = sll.SLL('M')
        expected_len = 1

        self.assertEqual(sll.length(my_sll), expected_len)
    def test_add_front2(self):
        """Check that add_front() works on SLL with one element."""

        old_sll = sll.SLL(20)
        new_sll = sll.add_front(old_sll, 'M')
        expected = ['M', 20]

        self.assertEqual(sll.__str__(new_sll), str(expected))
    def test_find3(self):
        """Check that find() works on an non-empty SLL with multiple finds."""

        my_sll = sll.SLL('A',
                         sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M')))))
        find = sll.find(my_sll, 20)
        msg = "Expected to find 20 in SLL '%s', failed" % sll.__str__(my_sll)
        self.assertTrue(find is not None, msg)

        # check returned sub-SLL is as expected
        expected = sll.SLL(20, sll.SLL('q', sll.SLL(20, sll.SLL('M'))))
        msg = ("find('%s', 20) returned '%s', expected '%s'" %
               (sll.__str__(my_sll), sll.__str__(find), sll.__str__(expected)))
        self.assertTrue(sll.__str__(find) == sll.__str__(expected), msg)
    def test_sll_create(self):
        """Check a simple SLL creation."""

        my_sll = sll.SLL('M')
        my_sll = sll.SLL('q', my_sll)
        my_sll = sll.SLL(20, my_sll)
        my_sll = sll.SLL('A', my_sll)

        my_sll2 = sll.SLL('A', sll.SLL(20, sll.SLL('q', sll.SLL('M'))))

        self.assertEqual(sll.__str__(my_sll), sll.__str__(my_sll2))