Beispiel #1
0
    def test_extend(self):
        lst = [1, 2, 3]

        def do_checks(l):
            self.assertEqual(len(l), len(lst))
            # Do an element wise comparison
            for x, y in zip(lst, l):
                self.assertEqual(x, y)

        l = base.List()
        l.extend(lst)
        do_checks(l)
        # Further extend
        l.extend(lst)
        self.assertEqual(len(l), len(lst) * 2)

        # Do an element wise comparison
        for i in range(0, len(lst)):
            self.assertEqual(lst[i], l[i])
            self.assertEqual(lst[i], l[i % len(lst)])

        # Now try after strogin
        l = base.List()
        l.extend(lst)
        l.store()
        do_checks(l)
Beispiel #2
0
    def test_append(self):
        def do_checks(l):
            self.assertEqual(len(l), 1)
            self.assertEqual(l[0], 4)

        l = base.List()
        l.append(4)
        do_checks(l)

        # Try the same after storing
        l = base.List()
        l.append(4)
        l.store()
        do_checks(l)
Beispiel #3
0
    def test_mutability(self):
        l = base.List()
        l.append(5)
        l.store()

        # Test all mutable calls are now disallowed
        with self.assertRaises(ModificationNotAllowed):
            l.append(5)
        with self.assertRaises(ModificationNotAllowed):
            l.extend([5])
        with self.assertRaises(ModificationNotAllowed):
            l.insert(0, 2)
        with self.assertRaises(ModificationNotAllowed):
            l.remove(0)
        with self.assertRaises(ModificationNotAllowed):
            l.pop()
        with self.assertRaises(ModificationNotAllowed):
            l.sort()
        with self.assertRaises(ModificationNotAllowed):
            l.reverse()
Beispiel #4
0
 def test_creation(self):
     l = base.List()
     self.assertEqual(len(l), 0)
     with self.assertRaises(IndexError):
         l[0]