Best Python code snippet using hypothesis
google_calendar_exercise.py
Source:google_calendar_exercise.py
...23 while index1 < len(person1_calendar):24 merged_list.append(person1_calendar[index1])25 index1 += 126 break27 time1 = convert_element(person1_calendar[index1][0])28 time2 = convert_element(person2_calendar[index2][0])29 if compare(time1, time2) == 1:30 merged_list.append(person1_calendar[index1])31 index1 += 132 elif compare(time1, time2) == 2:33 merged_list.append(person2_calendar[index2])34 index2 += 135 return merged_list36def compare(time1, time2):37 if time1 <= time2:38 return 139 else:40 return 241 pass42def eliminating(lis):43 index = 044 result = []45 while index < len(lis) -1:46 end1 = convert_element(lis[index][1])47 start2 = convert_element(lis[index + 1][0])48 end2 = convert_element(lis[index + 1][1])49 if end1 >= start2 and end1 <= end2:50 lis[index][1] = lis[index + 1][1]51 lis.pop(index + 1)52 elif end1 > end2:53 lis.pop(index + 1)54 else:55 if start2 - end1 >= 30:56 result.append([lis[index][1], lis[index + 1][0]])57 index += 158 else:59 index += 160 return result61 pass62def convert_element(string):63 hour, minute = string.split(":")64 time = int(hour) * 60 + int(minute)65 return time66def limit_parser(limit1,limit2):67 result = []68 result1 = []69 result2 = []70 limit1_1 = convert_element(limit1[0])71 limit1_2 = convert_element(limit1[1])72 limit2_1 = convert_element(limit2[0])73 limit2_2 = convert_element(limit2[1])74 if compare(limit1_1, limit2_1) == 1:75 result1.append(limit1[0])76 result1.append(limit2[0])77 else:78 result1.append(limit2[0])79 result1.append(limit1[0])80 if compare(limit1_2, limit2_2) == 1:81 result2.append(limit1[1])82 result2.append(limit2[1])83 else:84 result2.append(limit2[1])85 result2.append(limit1[1])86 result.append(result1)87 result.append(result2)88 return result89def pair_splitter(string):90 result = []91 first, second = string.split("-")92 result.append(first)93 result.append(second)94 return result95def get_free_intervalls(busy_intervalls, total_free_intervall):96 result = []97 new_busy_intervalls = []98 for i in range(len(busy_intervalls)):99 temp = convert_element(busy_intervalls[i][0])100 new_busy_intervalls.append([temp, busy_intervalls[i][1]])101 Sort(new_busy_intervalls)102 for i in range(len(new_busy_intervalls)):103 new_busy_intervalls[i][0] = convert_back_element(new_busy_intervalls[i][0])104 plus_free_start = [total_free_intervall[0], new_busy_intervalls[0][0]]105 plus_free_end = [get_biggest_second_from_list(new_busy_intervalls), total_free_intervall[1]]106 if plus_free_start[0] != plus_free_start[1]:107 result.append(plus_free_start)108 if eliminating(new_busy_intervalls) != []:109 for i in range(len(eliminating(new_busy_intervalls))):110 result.append(eliminating(new_busy_intervalls)[i])111 #result.append(eliminating(new_busy_intervalls))112 if plus_free_end[0] != plus_free_end[1]:113 result.append(plus_free_end)114 return result115def convert_back_element(time):116 result = ""117 hours = int(time / 60)118 minutes = time % 60119 if minutes == 0:120 result += str(hours) + ":00"121 elif minutes < 10:122 result += str(hours) + ":0" + str(minutes)123 else:124 result += str(hours) + ":" + str(minutes)125 return result126 pass127def Sort(list):128 list.sort(key=lambda x: x[0])129 return list130def check_validity(list, element, avalaible):131 element_start = convert_element(element[0])132 element_end = convert_element(element[1])133 avalaible_start = convert_element(avalaible[0])134 avalaible_end = convert_element(avalaible[1])135 if element_start < avalaible_start or element_end < avalaible_start:136 return -1137 elif element_end > avalaible_end or element_start > avalaible_end:138 return -1139 for i in range(len(list)):140 if element_start > convert_element(list[i][0]) and element_start < convert_element(list[i][1]):141 return -2142 elif element_end > convert_element(list[i][0]) and element_end < convert_element(list[i][1]):143 return -2144 elif element_start == convert_element(list[i][0]) and element_end == convert_element(list[i][1]):145 return -2146 return 1147def get_biggest_second_from_list(list):148 max_value = -1149 for i in range(len(list)):150 if max_value <= convert_element(list[i][1]):151 max_value = convert_element(list[i][1])152 return convert_back_element(max_value)153 pass154def check_format(string):155 try:156 first, second = string.split("-")157 first1, first2 = first.split(":")158 second1, second2 = second.split(":")159 except ValueError:160 return -1161 try:162 int(first1)163 int(first2)164 int(second1)165 int(second2)166 except ValueError:167 return -1168 if int(first1) < 0 or int(first1) >24 or int(first2) < 0 or int(first2) >60 or int(second1) < 0 or int(second1) >24 or int(second2) < 0 or int(second2) >60:169 return -1170 return 1171def sort_list(list):172 new_list = []173 for i in range(len(list)):174 temp = convert_element(list[i][0])175 new_list.append([temp, list[i][1]])176 Sort(new_list)177 for i in range(len(new_list)):178 new_list[i][0] = convert_back_element(new_list[i][0])179 return new_list180#limits = limit_parser(person1_limits, person2_limits)181#result_list = merge_lists(person1_calendar, person2_calendar)182#result = merge_lists(result_list, limits)183#new_res = eliminating(result)184#print(get_free_intervalls([["9:00", "10:30"], ["12:00", "13:00"], ["16:00", "18:00"]], ["9:00", "20:00"]))185#print(check_validity([["10:00", "11:30"], ["9:30", "12:00"], ["13:00", "14:30"]], ["12:00", "13:00"], ["9:00", "20:00"]))186#print(get_biggest_second_from_list([["10:00", "11:30"], ["9:30", "17:00"], ["13:00", "19:30"], ["12:30", "16:00"]]))...
matrix_to_ps.py
Source:matrix_to_ps.py
...16 for i in range(0, N):17 for j in range(0, N):18 #print('convert_element check:')19 #print(' args: m[i][j]={}, i={}, j={}, N={}, encoding={}'.format(matrix[i][j],i,j,N,encoding))20 #print(' res: {}'.format(convert_element(matrix[i][j],i,j,N,encoding)))21 22 # TODO: optimize could check matrix[i][j] is non-zero23 pauli_strings += convert_element(matrix[i][j], i, j, N, encoding)24 25 return pauli_strings26def convert_element(elem, i, j, N, encoding):27 nBinDigits = len(format(N-1,'b'))28 i_bin = encoding(i, nBinDigits)29 j_bin = encoding(j, nBinDigits)30 qubit_product = 131 32 for q in range(0,len(i_bin)):33 qubit_product *= basis_to_pauli_string(i_bin[q], j_bin[q], str(len(i_bin)-1-q))34 ...
MatrixToPauliString.py
Source:MatrixToPauliString.py
...16 for i in range(0, N):17 for j in range(0, N):18 #print('convert_element check:')19 #print(' args: m[i][j]={}, i={}, j={}, N={}, encoding={}'.format(matrix[i][j],i,j,N,encoding))20 #print(' res: {}'.format(convert_element(matrix[i][j],i,j,N,encoding)))21 pauli_strings += convert_element(matrix[i][j], i, j, N, encoding)22 23 return pauli_strings24def convert_element(elem, i, j, N, encoding):25 nBinDigits = len(format(N-1,'b'))26 i_bin = encoding(i, nBinDigits)27 j_bin = encoding(j, nBinDigits)28 qubit_product = 129 30 for q in range(0,len(i_bin)):31 qubit_product *= basis_to_pauli_string(i_bin[q], j_bin[q], str(len(i_bin)-1-q))32 ...
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!!