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_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_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_remove_last(self):
        """Check that remove_last() works on an empty SLL."""

        my_sll = None
        result = sll.remove_last(my_sll)
        expected = None
        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)
Esempio n. 5
0
    def test_remove_last(self):
        """Check that remove_last() works on an empty SLL."""

        my_sll = None
        result = sll.remove_last(my_sll)
        expected = None
        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)
Esempio n. 6
0
    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_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)
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
    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))
Esempio n. 12
0
    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))
Esempio n. 13
0
    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)
Esempio n. 14
0
    def test_find(self):
        """Check that find() works on an empty SLL."""

        my_sll = None
        find = sll.find(my_sll, 20)
        msg = "Expected to not find 20 in SLL '%s', failed" % sll.__str__(my_sll)
        self.assertFalse(find is not None, msg)
Esempio n. 15
0
    def test_add_front(self):
        """Check that add_front() works for empty SLL."""

        old_sll = None
        new_sll = sll.add_front(old_sll, 'A')
        expected = ['A']

        self.assertEqual(sll.__str__(new_sll), str(expected))
Esempio n. 16
0
    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))
Esempio n. 17
0
    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))
Esempio n. 18
0
    def test_find(self):
        """Check that find() works on an empty SLL."""

        my_sll = None
        find = sll.find(my_sll, 20)
        msg = "Expected to not find 20 in SLL '%s', failed" % sll.__str__(
            my_sll)
        self.assertFalse(find is not None, msg)
Esempio n. 19
0
    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))
Esempio n. 20
0
    def test_add_front(self):
        """Check that add_front() works for empty SLL."""

        old_sll = None
        new_sll = sll.add_front(old_sll, 'A')
        expected = ['A']

        self.assertEqual(sll.__str__(new_sll), str(expected))
Esempio n. 21
0
    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))
Esempio n. 22
0
    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)
Esempio n. 23
0
    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))
Esempio n. 24
0
    def test_add_front4(self):
        """Check that add_front() works repeatedly on SLL with no elements."""

        old_sll = None
        new_sll = sll.add_front(old_sll, 'first')
        expected = ['first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'second')
        expected = ['second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'third')
        expected = ['third', 'second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'fourth')
        expected = ['fourth', 'third', 'second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))
Esempio n. 25
0
    def test_add_front4(self):
        """Check that add_front() works repeatedly on SLL with no elements."""

        old_sll = None
        new_sll = sll.add_front(old_sll, 'first')
        expected = ['first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'second')
        expected = ['second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'third')
        expected = ['third', 'second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))

        new_sll = sll.add_front(new_sll, 'fourth')
        expected = ['fourth', 'third', 'second', 'first']
        self.assertEqual(sll.__str__(new_sll), str(expected))
Esempio n. 26
0
    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))
Esempio n. 27
0
    def test_find2(self):
        """Check that find() works on an non-empty SLL."""

        my_sll = sll.SLL('A', sll.SLL(20, sll.SLL('q', 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 the sub-SLL returned is correct
        expected = sll.SLL(20, sll.SLL('q', 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)
Esempio n. 28
0
    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)