Best Python code snippet using hypothesis
stats_operators.py
Source:stats_operators.py
...79 def __init__(self):80 #self.server = server81 pass82 def __call__(self, v_in, **kw):83 return self.do_map(v_in, **kw)84 def do_map(self, v_in, **kw):85 # this one does nothing really86 return v_in87################################################################################88# misc89################################################################################90def mapflat(f, l):91 return reduce(operator.add, map(f, l))92################################################################################93# Resource Operator implementations94################################################################################95class StatOperatorResourceUri (StatOperator):96 '''maps resource into a vector of their uri as strings'''97 name = 'resource-uri'98 version = '1.1'99 def do_map(self, v_in, **kw):100 def nameSafe(t): return t.get('uri', '')101 return map(nameSafe, v_in)102################################################################################103# Tag Operator implementations104################################################################################105class StatOperatorTagName (StatOperator):106 '''maps tags into a vector of their names as strings'''107 name = 'tag-name-string'108 version = '1.1'109 def do_map(self, v_in, **kw):110 def nameSafe(t): return t.get('name', '')111 return map(nameSafe, v_in)112class StatOperatorTagValue (StatOperator):113 '''maps tags into a vector of their values as strings'''114 name = 'tag-value-string'115 version = '1.1'116 def do_map(self, v_in, **kw):117 def valueSafe(t):118 v = BQValue(element=t)119 return v.toString()120 return map(valueSafe, v_in)121class StatOperatorTagType (StatOperator):122 '''maps tags into a vector of their types as strings'''123 name = 'tag-type'124 version = '1.0'125 def do_map(self, v_in, **kw):126 def nameSafe(t): return t.get('type', '')127 return map(nameSafe, v_in)128class StatOperatorTagNameNumeric (StatOperator):129 '''maps tags into a vector of their names as numbers'''130 name = 'tag-name-number'131 version = '1.0'132 def do_map(self, v_in, **kw):133 def intValueSafe(t):134 try:135 return float(t.attrib['name'])136 except Exception:137 return None138 return map(intValueSafe, v_in)139class StatOperatorTagValueNumeric (StatOperator):140 '''maps tags into a vector of their values as numbers'''141 name = 'tag-value-number'142 version = '1.1'143 def do_map(self, v_in, **kw):144 def intValueSafe(t):145 v = BQValue(element=t)146 try:147 return float(v.toString())148 except Exception:149 return None150 return map(intValueSafe, v_in)151################################################################################152# Gob Operator primitives153################################################################################154# TODO:155# GObjects:156# point polyline polygon circle ellipse square rectangle157#158# Features:159# length, perimeter, area, major axis, minor axis160def gobNumber(gob):161 # return just the object itself right now162 return 1163def gobType(gob):164 return str(BQFactory.make(gob).getAttr('type'))165def gobName(gob):166 return str(BQFactory.make(gob).getAttr('name'))167def gobPerimeter(gob):168 return BQFactory.make(gob).perimeter()169def gobArea(gob):170 return BQFactory.make(gob).area()171def gobVertexStr(gob):172 return [ v.toString() for v in BQFactory.make(gob).vertices ]173def gobVertexType(gob):174 g = BQFactory.make(gob)175 n = str(g.getAttr('type'))176 return [ n for v in g.vertices ]177def gobVertexName(gob):178 g = BQFactory.make(gob)179 n = str(g.getAttr('name'))180 return [ n for v in g.vertices ]181def gobVertexV(gob, f):182 return [ f(v) for v in BQFactory.make(gob).vertices ]183def gobVertexX(gob):184 return gobVertexV(gob, lambda v: v.x)185def gobVertexY(gob):186 return gobVertexV(gob, lambda v: v.y)187def gobVertexZ(gob):188 return gobVertexV(gob, lambda v: v.z)189def gobVertexT(gob):190 return gobVertexV(gob, lambda v: v.t)191def gobVertexC(gob):192 return gobVertexV(gob, lambda v: v.c)193def gobVertexI(gob):194 return gobVertexV(gob, lambda v: v.index)195#-------------------------------------------------------------------------------196# Gob Operator implementations197#-------------------------------------------------------------------------------198class StatOperatorGobName (StatOperator):199 '''maps GObjects into a vector of their names'''200 name = 'gobject-name'201 version = '1.0'202 def do_map(self, v_in, **kw):203 return map(gobName, v_in)204class StatOperatorGobType (StatOperator):205 '''maps GObjects into a vector of their types'''206 name = 'gobject-type'207 version = '1.0'208 def do_map(self, v_in, **kw):209 return map(gobType, v_in)210class StatOperatorGobTypePrimitive (StatOperator):211 '''returns only present primitive types'''212 name = 'gobject-type-primitive'213 version = '1.0'214 def do_map(self, v_in, **kw):215 t = map(gobType, v_in)216 return [i for i in t if i in gobject_primitives]217class StatOperatorGobTypeComposed (StatOperator):218 '''maps GObjects into a vector of their types'''219 name = 'gobject-type-composed'220 version = '1.0'221 def do_map(self, v_in, **kw):222 t = set( map(gobType, v_in) )223 return [i for i in t if not i in gobject_primitives]224class StatOperatorGobLength (StatOperator):225 '''maps GObjects into a vector of their perimeters or lengths'''226 name = 'gobject-length'227 version = '1.0'228 def do_map(self, v_in, **kw):229 return map(gobPerimeter, v_in)230class StatOperatorGobPerimeter (StatOperator):231 '''maps GObjects into a vector of their perimeters or lengths'''232 name = 'gobject-perimeter'233 version = '1.0'234 def do_map(self, v_in, **kw):235 return map(gobPerimeter, v_in)236class StatOperatorGobArea (StatOperator):237 '''maps GObjects into a vector of their areas'''238 name = 'gobject-area'239 version = '1.0'240 def do_map(self, v_in, **kw):241 return map(gobArea, v_in)242class StatOperatorGobNumber (StatOperator):243 '''maps GObjects into a vector of their number, each number is object + children'''244 name = 'gobject-number'245 version = '1.0'246 def do_map(self, v_in, **kw):247 return map(gobNumber, v_in)248#-------------------------------------------------------------------------------249# Gob Vertex Operator implementations250#-------------------------------------------------------------------------------251class StatOperatorGobVertexString (StatOperator):252 '''maps gobjects into a vector of their vertices as strings: "X, Y, Z, T, C, I"'''253 name = 'gobject-vertex-string'254 version = '1.0'255 def do_map(self, v_in, **kw):256 return mapflat(gobVertexStr, v_in)257class StatOperatorGobVertexType (StatOperator):258 '''maps gobjects into a vector of their types given for every vertex'''259 name = 'gobject-vertex-type'260 version = '1.0'261 def do_map(self, v_in, **kw):262 return mapflat(gobVertexType, v_in)263class StatOperatorGobVertexName (StatOperator):264 '''maps gobjects into a vector of their names given for every vertex'''265 name = 'gobject-vertex-name'266 version = '1.0'267 def do_map(self, v_in, **kw):268 return mapflat(gobVertexName, v_in)269class StatOperatorGobVertexX (StatOperator):270 '''maps gobjects into a vector of their vertices''s x coordinate'''271 name = 'gobject-vertex-x'272 version = '1.0'273 def do_map(self, v_in, **kw):274 return mapflat(gobVertexX, v_in)275class StatOperatorGobVertexY (StatOperator):276 '''maps gobjects into a vector of their vertices''s y coordinate'''277 name = 'gobject-vertex-y'278 version = '1.0'279 def do_map(self, v_in, **kw):280 return mapflat(gobVertexY, v_in)281class StatOperatorGobVertexZ (StatOperator):282 '''maps gobjects into a vector of their vertices''s z coordinate'''283 name = 'gobject-vertex-z'284 version = '1.0'285 def do_map(self, v_in, **kw):286 return mapflat(gobVertexZ, v_in)287class StatOperatorGobVertexT (StatOperator):288 '''maps gobjects into a vector of their vertices''s t coordinate'''289 name = 'gobject-vertex-t'290 version = '1.0'291 def do_map(self, v_in, **kw):292 return mapflat(gobVertexT, v_in)293class StatOperatorGobVertexC (StatOperator):294 '''maps gobjects into a vector of their vertices''s c coordinate'''295 name = 'gobject-vertex-c'296 version = '1.0'297 def do_map(self, v_in, **kw):298 return mapflat(gobVertexC, v_in)299class StatOperatorGobVertexI (StatOperator):300 '''maps gobjects into a vector of their vertices''s index'''301 name = 'gobject-vertex-index'302 version = '1.0'303 def do_map(self, v_in, **kw):...
code2020_4.py
Source:code2020_4.py
1# -*- coding: utf-8 -*-2# @Author: gunjianpan3# @Date: 2020-04-18 15:42:444# @Last Modified by: gunjianpan5# @Last Modified time: 2020-04-18 21:35:416"""74. æå°è·³è·æ¬¡æ°8éè¿çç¨æ·æ°3159å°è¯è¿çç¨æ·æ°146910ç¨æ·æ»éè¿æ¬¡æ°32011ç¨æ·æ»æ交次æ°440712é¢ç®é¾åº¦Hard13为äºç»å·é¢çåå¦ä¸äºå¥å±ï¼åæ£å¢éå¼å
¥äºä¸ä¸ªå¼¹ç°§æ¸¸ææºã游ææºç± N 个ç¹æ®å¼¹ç°§ææä¸æï¼ç¼å·ä¸º 0 å° N-1ãåå§æä¸ä¸ªå°çå¨ç¼å· 0 ç弹簧å¤ãè¥å°çå¨ç¼å·ä¸º i ç弹簧å¤ï¼éè¿æå¨å¼¹ç°§ï¼å¯ä»¥éæ©æå°çåå³å¼¹å° jump[i] çè·ç¦»ï¼æè
å左弹å°å°ä»»æ左侧弹簧çä½ç½®ãä¹å°±æ¯è¯´ï¼å¨ç¼å·ä¸º i 弹簧å¤æå¨å¼¹ç°§ï¼å°çå¯ä»¥å¼¹å 0 å° i-1 ä¸ä»»æ弹簧æè
i+jump[i] ç弹簧ï¼è¥ i+jump[i]>=N ï¼å表示å°çå¼¹åºäºæºå¨ï¼ãå°çä½äºç¼å· 0 å¤ç弹簧æ¶ä¸è½åå左弹ã14为äºè·å¾å¥å±ï¼ä½ éè¦å°å°çå¼¹åºæºå¨ã请æ±åºæå°éè¦æå¨å¤å°æ¬¡å¼¹ç°§ï¼å¯ä»¥å°å°çä»ç¼å· 0 弹簧弹åºæ´ä¸ªæºå¨ï¼å³åå³è¶è¿ç¼å· N-1 ç弹簧ã15ç¤ºä¾ 1ï¼16è¾å
¥ï¼jump = [2, 5, 1, 1, 1, 1]17è¾åºï¼318解éï¼å° Z æå°éè¦æå¨ 3 次弹簧ï¼å°çä¾æ¬¡å°è¾¾ç顺åºä¸º 0 -> 2 -> 1 -> 6ï¼æç»å°çå¼¹åºäºæºå¨ã19éå¶ï¼201 <= jump.length <= 10^6211 <= jump[i] <= 1000022"""23import sys24sys.setrecursionlimit(100000)25class Solution:26 def minJump(self, jump: List[int]) -> int:27 N = len(jump)28 do = [ii + jj for ii, jj in enumerate(jump)]29 do_map, max_do = {}, max(do) + 130 for ii, jj in enumerate(do):31 if jj not in do_map:32 do_map[jj] = []33 do_map[jj].append(ii)34 self.min_res = 2 ** 3235 # print(do)36 def dfs(res: int, need: int, last_need: int):37 if res >= self.min_res:38 return39 if need == 0:40 if res < self.min_res:41 self.min_res = res42 return43 out_lists = [44 (ii, jj)45 for ii in range(need, last_need)46 for jj in do_map.get(ii, [])47 if jj < need48 ]49 for ii, jj in out_lists:50 dfs(res + (1 if need == N or ii == need else 2), jj, need)51 dfs(0, N, max_do)52 return self.min_res53# class Solution:54# def minJump(self, jump: List[int]) -> int:55# N = len(jump)56# do = [ii + jj for ii, jj in enumerate(jump)]57# do_map, max_do = {}, max(do)58# for ii, jj in enumerate(do):59# if jj not in do_map:60# do_map[jj] = []61# do_map[jj].append(ii)62# need, res = N, 063# # print(do)64# while need:65# if need in do_map:66# res += 167# need = do_map[need][0]68# else:69# res += (2 if need != N else 1)70# for ii in range(need + 1, max_do + 1):71# if ii in do_map:72# need = do_map[ii][0]73# break74# return res75from collections import deque # append(left), pop(left), extend76class Solution:77 def minJump(self, s: List[int]) -> int:78 N = len(s)79 dp = [0] * (N - 1) + [1]80 st = deque([(1, N - 1), (0, N)])81 for i in range(N - 2, -1, -1):82 if i + s[i] >= N:83 dp[i] = 184 st = deque([(1, i), (0, N)])85 else:86 x = i + s[i]87 l, r = 0, len(st) - 188 while l + 1 < r:89 mi = (l + r) // 290 if st[mi][1] > x:91 r = mi92 else:93 l = mi94 print(st, l)95 now = min(dp[x], st[l][0] + 1) + 196 dp[i] = now97 while st[0][0] > dp[i]:98 st.popleft()99 st.appendleft((dp[i], i))100 print(dp)...
838_domi.py
Source:838_domi.py
1def pushDominoes(dominoes):2 """3 :type dominoes: str4 :rtype: str5 """6 do_map = list('u')*len(dominoes)7 do = list(dominoes)8 cnt: int = int(0)9 for i in do:10 if i != '.':11 do_map[cnt] = 'd'12 cnt = cnt+113 while(1):14 cnt: int = int(0)15 do = list(dominoes)16 for i in dominoes:17 if i != '.':18 if i == 'L':19 if cnt - 1 >= 0:20 if do[cnt - 1] == 'R' and do_map[cnt - 1] == 'u':21 do[cnt - 1] = '.'22 do_map[cnt] = 'd'23 elif do_map[cnt - 1] == 'u':24 do[cnt - 1] = 'L'25 do_map[cnt] = 'd'26 elif i == 'R':27 if cnt + 1 <= len(do) - 1:28 if do[cnt + 1] == 'L' and do_map[cnt + 1] == 'u':29 do[cnt + 1] = '.'30 do_map[cnt] = 'd'31 elif do_map[cnt + 1] == 'u':32 do[cnt + 1] = 'R'33 do_map[cnt] = 'd'34 cnt = cnt + 135 temp = ''.join(do)36 if dominoes == temp:37 break38 else:39 dominoes = temp40 return dominoes41if __name__ == '__main__':42 dom = "RL"43 dom = pushDominoes(dom)...
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!!