Exemplo n.º 1
0
    def test_isMaxHeap_i(self):
        h = MaxHeap()
        isHeap = h.isHeap_i

        h.items = []
        assert isHeap() == True

        h.items = [1, 1]
        assert isHeap() == True

        h.items = [1, 1, 1]
        assert isHeap() == True
        '''
		  5
		 / \
		4   3
	   / \
	  2   1
		'''
        h.items = [5, 4, 3, 2, 1]
        assert isHeap() == True
        '''
		  2
		 /
		1
		'''
        h.items = [2, 1]
        assert isHeap() == True

        h.items = [1, 2]
        assert isHeap() == False
        '''
		  3
		 / \
		1   2
		'''
        h.items = [3, 1, 2]
        assert isHeap() == True
        '''
		   1
		 /   \
		2     3
	   / \  
	  4   5 
		'''
        h.items = [1, 2, 3, 4, 5]
        assert isHeap() == False

        h.items = range(10, -1, -1)
        assert isHeap() == True

        h.items = range(10)
        assert isHeap() == False
Exemplo n.º 2
0
    def test_sorted(self):
        l = range(10, -1, -1)
        MaxHeap.build_heap(l)
        h = MaxHeap()
        h.items = l

        new_l = []
        h.sorted(lambda i, l: l.append(i), new_l)

        assert new_l == range(10, -1, -1)