def run(self, duration=3): """ Runs all the tests passed in at creation """ M = self.max_value n = self.data_size algorithms = self.algorithms start_time = time.time() end_time = start_time + duration iterations = 0 print(f"Running stress test iterations for {duration} seconds ...") while True: # ensure timed now = time.time() iterations += 1 if now >= end_time: print(f"\n------ ALL ITERATIONS PASSED ------") print( f"------ ELAPSED TIME - {round(now - start_time, 2)} SECONDS ------" ) print(f"------ ITERATIONS - {iterations} ------\n") break # build test data test_data = self.build_data() test_name = f"Iteration_{iterations}" # get test results test_results = [] for algorithm in algorithms: algorithm_result = algorithm.use(**test_data) test_results.append(algorithm_result) result = TestResult(test_name, algorithms, test_results, test_data) if result.get_status() == "fail": self.print_fail(result) break