def runSimplex(self, startPoint, epsilon, dim): self.iterator = 0 #init first tuple object prevBest = func(self.function, startPoint) self.DATA.append([startPoint, prevBest]) #init simplex points #create +n(dim) points with every val+initLength for i in range(dim): buff = copy(startPoint) buff[i] = buff[i] + random.uniform(1, 3) buffVal = func(self.function, buff) self.DATA.append([buff, buffVal]) print(self.DATA) self.HISTORY = copy(self.DATA) stopReq = self.chceckRequest(self.iterator) # stopReq = True ### START ITERATIONS ### while (stopReq): self.iterator = self.iterator + 1 #sort simplex for best(lowest) value at the start self.sortSimplex() centroid = self.centroid(func, dim) #centre of simplex reflection = self.reflection(func, centroid) if (reflection[1] < self.DATA[0][1]): #Fr < min expansion = self.expansion(func, reflection, centroid) if (expansion[1] < self.DATA[-1][1]): #Fe < max self.DATA[-1] = expansion else: self.DATA[-1] = reflection #next iteration if not F0>min if (reflection[1] > self.DATA[0][1]): for i in self.DATA[:-1]: if (reflection[1] >= self.DATA[-1][1]): continue else: self.DATA[-1] = reflection contraction = self.contraction(func, centroid) if (contraction[1] >= self.DATA[-1][1]): self.reduction() else: self.DATA[-1] = contraction for i in self.DATA[:-1]: if (reflection[1] < self.DATA[-1][1]): self.DATA[-1] = reflection #check iteration request stopReq = self.chceckRequest(self.iterator) self.HISTORY.append(self.DATA[-1]) #END OF WHILE ITERATION print("Loops: ", self.iterator) self.sortSimplex() print(self.DATA) print("ERROR: ", self.returnErr())
def test_mock(mocker): mocker.patch("sub1.client1.func1", return_value=10) assert cli1.func1() == 10 mocker.patch("main.func", return_value="XXX") hello = main.func("foo") assert hello == "XXX"
def apinum(number): result = { "number": number, "Armstrong": main.func(number), "server IP": IPAddr } return jsonify(result)
def test_input_output(self): input_value = {'hired': {'be': {'to': {'deserve': 'I'}}}} expected = {'I': {'deserve': {'to': {'be': 'hired'}}}} result = func(input_value) self.assertEqual(result, expected)
def output(request): #It's the current file location HERE = Path(__file__).parent sys.path.append(str(HERE / '../../')) #Importing the main() function from main import func search = func() if 'c0' not in search.payload[0].display_name: search = 'Distracted!' else: search = 'Not Distracted' return render(request, 'home.html', {'search': search})
def test_func(): hello = main.func("foo") assert hello == "hello foo"
main.read() if main.event in (None, 'Cancel'): break elif main.event == 'Run': path_input = main.values['-INPUT_FILE-'] dir_output = main.values['-OUTPUT_FOLDER-'] if path_input == '': sg.PopupError('You have to select input file.', **popup_options) elif dir_output == '': sg.PopupError('You have to select output folder.', **popup_options) else: seed = randint(0, 2**32) if main.values['seed'] == 'None' else int( main.values['seed']) try: func(random_state=seed, path_input=path_input, dir_output=dir_output) except Exception as e: sg.PopupError(e, **popup_options) else: sg.PopupOK('Finish!', **popup_options) with open(os.path.join(dir_output, 'seed.txt'), mode='w', encoding='utf_8_sig') as f: f.write('SEED: {}'.format(seed)) subprocess.run(['open', dir_output]) finally: break main.window.close()
def test_function_that_raises_another_exception(self): with self.assertRaises(KeyError): func()
def RUN_mark(color, robot_id, barriers, target_x, target_y, global_p, local_p, receive): global_planner = global_p local_planner = local_p R = 25 index = 1 r = R / index receive.get_info(color, robot_id) score = 0 path_last = [] lines_last = [] path_lines_last = [] score_list = [] path_list = [] flag = 0 s = time.time() for index in range(20): global_path = global_planner(target_x, target_y, -target_x, -target_y, barriers, # receive, color=color, id=robot_id) receive, color=color, id=robot_id, inflateRadius=R, dis_threshold=R) status, tree, lines = global_path.Generate_Path() if status: flag += 1 path, path_lines = global_path.Get_Path() path, path_lines = global_path.merge() score_now = mark(path, barriers, receive, color, robot_id) score_list.append(score_now) path_list.append(path) lines_last.append(lines) path_lines_last.append(path_lines) score_list = np.array(score_list) path_list = np.array(path_list) ind = np.argpartition(score_list, -5)[-5:] # import ipdb; ipdb.set_trace() path_select = path_list[ind] path_select = [interpolate_path(path_s) for path_s in path_select] lines_last = np.array(lines_last)[ind] path_lines_last = np.array(path_lines_last)[ind] e = time.time() print('cost:', e-s) print(flag) if flag == 0: func(color, robot_id, receive) return global_path = global_planner(receive.robot_info['x'], receive.robot_info['y'], target_x, target_y, barriers, # receive, color=color, id=robot_id) receive, color=color, id=robot_id, inflateRadius=R, dis_threshold=R) status, tree, lines = global_path.Generate_Path() path, path_lines = global_path.Get_Path() path, path_lines = global_path.merge() path_start = path debug_info = SendDebug('LINE', [lines, path_lines]) debug_info.send() motion = local_planner() motion.line_control(path_start, robot_id, color, receive, target_x, target_y, barriers, r, index=index) index = 1 num = 0 r = R / index while True: path_last = path_select[num] debug_info = SendDebug('LINE', [lines_last[num], path_lines_last[num]]) debug_info.send() receive.get_info(color, robot_id) motion = local_planner() motion.line_control(path_last, robot_id, color, receive, target_x, target_y, barriers, r, index=index) target_x *= -1 target_y *= -1 path_last = path_last[::-1] receive.get_info(color, robot_id) motion = local_planner() motion.line_control(path_last, robot_id, color, receive, target_x, target_y, barriers, r, index=index) num += 1 if num == 5: num = 0
def test_main(): assert func(4) == 4
def test_func(self): self.assertEqual(main.func(1), 2)
def test_answer(): assert func(3) == 4
def test_func(self, mock_open): mock_open.return_value = '127.0.0.1' result = func() mock_open.assert_called_with('http://130.92.70.160/5000') self.assertEqual(result, '127.0.0.1')
def RUN_mark(color, robot_id, barriers, target_x, target_y, global_p, local_p, receive): global_planner = global_p local_planner = local_p R = 30 index = 1 r = R / index receive.get_info(color, robot_id) score = 0 path_last = [] lines_last = [] path_lines_last = [] flag = 0 s = time.time() for index in range(20): global_path = global_planner( target_x, target_y, -target_x, -target_y, barriers, # receive, color=color, id=robot_id) receive, color=color, id=robot_id, inflateRadius=R, dis_threshold=R) status, tree, lines = global_path.Generate_Path() if status: flag += 1 path, path_lines = global_path.Get_Path() path, path_lines = global_path.merge() score_now = mark(path, barriers, receive, color, robot_id) if score_now >= score: score = score_now path_last = path lines_last = lines path_lines_last = path_lines path_last = interpolate_path(path_last) e = time.time() print('cost:', e - s) print(flag) if flag == 0: func(color, robot_id, receive) return global_path = global_planner( receive.robot_info['x'], receive.robot_info['y'], target_x, target_y, barriers, # receive, color=color, id=robot_id) receive, color=color, id=robot_id, inflateRadius=R, dis_threshold=R) status, tree, lines = global_path.Generate_Path() path, path_lines = global_path.Get_Path() path, path_lines = global_path.merge() path_start = path debug_info = SendDebug('LINE', [lines, path_lines]) debug_info.send() motion = local_planner() motion.line_control(path_start, robot_id, color, receive, target_x, target_y, barriers, r, index=index) debug_info = SendDebug('LINE', [lines_last, path_lines_last]) debug_info.send() # receive.get_info(color, robot_id) # now_x = receive.robot_info['x'] # now_y = receive.robot_info['y'] index = 1 r = R / index while True: receive.get_info(color, robot_id) motion = local_planner() motion.line_control(path_last, robot_id, color, receive, target_x, target_y, barriers, r, index=index) target_x *= -1 target_y *= -1 path_last = path_last[::-1]