def run(self, duration=3, max_capacity=500): """ 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} ------') break # build test data weights, values, capacity = self.build_data(n, M, max_capacity) test_data = { 'capacity': capacity, 'weights': weights, 'values': values } test_name = f'Iteration_{iterations}' # get test results test_results = [] for algorithm in algorithms: algorithm_result = round(algorithm.use(**test_data), 2) test_results.append(algorithm_result) result = TestResult(test_name, algorithms, test_results, test_data) result.check_results(show_print=False) if result.failure == True: result.print_fail() break