Best Python code snippet using hypothesis
puzzle.py
Source:puzzle.py
...41 l2.append(x)42 l2.append(l2.pop(l2.index(0)))43 return l, l244 #private function for swapping positions on the board45 def __swap(self, pos1, pos2):46 self.puzzle[pos1], self.puzzle[pos2] = self.puzzle[pos2], self.puzzle[pos1] 47 if self.puzzle[pos1] == 0:48 return self.puzzle[pos2]49 else:50 return self.puzzle[pos1]51 #swaps the 0 slot up or down and adds to cost52 def upVerticalMove(self):53 pos = self.puzzle.index(0)54 w = self.width55 self.cost += 156 return self.__swap(pos, pos-w)57 58 def downVerticalMove(self):59 pos = self.puzzle.index(0)60 w = self.width61 self.cost += 162 return self.__swap(pos, pos+w)63 64 #moves 0 left and adds 1 to cost, if 0 is on the left edge then it wraps around and cost += 265 def leftHorizontalMove(self):66 pos = self.puzzle.index(0)67 w = self.width68 if pos % w == 0:69 self.cost += 270 return (self.__swap(pos, pos + w - 1),2)71 72 else:73 self.cost += 174 return (self.__swap(pos, pos-1),2)75 #moves 0 right and adds 1 to cost, if 0 is on the right edge then it wraps around and cost += 276 def rightHorizontalMove(self):77 pos = self.puzzle.index(0)78 w = self.width79 if pos % w == w - 1:80 self.cost += 281 return (self.__swap(pos, pos - w + 1),2)82 83 else:84 self.cost += 185 return (self.__swap(pos, pos+1),1)86 #moves the 0 diag left if 0 is in one of the corners and adds 3 to cost87 def leftDiagMove(self):88 pos = self.puzzle.index(0)89 w = self.width90 h = self.height91 top_l = 092 bottom_l = w*(h-1)93 top_r = w-194 bottom_r = w*h-195 self.cost +=396 if pos == top_l:97 return self.__swap(pos, bottom_r)98 elif pos == bottom_l:99 return self.__swap(pos, top_r)100 elif pos == top_r:101 return self.__swap(pos, pos + w -1)102 elif pos == bottom_l:103 return self.__swap(pos, pos - w -1)104 105 def getSolution(self):106 out = []107 for x in range(len(self.moveList)):108 out.append([self.moveList[x], self.CostList[x], self.stateList[x]])109 return out110 ##moves the 0 diag right if 0 is in one of the corners and adds 3 to cost111 def rightDiagMove(self):112 pos = self.puzzle.index(0)113 w = self.width114 h = self.height115 top_l = 0116 bottom_l = w*(h-1)117 top_r = w-1118 bottom_r = w*h-1119 self.cost += 3120 if pos == top_l:121 return self.__swap(pos, pos + w + 1)122 elif pos == bottom_l:123 return self.__swap(pos, pos - w + 1)124 elif pos == top_r:125 return self.__swap(pos, bottom_l)126 elif pos == bottom_r:127 return self.__swap(pos, top_l)128 def h_0(self):129 if self.getState()[-1] == 0:130 return 0131 else:132 return 1133 134 def getSumOfPermInv(self):135 count = 0 136 count2 = 0137 current = self.puzzle138 for x in current:139 remain = current[current.index(x)+1:]140 f1 = self.getFinal()[0]141 f2 = self.getFinal()[1]...
heap.py
Source:heap.py
...26 pi = i // 227 ei, ep = self.items[i], self.items[pi]28 if i == pi or ei >= ep:29 break30 self.__swap(i, pi)31 def insert(self, value): 32 self.items.append(value)33 self.__sift_up(len(self.items) - 1)34 def __sift_down(self, i = 0):35 while True:36 cl = 2*i + 137 cr = 2*i + 238 ei = self.items[i]39 el = self.items[cl] if cl < len(self.items) else float('inf')40 er = self.items[cr] if cr < len(self.items) else float('inf')41 if ei <= el and ei <= er: break42 if el < ei and el <= er:43 self.__swap(i, cl)44 i = cl45 elif er < ei and er < el:46 self.__swap(i, cr)47 i = cr48 def __swap(self, a, b):49 self.items[a], self.items[b] = self.items[b], self.items[a]50 def remove(self):51 if len(self.items) == 0:52 return None53 l_i = len(self.items) - 154 self.items[0], self.items[l_i] = self.items[l_i], self.items[0]55 value = self.items.pop()56 self.__sift_down()57 return value58 59 def peek_min(self):60 return self.items[0]61class MaxHeap:62 def __init__(self, items):63 self.items = items64 self.__heapify()65 def __len__(self):66 return len(self.items)67 def __heapify(self):68 for i in reversed(range(len(self.items) // 2)):69 self.__sift_down(i)70 def __sift_up(self, pi):71 while True:72 i = pi73 pi = i // 274 ei, ep = self.items[i], self.items[pi]75 if i == pi or ei <= ep:76 break77 self.__swap(i, pi)78 def insert(self, value): 79 self.items.append(value)80 self.__sift_up(len(self.items) - 1)81 def __sift_down(self, i = 0):82 if len(self) == 0:83 return84 while True:85 cl = 2*i + 186 cr = 2*i + 287 ei = self.items[i]88 el = self.items[cl] if cl < len(self.items) else float('inf')89 er = self.items[cr] if cr < len(self.items) else float('inf')90 if ei >= el and ei >= er: break91 if el > ei and el >= er:92 self.__swap(i, cl)93 i = cl94 elif er > ei and er > el:95 self.__swap(i, cr)96 i = cr97 def __swap(self, a, b):98 self.items[a], self.items[b] = self.items[b], self.items[a]99 def remove(self):100 if len(self.items) == 0:101 return None102 l_i = len(self.items) - 1103 self.items[0], self.items[l_i] = self.items[l_i], self.items[0]104 value = self.items.pop()105 self.__sift_down()106 return value107 108 def peek_max(self):109 return self.items[0]110heap = MinHeap([2, 6, 3, 4, 8, 30, 15,2 ,1, 9, 28, 4, 5, 24, 1, 12, 25])111check_heap_invariant(heap)...
215.py
Source:215.py
...20 else:21 return self.__findKthLargest(nums, start, pivot - 1, kthLarget - pivot_order)22 def __random_partition(self, nums, start, end):23 select_index = random.randrange(start, end)24 self.__swap(nums, select_index, end)25 return self.__partition(nums, start, end)26 def __partition(self, nums, start, end):27 pivot = nums[end]28 pivot_index = start - 129 for i in range(start, end+1):30 value = nums[i]31 if value < pivot:32 pivot_index += 133 self.__swap(nums, i, pivot_index)34 self.__swap(nums, pivot_index + 1, end)35 return pivot_index + 136 def __swap(self, nums, foo, bar):37 temp = nums[foo]38 nums[foo] = nums[bar]39 nums[bar] = temp40s = Solution()...
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!!