Beispiel #1
0
    def test_06(self):
        example = BackFront()
        for i in range(8):
            example.prepend(i)

        example.delete_last()
        for i in range(7):
            self.assertEqual(example.as_list()[i], 7 - i)
            example[i] = 6

        self.assertEqual(example.as_list(), [6] * 7)
Beispiel #2
0
    def test_08(self):
        n = 300000
        example = BackFront()
        for i in range(n):
            example.prepend(i)
        self.assertEqual(example.as_list(), list(reversed(range(n))))

        for _ in range(n // 2):
            example.delete_first()
        self.assertEqual(example.as_list(), list(reversed(range(n // 2))))

        for _ in range(n // 2):
            example.delete_last()
        self.assertEqual(example.as_list(), [])
Beispiel #3
0
    def test_10(self):
        # similar to 8 but also tests for indexing in O(1) time
        n = 300000
        example = BackFront()
        for i in range(n):
            example.prepend(i)
        self.assertEqual(example.as_list(), list(reversed(range(n))))

        for i in range(n // 2):
            self.assertEqual(example[2], n - 3 - i)
            example.delete_first()
        self.assertEqual(example.as_list(), list(reversed(range(n // 2))))

        for _ in range(n // 2):
            example.delete_last()
        self.assertEqual(example.as_list(), [])
Beispiel #4
0
    def test_09(self):
        # similar to 7, but also tests for indexing in O(1) time
        n = 300000
        example = BackFront()
        for i in range(n):
            example.append(i)
        self.assertEqual(example.as_list(), list(range(n)))

        for i in range(n // 2):
            self.assertEqual(example[0], i)
            example.delete_first()
        self.assertEqual(example.as_list(), list(range(n // 2, n)))

        first = example[0]
        for _ in range(n // 2):
            self.assertEqual(example[0], first)
            example.delete_last()
        self.assertEqual(example.as_list(), [])
Beispiel #5
0
 def test_02(self):
     example = BackFront()
     example.prepend(3)
     example.prepend(2)
     example.delete_last()
     self.assertEqual(example.as_list(), [2])