How to use __push method in hypothesis

Best Python code snippet using hypothesis

vm.py

Source:vm.py Github

copy

Full Screen

...130 else:131 raise RuntimeError('No such operation: ', op)132 def top(self):133 return self.__data_stack.top()134 def __push(self, value):135 self.__data_stack.push(value)136 def __pop(self):137 return self.__data_stack.pop()138 def __add(self):139 self.__push(self.__pop() + self.__pop())140 def __sub(self):141 last = self.__pop()142 self.__push(self.__pop() - last)143 def __mul(self):144 self.__push(self.__pop() * self.__pop())145 def __div(self):146 last = self.__pop()147 self.__push(self.__pop() / last)148 def __mod(self):149 last = self.__pop()150 self.__push(self.__pop() % last)151 def __eq(self):152 self.__push(self.__pop() == self.__pop())153 def __ne(self):154 self.__push(self.__pop() != self.__pop())155 def __lt(self):156 last = self.__pop()157 self.__push(self.__pop() < last)158 def __le(self):159 last = self.__pop()160 self.__push(self.__pop() <= last)161 def __gt(self):162 last = self.__pop()163 self.__push(self.__pop() > last)164 def __ge(self):165 last = self.__pop()166 self.__push(self.__pop() >= last)167 def __ord(self):168 char = self.__pop()169 if isinstance(char, str) and len(char) == 1:170 self.__push(ord(char))171 elif isinstance(char, str):172 raise ValueError('ord accepts only one symbol')173 else:174 raise ValueError('ord accepts char(one-symbol str)')175 def __chr(self):176 code = self.__pop()177 if isinstance(code, int) and code > 0:178 self.__push(chr(code))179 else:180 raise ValueError('chr accepts positive int')181 def __sep(self):182 word = self.__pop()183 word_size = len(word)184 if isinstance(word, str):185 for char in list(word):186 self.__push(char)187 self.__push(word_size)188 else:189 raise ValueError('sep accepts str')190 def __uni(self):191 word = ''192 word_size = self.__pop()193 for i in range(word_size):194 word += self.__pop()195 word = word[::-1]196 self.__push(word)197 def __encr(self):198 self.__sep()199 word_size = self.__pop()200 word = [0 for _ in range(word_size)]201 for i in reversed(range(word_size)):202 self.__ord()203 word[i] = self.__pop() + self.__key204 for char in word:205 self.__push(char)206 self.__chr()207 self.__push(word_size)208 self.__uni()209 def __decr(self):210 self.__sep()211 word_size = self.__pop()212 word = [0 for _ in range(word_size)]213 for i in reversed(range(word_size)):214 self.__ord()215 word[i] = self.__pop() - self.__key216 for char in word:217 self.__push(char)218 self.__chr()219 self.__push(word_size)220 self.__uni()221 def __cast_int(self):222 self.__push(int(self.__pop()))223 def __cast_str(self):224 self.__push(str(self.__pop()))225 def __drop(self):226 self.__pop()227 def __dup(self):228 self.__push(self.top())229 def __if_cond(self):230 condition = self.__pop()231 false_clause = self.__pop()232 true_clause = self.__pop()233 self.__push(true_clause if condition else false_clause)234 def __jmp(self):235 addr = self.__pop()236 if isinstance(addr, int) and 0 <= addr < len(self.__code):237 self.__instruction_pointer = addr238 else:239 raise ValueError('jmp address should be non-negative integer')240 def __stack(self):241 print('Data stack:', end='')242 print(' Empty') if self.__data_stack.empty() else print()243 for el in self.__data_stack:244 print(f" - type {type(el)}, value '{el}'")245 print(f'Instruction pointer: {self.__instruction_pointer}')246 print('Return stack:', end='')247 print(' Empty\n') if self.__return_stack.empty() else print('\n')248 for el in self.__return_stack:249 print(f" - type {type(el)}, value '{el}'")250 def __swap(self):251 self.__data_stack[-1], self.__data_stack[-2] = self.__data_stack[-2], self.__data_stack[-1]252 def __print_(self):253 print(self.__pop(), end=' ')254 def __println(self):255 print(self.__pop())256 def __read(self):257 self.__push(self.__get_input())258 def __get_input(self):259 return input()260 def __call(self):261 self.__return_stack.push(self.__instruction_pointer)262 self.__jmp()263 def __return_(self):264 self.__instruction_pointer = self.__return_stack.pop()265 def __exit(self):266 sys.exit(0)267 def __test(self):268 pass269 def __store(self):270 name = self.__pop()271 value = self.__pop()272 self.__vars[name] = value273 def __load(self):...

Full Screen

Full Screen

lazy_segtree.py

Source:lazy_segtree.py Github

copy

Full Screen

...36 def __all_apply(self, k: int, f):37 self.__d[k] = self.__mapping(f, self.__d[k])38 if(k < self.__size):39 self.__lz[k] = self.__composition(f, self.__lz[k])40 def __push(self, k: int):41 self.__all_apply(2 * k, self.__lz[k])42 self.__all_apply(2 * k + 1, self.__lz[k])43 self.__lz[k] = self.__id44 def set(self, p: int, x):45 assert (0 <= p) & (p < self.__n)46 p += self.__size47 for i in range(self.__log, 0, -1):48 self.__push(p >> i)49 self.__d[p] = x50 for i in range(1, self.__log + 1):51 self.__update(p >> i)52 def get(self, p: int):53 assert (0 <= p) & (p < self.__n)54 p += self.__size55 for i in range(self.__log, 0, -1):56 self.__push(p >> i)57 return self.__d[p]58 def prod(self, l: int, r: int):59 assert (0 <= l) & (l <= r) & (r <= self.__n)60 if(l == r):61 return self.__e62 l += self.__size63 r += self.__size64 for i in range(self.__log, 0, -1):65 if((l >> i) << i) != l:66 self.__push(l >> i)67 if((r >> i) << i) != r:68 self.__push(r >> i)69 sml = self.__e70 smr = self.__e71 while(l < r):72 if(l & 1):73 sml = self.__op(sml, self.__d[l])74 l += 175 if(r & 1):76 r -= 177 smr = self.__op(self.__d[r], smr)78 l //= 279 r //= 280 return self.__op(sml, smr)81 def all_prod(self):82 return self.__d[1]83 def apply(self, p: int, f):84 assert (0 <= p) & (p < self.__n)85 p += self.__size86 for i in range(self.__log, 0, -1):87 self.__push(p >> i)88 self.__d[p] = self.__mapping(f, self.__d[p])89 for i in range(1, self.__log + 1):90 self.__update(p >> i)91 def apply_range(self, l: int, r: int, f):92 assert (0 <= l) & (l <= r) & (r <= self.__n)93 if(l == r):94 return95 l += self.__size96 r += self.__size97 for i in range(self.__log, 0, -1):98 if((l >> i) << i) != l:99 self.__push(l >> i)100 if((r >> i) << i) != r:101 self.__push((r - 1) >> i)102 l2, r2 = l, r103 while(l < r):104 if(l & 1):105 self.__all_apply(l, f)106 l += 1107 if(r & 1):108 r -= 1109 self.__all_apply(r, f)110 l //= 2111 r //= 2112 l, r = l2, r2113 for i in range(1, self.__log + 1):114 if((l >> i) << i) != l:115 self.__update(l >> i)116 if((r >> i) << i) != r:117 self.__update((r - 1) >> i)118 def max_right(self, l: int, g):119 assert (0 <= l) & (l <= self.__n)120 assert g(self.__e)121 if(l == self.__n):122 return self.__n123 l += self.__size124 for i in range(self.__log, 0, -1):125 self.__push(l >> i)126 sm = self.__e127 while(True):128 while(l % 2 == 0):129 l //= 2130 if(not g(self.__op(sm, self.__d[l]))):131 while(l < self.__size):132 self.__push(l)133 l *= 2134 if(g(self.__op(sm, self.__d[l]))):135 sm = self.__op(sm, self.__d[l])136 l += 1137 return l - self.__size138 sm = self.__op(sm, self.__d[l])139 l += 1140 if(l & -l) == l:141 break142 return self.__n143 def min_left(self, r: int, g):144 assert (0 <= r) & (r <= self.__n)145 assert g(self.__e)146 if(r == 0):147 return 0148 r += self.__size149 for i in range(self.__log, 0, -1):150 self.__push((r - 1) >> i)151 sm = self.__e152 while(True):153 r -= 1154 while(r > 1) & (r % 2):155 r //= 2156 if(not g(self.__op(self.__d[r], sm))):157 while(r < self.__size):158 self.__push(r)159 r = 2 * r + 1160 if(g(self.__op(self.__d[r], sm))):161 sm = self.__op(self.__d[r], sm)162 r -= 1163 return r + 1 - self.__size164 sm = self.__op(self.__d[r], sm)165 if(r & -r) == r:166 break167 return 0168 def all_push(self):169 for i in range(1, self.__size):170 self.__push(i)171 def get_all(self):172 self.all_push()173 return self.__d[self.__size:self.__size + self.__n]174 def print(self):175 print(list(map(lambda x: divmod(x, (1 << 30)), self.__d)))176 print(self.__lz)177 print('------------------')178# ----- 区間加算・区間最小 ----- #179e = INF180id = 0181def op(a, b):182 return min(a, b)183def mapping(f, a):184 return a + f...

Full Screen

Full Screen

lexer.py

Source:lexer.py Github

copy

Full Screen

...56 if self.index < len(self.src):57 return self.src[self.index]58 else:59 return None60 def __push(self, type):61 self.tokens.append((type, self.value))62 self.value = ""63 def __lex_func(self, fn, type=None):64 while self.index < len(self.src) and fn(self.__look()):65 self.__eat()66 if type != None:67 self.__push(type)68 def tokenize(self, src):69 self.index = 070 self.tokens = []71 self.src = src72 while self.index < len(src):73 char = self.__eat()74 if char.isalpha():75 self.__lex_func(lambda c: c.isalnum() or c == '_')76 if self.value == "on":77 self.__push(Token.ON)78 elif self.value == "if":79 self.__push(Token.IF)80 elif self.value == "or":81 self.__push(Token.OR)82 elif self.value == "and":83 self.__push(Token.AND)84 elif self.value == "not":85 self.__push(Token.NOT)86 elif self.value == "send":87 self.__push(Token.SEND)88 elif self.value == "with":89 self.__push(Token.WITH)90 elif self.value == "do":91 self.__push(Token.DO)92 elif self.value == "then":93 self.__push(Token.THEN)94 elif self.value == "end":95 self.__push(Token.END)96 elif self.value == "let":97 self.__push(Token.LET)98 elif self.value == "entity":99 self.__push(Token.ENTITY)100 elif self.value == "surface":101 self.__push(Token.SURFACE)102 elif self.value == "texture":103 self.__push(Token.TEXTURE)104 elif self.value == "overlay":105 self.__push(Token.OVERLAY)106 elif self.value == "background":107 self.__push(Token.BACKGROUND)108 else:109 self.__push(Token.ID)110 elif char == '"':111 self.value = ""112 self.__lex_func(lambda c: c != '"')113 self.__push(Token.STRING)114 token = self.__eat()115 self.__assert(token, '"')116 self.value = ""117 elif char.isdigit():118 self.__lex_func(lambda c: c.isdigit(), Token.NUM)119 elif char == '(':120 self.__push(Token.LPAR)121 elif char == ')':122 self.__push(Token.RPAR)123 elif char == '*':124 self.__push(Token.MUL)125 elif char == '/':126 self.__push(Token.DIV)127 elif char == '+':128 self.__push(Token.ADD)129 elif char == '-':130 self.__push(Token.SUB)131 elif char == ':':132 self.__push(Token.COLON)133 elif char == '>':134 self.__push(Token.GT)135 elif char == '<':136 self.__push(Token.LT)137 elif char == '.':138 self.__push(Token.DOT)139 elif char == '@':140 self.__push(Token.AT)141 elif char == '\n':142 self.value = ""143 # self.__push(Token.NL)144 elif char.isspace():145 self.value = ""146 else:147 print("[Lexing Error] Unknown char: '" + char + "'")...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful