Exemplo n.º 1
0
	def test_speed_compare(self):
	
		H = FiboHeap()
		random.seed()

		n = 10000
		
		gc.disable()
		t1 = time.time()
		for d in range(n):
			H.insert(random.randint(1, 100000), "Random Data")
			
		for d in range(n):
			H.extract()
		
		t2 = time.time()
		zenFinal = t2-t1
		gc.collect()
		
		h = []
		t1 = time.time()
		for d in range(n):
			heappush(h, random.randint(1, 100000))

		for d in range(n):
			heappop(h)

		t2 = time.time()
		pythonFinal = t2-t1
		gc.enable()
		
		self.assertGreater(pythonFinal, zenFinal)
Exemplo n.º 2
0
    def test_insert_data(self):
        minNode = None

        H = FiboHeap()
        random.seed()

        for d in range(10000):
            n = random.randint(1, 100000)
            if minNode == None or n < minNode:
                minNode = n

            H.insert(n, n)

        self.assertEqual(H.get_min_key(), minNode)
Exemplo n.º 3
0
	def test_insert_data(self):
		minNode=None
	
		H = FiboHeap()
		random.seed()
		
		for d in range(10000):
			n = random.randint(1, 100000)
			if minNode == None or n < minNode:
				minNode = n
			
			H.insert(n,n)
		
		self.assertEqual(H.get_min_key(), minNode)
Exemplo n.º 4
0
    def test_object_data(self):

        H = FiboHeap()

        n1 = H.insert(1, 'this is a string')

        self.assertEqual('this is a string', H.get_node_data(n1))

        n2 = H.insert(2)
        H.replace_data(n2, (1, 2))
        self.assertEqual((1, 2), H.get_node_data(n2))

        self.assertEqual('this is a string', H.extract())
Exemplo n.º 5
0
	def test_object_data(self):
		
		H = FiboHeap()

		n1 = H.insert(1, 'this is a string')
		
		self.assertEquals('this is a string', H.get_node_data(n1))

		n2 = H.insert(2)
		H.replace_data(n2,(1,2))
		self.assertEquals((1,2), H.get_node_data(n2))

		self.assertEquals('this is a string', H.extract())
Exemplo n.º 6
0
    def test_rigorous_insert_extract(self):

        H = FiboHeap()
        random.seed()

        for d in range(100000):
            n = random.randint(1, 100000)
            m = H.insert(n, n)
            H.decrease_key(m, n-1)
            H.extract()
Exemplo n.º 7
0
    def test_decrease_key(self):
        nodes = []
        maxKey = None
        maxNode = None

        H = FiboHeap()
        random.seed()

        for d in range(10000):
            n = random.randint(1, 100000)
            if maxNode is None or n > maxKey:
                maxKey = n
                maxNode = H.insert(n, n)
                nodes.append(n)
            else:
                nodes.append(n)
                H.insert(n, n)

        H.decrease_key(maxNode, H.get_min_key())

        self.assertEqual(H.get_node_key(maxNode), H.get_min_key())
Exemplo n.º 8
0
    def test_speed_compare(self):

        H = FiboHeap()
        random.seed()

        n = 10000

        gc.disable()
        t1 = time.time()
        for d in range(n):
            H.insert(random.randint(1, 100000), "Random Data")

        for d in range(n):
            H.extract()

        t2 = time.time()
        zenFinal = t2-t1
        gc.collect()

        h = []
        t1 = time.time()
        for d in range(n):
            heappush(h, random.randint(1, 100000))

        for d in range(n):
            heappop(h)

        t2 = time.time()
        pythonFinal = t2-t1
        gc.enable()

        self.assertGreater(pythonFinal, zenFinal)
Exemplo n.º 9
0
	def test_rigorous_insert_extract(self):
		
		H = FiboHeap()
		random.seed()
		
		for d in range(100000):
			n = random.randint(1, 100000)
			m = H.insert(n,n)
			H.decrease_key(m, n-1)
			H.extract()
Exemplo n.º 10
0
	def test_decrease_key(self):
			nodes = []
			maxKey = None
			maxNode = None
			
		
			H = FiboHeap()
			random.seed()
			
			for d in range(10000):
				n = random.randint(1, 100000)
				if maxNode == None or n > maxNode:
					maxKey = n
					maxNode = H.insert(n,n)
					nodes.append(n)
				else: 
					nodes.append(n)
					H.insert(n,n)
			
			H.decrease_key(maxNode, H.get_min_key())	
			
			self.assertEqual(H.get_node_key(maxNode), H.get_min_key())
Exemplo n.º 11
0
    def test_insert_extract_order(self):

        nodes = []
        extractedNodes = []

        H = FiboHeap()
        random.seed()

        for d in range(10000):
            n = random.randint(1, 100000)
            nodes.append(n)
            H.insert(n, n)

        for i in range(10000):
            n = H.get_min_key()
            H.extract()
            extractedNodes.append(n)

        nodes.sort()

        self.assertEqual(extractedNodes, nodes)
Exemplo n.º 12
0
	def test_insert_extract_order(self):
		
		nodes = []
		extractedNodes = []
		
		H = FiboHeap()
		random.seed()
		
		for d in range(10000):
			n = random.randint(1, 100000)
			nodes.append(n)
			H.insert(n,n)

		for i in range(10000):
			n = H.get_min_key()
			H.extract()
			extractedNodes.append(n)
		
		nodes.sort()
	
		self.assertEqual(extractedNodes, nodes)