def testSet(self):
        a = AutoResizeList()
        a[5] = 5
        self.assertEqual(a._data, [None, None, None, None, None, 5])

        b = AutoResizeList([0, 1, 2, 3], fill=0)
        b[6] = 6
        self.assertEqual(b._data, [0, 1, 2, 3, 0, 0, 6])
Пример #2
0
    def __init__(self, initial_data=None, heap_type=HeapType.maxheap):
        self.heap_type = heap_type
        if heap_type == HeapType.maxheap:
            self.comparator = lambda x, y: x > y
        else:
            self.comparator = lambda x, y: x < y

        self.data = AutoResizeList()
        if initial_data is not None:
            self.build_heap(initial_data)

        self._size = len(self.data)
 def testPrepend(self):
     a = AutoResizeList([1, 2, 3])
     a.prepend(0)
     self.assertEqual(0, a._data[0])
 def testLen(self):
     a = AutoResizeList([1, 2, 3])
     self.assertEqual(len(a), 3)
 def testEqual(self):
     a = AutoResizeList([1, 2, 3])
     b = AutoResizeList([1, 2, 3])
     self.assertEqual(a, b)
 def testDel(self):
     d = AutoResizeList([0, 1, 2])
     d[4] = 4
     del d[3]
     self.assertEqual(d._data, [0, 1, 2, 4])
 def testGet(self):
     c = AutoResizeList([], fill=100)
     c[10] = 1
     self.assertEqual(c[10], 1)
     self.assertEqual(c[9], 100)