def testOne(): try: tree = BST(10) tree.insert(7) tree.insert(15) tree.insert(12) COMPARE_LISTS(list([10, 7, 15, 12]), tree.BFSTraversal()) tree.insert(13) COMPARE_LISTS(list([10, 7, 15, 12, 13]), tree.BFSTraversal()) tree.insert(14) COMPARE_LISTS(list([10, 7, 15, 12, 13, 14]), tree.BFSTraversal()) tree.insert(11) COMPARE_LISTS(list([10, 7, 15, 12, 11, 13, 14]), tree.BFSTraversal()) tree.insert(4) tree.insert(8) tree.insert(9) tree.insert(5) tree.insert(3) tree.insert(2) COMPARE_LISTS(list([10, 7, 15, 4, 8, 12, 3, 5, 9, 11, 13, 2, 14]), tree.BFSTraversal()) except Exception as err: print(err) print('Test 1 FAILED!') else: print('Test 1 Passed!') finally: print('Test 1 Complete.')
def testOne(schema): try: graph = Graph(schema) shortestPath = graph.shortestPath(3) if shortestPath == None: raise Exception('Shortest Path is None, but I expected a result!') COMPARE_LISTS([1, 2, 4, 3], graph.displayGraphInBFSOrder()) COMPARE_LISTS([1, 2, 3], shortestPath.printPath()) COMPARE_VALUES(2, shortestPath.getWeight()) except Exception as err: print(err) print('Test 1 FAILED!') else: print('Test 1 Passed!') finally: print('Test 1 Complete.')
def testTwo(schema): try: graph = Graph(schema) shortestPath = graph.shortestPath(7) if shortestPath == None: raise Exception('Shortest path is None, but I expected a result!') COMPARE_LISTS([1, 2, 3, 5, 6, 7, 4], graph.displayGraphInBFSOrder()) COMPARE_LISTS([1, 2, 5, 7], shortestPath.printPath()) COMPARE_VALUES(3, shortestPath.getWeight()) except Exception as err: print(err) print('Test 2 FAILED!') else: print('Test 2 Passed!') finally: print('Test 2 Complete.')
def testFour(): try: tree = BST(10) tree.insert(7) tree.insert(15) tree.insert(12) tree.insert(13) tree.insert(14) tree.insert(11) tree.insert(4) tree.insert(8) tree.insert(9) tree.insert(5) tree.insert(3) tree.insert(2) tree.removeElem(3) COMPARE_LISTS(list([10, 7, 15, 4, 8, 12, 2, 5, 9, 11, 13, 14]), tree.BFSTraversal()) except Exception as err: print(err) print('Test 4 FAILED!') else: print('Test 4 Passed!') finally: print('Test 4 Complete.')
def testOne(): try: heap = Heap(4) heap.insert(3) heap.insert(1) heap.insert(2) heap.insert(5) COMPARE_LISTS(list([1, 2, 3, 4, 5]), heap.sort()) COMPARE_VALUES(0, heap.getLength()) except Exception as err: print(err) print('Test 1 FAILED!') else: print('Test 1 Passed!') finally: print('Test 1 Complete.')
def testTwo(): try: heap = Heap(4) heap.insert(3) heap.insert(1) heap.insert(2) heap.insert(5) heap.insert(10) heap.insert(9) heap.insert(6) heap.insert(8) heap.insert(7) COMPARE_LISTS(list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), heap.sort()) COMPARE_VALUES(0, heap.getLength()) except Exception as err: print(err) print('Test 2 FAILED!') else: print('Test 2 Passed!') finally: print('Test 2 Complete.')