import unittest

from implementations.heap import Heap


class HeapTest(unittest.TestCase):

    def test_heap_creation(self):
        heap = Heap()
        self.assertEqual(heap.items, [])
        heap.insert(3)
        self.assertEqual(heap.items, [3])
        heap.insert(5)
        self.assertEqual(heap.items, [3, 5])
        heap.insert(1)
        self.assertEqual(heap.items, [1, 5, 3])
        heap.insert(-1)
        self.assertEqual(heap.items, [-1, 1, 3, 5])
        heap.insert(0)
        self.assertEqual(heap.items, [-1, 0, 3, 5, 1])

    def test_heap_extracts(self):
        heap = Heap()
        heap.items = [-1, 0, 3, 5, 1]
        self.assertEqual(heap.extract_min(), -1)
        self.assertEqual(heap.items, [0, 1, 3, 5])
        self.assertEqual(heap.extract_min(), 0)
        self.assertEqual(heap.items, [1, 5, 3])
        self.assertEqual(heap.extract_min(), 1)
        self.assertEqual(heap.items, [3, 5])
        self.assertEqual(heap.extract_min(), 3)
        self.assertEqual(heap.items, [5])
        self.assertEqual(heap.extract_min(), 5)
        self.assertEqual(heap.items, [])


if __name__ == '__main__':
    unittest.main()