print(('{} of {} trial{} complete, {:3.1f}% with ' '{} satisfying all rules, {:3.1f}%').format( trial, trials, '' if trials == 1 else 's', 100 * trial / trials, satisfied, 100 * satisfied / trial)) if __name__ == '__main__': # random.seed(3.14159) # Use fixed seed for testing consistency tree = RedBlackTree(title='Red-Black Tree Tester') values = [int(arg) for arg in sys.argv[1:] if arg.isdigit() ] if len(sys.argv) > 1 else [i for i in range(1, 96, 3)] rulesSatisfied = 0 nNodes = 2 ** tree.MAX_LEVEL - 1 trials = 1000 for trial in range(trials): tree.emptyAndFill(nNodes) satisfied = len(tree.canvas.itemconfigure(tree.measures[3], 'text')[-1]) > 0 height = tree.getHeight(0) tree.startAnimations() if satisfied: rulesSatisfied += 1 print('Trial', trial, 'satisfied the rules') tree.wait(0.1) else: tree.wait(0) if height != tree.MAX_LEVEL: print('Tree height {} not equal to {}'.format( height, tree.MAX_LEVEL)) tree.wait(1)