Best Python code snippet using avocado_python
test.py
Source:test.py
1from subprocess import Popen, PIPE2from unittest import TestCase3import signal4import threading5import random6import logging7# use `sudo lsof -i -P -n` to make sure all processes have been terminated8def get_random_string():9 return "-" + str(random.randrange(0, 100000))10TIME_INTERVAL = 1 # in seconds11testcase = TestCase()12CLIENT1 = "client1" + get_random_string()13CLIENT2 = "client2" + get_random_string()14UNKNOWNCLIENT = "unknownClient" + get_random_string()15MESSAGE1 = "message1" + get_random_string()16MESSAGE2 = "message2" + get_random_string()17CLEANUP_COMMANDS = ["pkill -f python",18 "pkill -f Python"19 ]20# constants for test 121TEST1_SERVER_PORT = str(random.randrange(6600, 9000))22TEST1_COMMANDS = ["python3 server.py -p " + TEST1_SERVER_PORT,23 "python3 client.py -s 127.0.0.1 -p " + TEST1_SERVER_PORT + " -n " + CLIENT124 ]25TEST1_SERVER_INPUTS = []26TEST1_CLIENT_INPUTS = ["exit"]27TEST1_EXPECTED_SERVER_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST1_SERVER_PORT,28 CLIENT1 + " registered from host 127.0.0.1 port "29 ]30TEST1_EXPECTED_CLIENT_OUTPUTS = ["connected to server and registered " + CLIENT1,31 "terminating client..."32 ]33# constants for test234TEST2_SERVER_PORT = str(random.randrange(6600, 9000))35TEST2_COMMANDS = ["python3 server.py -p " + TEST2_SERVER_PORT,36 "python3 client.py -s 127.0.0.1 -p " + TEST2_SERVER_PORT + " -n " + CLIENT1,37 "python3 client.py -s 127.0.0.1 -p " + TEST2_SERVER_PORT + " -n " + CLIENT238 ]39TEST2_SERVER_INPUTS = []40TEST2_CLIENT1_INPUTS = []41TEST2_CLIENT2_INPUTS = []42TEST2_EXPECTED_SERVER_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST2_SERVER_PORT,43 CLIENT1 + " registered from host 127.0.0.1 port ",44 CLIENT2 + " registered from host 127.0.0.1 port "45 ]46TEST2_EXPECTED_CLIENT1_OUTPUTS = ["connected to server and registered " + CLIENT147 ]48TEST2_EXPECTED_CLIENT2_OUTPUTS = ["connected to server and registered " + CLIENT249 ]50# constants for test351TEST3_SERVER_PORT = str(random.randrange(6600, 9000))52TEST3_COMMANDS = ["python3 server.py -p " + TEST3_SERVER_PORT,53 "python3 client.py -s 127.0.0.1 -p " + TEST3_SERVER_PORT + " -n " + CLIENT1,54 "python3 client.py -s 127.0.0.1 -p " + TEST3_SERVER_PORT + " -n " + CLIENT255 ]56TEST3_SERVER_INPUTS = []57TEST3_CLIENT1_INPUTS = ["sendto " + CLIENT2 + " " + MESSAGE1,58 "sendto " + UNKNOWNCLIENT + " " + MESSAGE259 ]60TEST3_CLIENT2_INPUTS = []61TEST3_EXPECTED_SERVER_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST3_SERVER_PORT,62 CLIENT1 + " registered from host 127.0.0.1 port ",63 CLIENT2 + " registered from host 127.0.0.1 port ",64 CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1,65 CLIENT1 + " to " + UNKNOWNCLIENT + ": " + MESSAGE2,66 UNKNOWNCLIENT + " is not registered with server"67 ]68TEST3_EXPECTED_CLIENT1_OUTPUTS = ["connected to server and registered " + CLIENT169 ]70TEST3_EXPECTED_CLIENT2_OUTPUTS = ["connected to server and registered " + CLIENT2,71 CLIENT1 + ": " + MESSAGE172 ]73# constants for test474TEST4_SERVER1_PORT = str(random.randrange(6600, 9000))75TEST4_SERVER2_PORT = str(random.randrange(6600, 9000))76TEST4_SERVER1_OVERLAY_PORT = str(random.randrange(6600, 9000))77TEST4_SERVER2_OVERLAY_PORT = str(random.randrange(6600, 9000))78TEST4_COMMANDS = ["python3 server.py -p " + TEST4_SERVER1_PORT + " -o " + TEST4_SERVER1_OVERLAY_PORT,79 "python3 server.py -p " + TEST4_SERVER2_PORT + " -s 127.0.0.1 -t " + TEST4_SERVER1_OVERLAY_PORT + " -o " + TEST4_SERVER2_OVERLAY_PORT,80 "python3 client.py -s 127.0.0.1 -p " + TEST4_SERVER1_PORT + " -n " + CLIENT1,81 "python3 client.py -s 127.0.0.1 -p " + TEST4_SERVER2_PORT + " -n " + CLIENT282 ]83TEST4_SERVER1_INPUTS = []84TEST4_SERVER2_INPUTS = []85TEST4_CLIENT1_INPUTS = ["sendto " + CLIENT2 + " " + MESSAGE186 ]87TEST4_CLIENT2_INPUTS = []88TEST4_EXPECTED_SERVER1_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST4_SERVER1_PORT,89 "server overlay started at port " + TEST4_SERVER1_OVERLAY_PORT,90 "server overlay connection from host 127.0.0.1 port ",91 CLIENT1 + " registered from host 127.0.0.1 port ",92 CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1,93 CLIENT2 + " is not registered with server",94 "Sending message to overlay server: " + CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE195 ]96TEST4_EXPECTED_SERVER2_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST4_SERVER2_PORT,97 "server overlay started at port " + TEST4_SERVER2_OVERLAY_PORT,98 "connected to overlay server at 127.0.0.1 port " + TEST4_SERVER1_OVERLAY_PORT,99 CLIENT2 + " registered from host 127.0.0.1 port ",100 "Received from overlay server: " + CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1101 ]102TEST4_EXPECTED_CLIENT1_OUTPUTS = ["connected to server and registered " + CLIENT1103 ]104TEST4_EXPECTED_CLIENT2_OUTPUTS = ["connected to server and registered " + CLIENT2,105 CLIENT1 + ": " + MESSAGE1106 ]107# constants for test5108TEST5_SERVER1_PORT = str(random.randrange(6600, 9000))109TEST5_SERVER2_PORT = str(random.randrange(6600, 9000))110TEST5_SERVER1_OVERLAY_PORT = str(random.randrange(6600, 9000))111TEST5_SERVER2_OVERLAY_PORT = str(random.randrange(6600, 9000))112TEST5_COMMANDS = ["python3 server.py -p " + TEST5_SERVER1_PORT + " -o " + TEST5_SERVER1_OVERLAY_PORT,113 "python3 server.py -p " + TEST5_SERVER2_PORT + " -s 127.0.0.1 -t " + TEST5_SERVER1_OVERLAY_PORT + " -o " + TEST5_SERVER2_OVERLAY_PORT,114 "python3 client.py -s 127.0.0.1 -p " + TEST5_SERVER1_PORT + " -n " + CLIENT1,115 "python3 client.py -s 127.0.0.1 -p " + TEST5_SERVER2_PORT + " -n " + CLIENT2116 ]117TEST5_SERVER1_INPUTS = []118TEST5_SERVER2_INPUTS = []119TEST5_CLIENT1_INPUTS = ["sendto " + CLIENT2 + " " + MESSAGE1120 ]121TEST5_CLIENT2_INPUTS = ["sendto " + CLIENT1 + " " + MESSAGE2122 ]123TEST5_EXPECTED_SERVER1_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST5_SERVER1_PORT,124 "server overlay started at port " + TEST5_SERVER1_OVERLAY_PORT,125 "server overlay connection from host 127.0.0.1 port ",126 CLIENT1 + " registered from host 127.0.0.1 port ",127 CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1,128 CLIENT2 + " is not registered with server",129 "Sending message to overlay server: " + CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1,130 "Received from overlay server: " + CLIENT2 + " to " + CLIENT1 + ": " + MESSAGE2131 ]132TEST5_EXPECTED_SERVER2_OUTPUTS = ["server started on 127.0.0.1 at port " + TEST5_SERVER2_PORT,133 "server overlay started at port " + TEST5_SERVER2_OVERLAY_PORT,134 "connected to overlay server at 127.0.0.1 port " + TEST5_SERVER1_OVERLAY_PORT,135 CLIENT2 + " registered from host 127.0.0.1 port ",136 "Received from overlay server: " + CLIENT1 + " to " + CLIENT2 + ": " + MESSAGE1,137 CLIENT2 + " to " + CLIENT1 + ": " + MESSAGE2,138 CLIENT1 + " is not registered with server",139 "Sending message to overlay server: " + CLIENT2 + " to " + CLIENT1 + ": " + MESSAGE2140 ]141TEST5_EXPECTED_CLIENT1_OUTPUTS = ["connected to server and registered " + CLIENT1,142 CLIENT2 + ": " + MESSAGE2143 ]144TEST5_EXPECTED_CLIENT2_OUTPUTS = ["connected to server and registered " + CLIENT2,145 CLIENT1 + ": " + MESSAGE1146 ]147TEST_COMMANDS = [TEST1_COMMANDS, TEST2_COMMANDS, TEST3_COMMANDS, TEST4_COMMANDS, TEST5_COMMANDS]148TEST_INPUTS = [[TEST1_SERVER_INPUTS, TEST1_CLIENT_INPUTS],149 [TEST2_SERVER_INPUTS, TEST2_CLIENT1_INPUTS, TEST2_CLIENT2_INPUTS],150 [TEST3_SERVER_INPUTS, TEST3_CLIENT1_INPUTS, TEST3_CLIENT2_INPUTS],151 [TEST4_SERVER1_INPUTS,TEST4_SERVER2_INPUTS, TEST4_CLIENT1_INPUTS, TEST4_CLIENT2_INPUTS],152 [TEST5_SERVER1_INPUTS,TEST5_SERVER2_INPUTS, TEST5_CLIENT1_INPUTS, TEST5_CLIENT2_INPUTS]153 ]154EXPECTED_OUTPUTS = [[TEST1_EXPECTED_SERVER_OUTPUTS, TEST1_EXPECTED_CLIENT_OUTPUTS],155 [TEST2_EXPECTED_SERVER_OUTPUTS, TEST2_EXPECTED_CLIENT1_OUTPUTS, TEST2_EXPECTED_CLIENT2_OUTPUTS],156 [TEST3_EXPECTED_SERVER_OUTPUTS, TEST3_EXPECTED_CLIENT1_OUTPUTS, TEST3_EXPECTED_CLIENT2_OUTPUTS],157 [TEST4_EXPECTED_SERVER1_OUTPUTS, TEST4_EXPECTED_SERVER2_OUTPUTS, TEST4_EXPECTED_CLIENT1_OUTPUTS, TEST4_EXPECTED_CLIENT2_OUTPUTS],158 [TEST5_EXPECTED_SERVER1_OUTPUTS, TEST5_EXPECTED_SERVER2_OUTPUTS, TEST5_EXPECTED_CLIENT1_OUTPUTS, TEST5_EXPECTED_CLIENT2_OUTPUTS]159 ]160class TimeoutException(Exception):161 def __init__(self):162 super().__init__()163def handler(signum, frame):164 raise TimeoutException()165def run_process(process):166 signal.signal(signal.SIGALRM, handler)167 try:168 signal.alarm(TIME_INTERVAL) # timeout after TIME_INTERVAL (in seconds)169 process.wait()170 except TimeoutException:171 pass172 finally:173 signal.alarm(0)174def create_processes(commands, processes):175 for cmd in commands:176 process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)177 processes.append(process)178 run_process(process)179def run_processes(processes):180 for process in processes:181 run_process(process)182def write_to_console(processes, inputs):183 for i in range(len(processes)):184 for line in inputs[i]:185 line += "\n"186 processes[i].stdin.write(line.encode("utf-8"))187 processes[i].stdin.flush()188 run_process(processes[i])189def check_console_messages(processes, outputs):190 signal.signal(signal.SIGALRM, handler)191 for i in range(len(processes)):192 counter = 0193 try:194 signal.alarm(TIME_INTERVAL) # timeout after TIME_INTERVAL (in seconds)195 processes[i].stdout.flush()196 for line in processes[i].stdout:197 line = line.decode("utf-8").strip()198 if not (line.isspace() or line == ""):199 testcase.assertIn(outputs[i][counter], line)200 counter += 1201 except TimeoutException:202 # make sure that all expected lines are present203 testcase.assertEqual(counter, len(outputs[i]))204 pass205 finally:206 signal.alarm(0)207def kill_processes(processes):208 for process in processes:209 process.kill()210def cleanup():211 create_processes(CLEANUP_COMMANDS, [])212def check_results_and_cleanup(processes, outputs, identifier):213 try:214 check_console_messages(processes, outputs)215 print(identifier + " PASSED. CONGRATS!")216 return 20217 except AssertionError as e:218 errorMsg = str(e)219 if "!=" in errorMsg:220 logging.error(identifier + " FAILED: Missing console statements: " + str(e))221 else:222 logging.error(identifier + " FAILED: " + str(e))223 print(identifier + " FAILED.")224 return 0225 finally:226 kill_processes(processes)227 cleanup()228def run_tests():229 points = 0230 for i in range(len(TEST_COMMANDS)):231 processes = []232 create_processes(TEST_COMMANDS[i], processes)233 write_to_console(processes, TEST_INPUTS[i])234 run_processes(processes)235 points += check_results_and_cleanup(processes, EXPECTED_OUTPUTS[i], "TEST" + str(i+1))236 return points237if __name__ == "__main__":...
level2_level3.py
Source:level2_level3.py
1import timeit2from decimal import Decimal3decim1 = Decimal("0.33")4decim2 = Decimal("1.66")5s = "ab" * 10000 + "c"6L = [i for i in range(10000)]7T = tuple(i for i in range(10000))8S = {i for i in range(10000)}9D = {i: i for i in range(10000)}10R = range(10000)11int1 = 5 ** 712int2 = 7 ** 513long1 = 17 ** 1914long2 = 19 ** 1715float1 = 1e3016float2 = 1e-3017complex1 = 1 + 2j18complex2 = 2 - 1j19def test1_1():20 """(5 ** 7) + (7 ** 5) """21 return int1 + int222def test1_2():23 """17**19 + 19**17 """24 return long1 + long225def test1_3():26 """1e30 + 1e-30 """27 return float1 + float228def test1_4():29 """1+2j + 2-1j """30 return complex1 + complex231def test1_5():32 """0.33" + "1.66 """33 return decim1 + decim234def test1_6():35 """5**7 + 7**5 """36 return Decimal(int1 + int2)37def test1_7():38 """17**19 + 19**17 """39 return Decimal(long1 + long2)40def test2_1():41 """(5 ** 7) * (7 ** 5) """42 return int1 * int243def test2_2():44 """17**19 * 19**17"""45 return long1 * long246def test2_3():47 """1e30 * 1e-30 """48 return float1 * float249def test2_4():50 """1+2j * 2-1j """51 return complex1 * complex252def test2_5():53 """0.33" * "1.66 """54 return decim1 * decim255def test2_6():56 """5**7 * 7**5 """57 return Decimal(int1 * int2)58def test2_7():59 """17**19 * 19**17 """60 return Decimal(long1 * long2)61def test3_1():62 """(5 ** 7) / (7 ** 5) """63 return int1 / int264def test3_2():65 """17**19 / 19**17 """66 return long1 / long267def test3_3():68 """1e30 / 1e-30 """69 return float1 / float270def test3_4():71 """1+2j / 2-1j """72 return complex1 / complex273def test3_5():74 """0.33" / "1.66 """75 return decim1 / decim276def test3_6():77 """5**7 / 7**5 """78 return Decimal(int1 / int2)79def test3_7():80 """17**19 / 19**17 """81 return Decimal(long1 / long2)82def test4_1():83 """searching 'a' in s = "ab" * 10000 + "c" """84 return "a" in s85def test4_2():86 """searching 'b' in s = "ab" * 10000 + "c" """87 return "b" in s88def test4_3():89 """searching 'c' in s = "ab" * 10000 + "c" """90 return "c" in s91def test4_4():92 """searching 'ab' in s = "ab" * 10000 + "c" """93 return "ab" in s94def test4_5():95 """searching 'ba' in s = "ab" * 10000 + "c" """96 return "ba" in s97def test4_6():98 """searching 'bc' in s = "ab" * 10000 + "c" """99 return "bc" in s100def test4_7():101 """searching 'ac' in s = "ab" * 10000 + "c" """102 return "ac" in s103def test4_8():104 """searching 'ababababababababababc' in s = "ab" * 10000 + "c" """105 return "ababababababababababc" in s106def test5_1_1():107 """searching 0 in [i for i in range(10000)] """108 return 0 in L109def test5_1_2():110 """searching 9999 in [i for i in range(10000)] """111 return 9999 in L112def test5_1_3():113 """searching 10000 in [i for i in range(10000)] """114 return 10000 in L115def test5_2_1():116 """searching 0 in tuple(i for i in range(10000)) """117 return 0 in T118def test5_2_2():119 """searching 9999 in tuple(i for i in range(10000)) """120 return 9999 in T121def test5_2_3():122 """searching 10000 in tuple(i for i in range(10000)) """123 return 10000 in T124def test5_3_1():125 """searching 0 in {i for i in range(10000)} """126 return 0 in S127def test5_3_2():128 """searching 9999 in {i for i in range(10000)} """129 return 9999 in S130def test5_3_3():131 """searching 10000 in {i for i in range(10000)} """132 return 10000 in S133def test5_4_1():134 """searching 0 in {i:i for i in range(10000)} """135 return 0 in D136def test5_4_2():137 """searching 9999 in {i:i for i in range(10000)} """138 return 9999 in D139def test5_4_3():140 """searching 10000 in {i:i for i in range(10000)} """141 return 10000 in D142def test5_5_1():143 """searching 0 in range(10000) """144 return 0 in R145def test5_5_2():146 """searching 9999 in range(10000) """147 return 9999 in R148def test5_5_3():149 """searching 10000 in range(10000) """150 return 10000 in R151tests = (152 test1_1,153 test1_2,154 test1_3,155 test1_4,156 test1_5,157 test1_6,158 test1_7,159 test2_1,160 test2_2,161 test2_3,162 test2_4,163 test2_5,164 test2_6,165 test2_7,166 test3_1,167 test3_2,168 test3_3,169 test3_4,170 test3_5,171 test3_6,172 test3_7,173 test4_1,174 test4_2,175 test4_3,176 test4_4,177 test4_5,178 test4_6,179 test4_7,180 test4_8,181 test5_1_1,182 test5_1_2,183 test5_1_3,184 test5_2_1,185 test5_2_2,186 test5_2_3,187 test5_3_1,188 test5_3_2,189 test5_3_3,190 test5_4_1,191 test5_4_2,192 test5_4_3,193 test5_5_1,194 test5_5_2,195 test5_5_3,196)197def benchmark(testing, file):198 file.write(199 f"""Function: {testing.__doc__}200Time: {str(round(timeit.timeit(testing, number=1000), 5))}201"""202 )203with open("results.txt", "w") as file:204 for test in tests:205 benchmark(test, file)206 file.write(207 """208Below written has the format: 209the first line is the slowest type, his speed accepted as one; 210another lines are the faster types, their speed shows how many times they are faster the slowest type.211 """212 )213 test1 = {214 "list ": round(timeit.timeit(test5_1_1, number=1000), 5),215 "tuple ": round(timeit.timeit(test5_2_1, number=1000), 5),216 "set ": round(timeit.timeit(test5_3_1, number=1000), 5),217 "dict ": round(timeit.timeit(test5_4_1, number=1000), 5),218 "range ": round(timeit.timeit(test5_5_1, number=1000), 5),219 }220 file.write("\nTime for searching 0: \n")221 slowest = list(reversed(sorted(test1.values())))222 slowest = slowest[0]223 for p in test1:224 file.write(p + str(round((slowest / test1[p]), 3)))225 file.write("\n")226 test2 = {227 "list ": round(timeit.timeit(test5_1_2, number=1000), 5),228 "tuple ": round(timeit.timeit(test5_2_2, number=1000), 5),229 "set ": round(timeit.timeit(test5_3_2, number=1000), 5),230 "dict ": round(timeit.timeit(test5_4_2, number=1000), 5),231 "range ": round(timeit.timeit(test5_5_2, number=1000), 5),232 }233 file.write("\nTime for searching 9999: \n")234 slowest = list(reversed(sorted(test2.values())))235 slowest = slowest[0]236 for p in test2:237 file.write(p + str(round((slowest / test2[p]), 3)))238 file.write("\n")239 test3 = {240 "list ": round(timeit.timeit(test5_1_3, number=1000), 5),241 "tuple ": round(timeit.timeit(test5_2_3, number=1000), 5),242 "set ": round(timeit.timeit(test5_3_3, number=1000), 5),243 "dict ": round(timeit.timeit(test5_4_3, number=1000), 5),244 "range ": round(timeit.timeit(test5_5_3, number=1000), 5),245 }246 file.write("\nTime for searching 10000: \n")247 slowest = list(reversed(sorted(test3.values())))248 slowest = slowest[0]249 for p in test3:250 file.write(p + str(round((slowest / test3[p]), 3)))...
env_test.py
Source:env_test.py
1import numpy as np2import math3env_test1 = np.zeros((100,1,3))4env_test2 = np.zeros((100,2,3))5env_test3 = np.zeros((100,3,3))6env_test4 = np.zeros((100,4,3))7env_test5 = np.zeros((100,5,3))8#env_test1 development9for i in range(100):10 for j in range(1):11 env_test1[i][j][0]= np.random.randint(15,85)12 env_test1[i][j][1]= np.random.randint(15,85)13 env_test1[i][j][2]= np.random.randint(5,15)14#env_test2 development15for i in range(100):16 while True:17 for j in range(2):18 env_test2[i][j][0]= np.random.randint(15,85)19 env_test2[i][j][1]= np.random.randint(15,85)20 env_test2[i][j][2]= np.random.randint(5, 15)21 dis_1 = math.hypot(env_test2[i][0][0] - env_test2[i][1][0], env_test2[i][0][1] - env_test2[i][1][1])- \22 env_test2[i][0][2]-env_test2[i][1][2]23 if dis_1 > 20:24 break25#env_test3 development26for i in range(100):27 while True:28 for j in range(3):29 env_test3[i][j][0]= np.random.randint(15,85)30 env_test3[i][j][1]= np.random.randint(15,85)31 env_test3[i][j][2]= np.random.randint(5, 15)32 dis_1 = math.hypot(env_test3[i][0][0] - env_test3[i][1][0], env_test3[i][0][1] - env_test3[i][1][1])- \33 env_test3[i][0][2]-env_test3[i][1][2]34 dis_2 = math.hypot(env_test3[i][0][0] - env_test3[i][2][0], env_test3[i][0][1] - env_test3[i][2][1])- \35 env_test3[i][0][2]-env_test3[i][2][2]36 dis_3 = math.hypot(env_test3[i][1][0] - env_test3[i][2][0], env_test3[i][1][1] - env_test3[i][2][1])- \37 env_test3[i][1][2]-env_test3[i][2][2]38 if dis_1 > 20 and dis_2 > 20 and dis_3 > 20:39 break40#env_test4 development41for i in range(100):42 while True:43 for j in range(4):44 env_test4[i][j][0]= np.random.randint(15,85)45 env_test4[i][j][1]= np.random.randint(15,85)46 env_test4[i][j][2]= np.random.randint(5, 15)47 dis_1 = math.hypot(env_test4[i][0][0] - env_test4[i][1][0], env_test4[i][0][1] - env_test4[i][1][1]) - \48 env_test4[i][0][2] - env_test4[i][1][2]49 dis_2 = math.hypot(env_test4[i][0][0] - env_test4[i][2][0], env_test4[i][0][1] - env_test4[i][2][1]) - \50 env_test4[i][0][2] - env_test4[i][2][2]51 dis_3 = math.hypot(env_test4[i][0][0] - env_test4[i][3][0], env_test4[i][0][1] - env_test4[i][3][1]) - \52 env_test4[i][0][2] - env_test4[i][3][2]53 dis_4 = math.hypot(env_test4[i][1][0] - env_test4[i][2][0], env_test4[i][1][1] - env_test4[i][2][1]) - \54 env_test4[i][1][2] - env_test4[i][2][2]55 dis_5 = math.hypot(env_test4[i][1][0] - env_test4[i][3][0], env_test4[i][1][1] - env_test4[i][3][1]) - \56 env_test4[i][1][2] - env_test4[i][3][2]57 dis_6 = math.hypot(env_test4[i][2][0] - env_test4[i][3][0], env_test4[i][2][1] - env_test4[i][3][1]) - \58 env_test4[i][2][2] - env_test4[i][3][2]59 if dis_1 > 20 and dis_2 > 20 and dis_3 > 20 and dis_4 > 20 and dis_5 > 20 and dis_6 > 20:60 break61#env_test5 development62for i in range(5):63 while True:64 for j in range(5):65 env_test5[i][j][0]= np.random.randint(15,85)66 env_test5[i][j][1]= np.random.randint(15,85)67 env_test5[i][j][2]= np.random.randint(5, 15)68 dis_1 = math.hypot(env_test5[i][0][0] - env_test5[i][1][0], env_test5[i][0][1] - env_test5[i][1][1]) - \69 env_test5[i][0][2] - env_test5[i][1][2]70 dis_2 = math.hypot(env_test5[i][0][0] - env_test5[i][2][0], env_test5[i][0][1] - env_test5[i][2][1]) - \71 env_test5[i][0][2] - env_test5[i][2][2]72 dis_3 = math.hypot(env_test5[i][0][0] - env_test5[i][3][0], env_test5[i][0][1] - env_test5[i][3][1]) - \73 env_test5[i][0][2] - env_test5[i][3][2]74 dis_4 = math.hypot(env_test5[i][1][0] - env_test5[i][2][0], env_test5[i][1][1] - env_test5[i][2][1]) - \75 env_test5[i][1][2] - env_test5[i][2][2]76 dis_5 = math.hypot(env_test5[i][1][0] - env_test5[i][3][0], env_test5[i][1][1] - env_test5[i][3][1]) - \77 env_test5[i][1][2] - env_test5[i][3][2]78 dis_6 = math.hypot(env_test5[i][2][0] - env_test5[i][3][0], env_test5[i][2][1] - env_test5[i][3][1]) - \79 env_test5[i][2][2] - env_test5[i][3][2]80 dis_7 = math.hypot(env_test5[i][0][0] - env_test5[i][4][0], env_test5[i][0][1] - env_test5[i][4][1]) - \81 env_test5[i][0][2] - env_test5[i][4][2]82 dis_8 = math.hypot(env_test5[i][1][0] - env_test5[i][4][0], env_test5[i][1][1] - env_test5[i][4][1]) - \83 env_test5[i][1][2] - env_test5[i][4][2]84 dis_9 = math.hypot(env_test5[i][2][0] - env_test5[i][4][0], env_test5[i][2][1] - env_test5[i][4][1]) - \85 env_test5[i][2][2] - env_test5[i][4][2]86 dis_0 = math.hypot(env_test5[i][3][0] - env_test5[i][4][0], env_test5[i][3][1] - env_test5[i][4][1]) - \87 env_test5[i][3][2] - env_test5[i][4][2]88 if dis_1 > 20 and dis_2 > 20 and dis_3 > 20 and dis_4 > 20 and dis_5 > 20 and dis_6 > 20 and dis_7 > 20 \89 and dis_8 > 20 and dis_9 > 20 and dis_0 > 20:90 break91np.save("/home/wp/waveglider_RL/Environment/data/env_test5.npy", env_test5)92a = np.load("/home/wp/waveglider_RL/Environment/data/env_test5.npy")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!