Best Python code snippet using hypothesis
storage.py
Source:storage.py
...21 ===========22 * num_bits (:obj:`int`): Number of bits needed.23 """24 self._bits = array.array('L')25 self.__check_capacity(num_bits >> 5)26 def get(self, index):27 """ Get the value of the bit at position `index`. """28 self.__check_capacity(index >> 5)29 return (self._bits[index >> 5] & (1 << (index & 0x1F))) != 030 def set(self, index):31 """ Set the value of the bit at position `index`. """32 self.__check_capacity(index >> 5)33 self._bits[index >> 5] |= 1 << (index & 0x1F)34 def set_all(self):35 """ Set all the bits within this array. """36 for i in xrange(len(self._bits)):37 self._bits[i] = BitArray.MAX_VALUE38 def clear(self, index):39 """ Clear the bit at position `index`. """40 self.__check_capacity(index >> 5)41 self._bits[index >> 5] &= ~(1 << (index & 0x1F))42 def clear_all(self):43 """ Clear all the bits in this array. """44 for i in xrange(len(self._bits)):45 self._bits[i] = 0L46 def toggle(self, index):47 """ Toggle the bit at position `index`. """48 self._bits[index >> 5] ^= 1 << (index & 0x1F)49 def __check_capacity(self, size):50 """ Check if the array contains enough elements (size) to provide the51 desired number of bits. """52 if (size >= len(self._bits)):53 self._bits.extend((0L,)*(size + 1 - len(self._bits)))54 def __str__(self):55 out = []56 for i in xrange(len(self._bits)*BitArray.BITS_PER):57 out.append("{:b}".format(self.get(i)))58 return "".join(out)59class Bag(object):60 """ The Bag class is a data container. """61 def __init__(self, type_, size=64):62 """ Constructor. 63 Parameters:...
dynamic_array.py
Source:dynamic_array.py
...19 raise IndexError("Can't pop from an empty list!")20 val = self.store[self.length - 1]21 self.store[self.length-1] = None22 self.length -= 123 self.__check_capacity()24 return val25 def append(self, val):26 self.__check_capacity()27 self.store[self.length] = val28 self.length += 129 def shift(self):30 val = self.store[0]31 for i in range(1, self.length):32 self.store[i - 1] = self.store[i]33 self.store[self.length - 1] = None34 self.length -= 135 self.__check_capacity()36 return val37 def unshift(self, val):38 self.__check_capacity()39 i = self.length40 while i > 0:41 self.store[i] = self.store[i-1]42 i -= 143 self.store[0] = val44 self.length += 145 def __check_index(self, index):46 if 0 > index > self.length:47 raise IndexError("Index out of range!")48 def __check_capacity(self):49 if self.length <= (self.capacity // 2) and self.capacity > 8:50 self.__resize(False)51 if self.length == self.capacity:52 self.__resize()53 def __resize(self, up=True):54 if up:55 new_capacity = self.capacity * 256 else:57 new_capacity = self.capacity // 258 new_store = StaticArray(new_capacity)59 for i in range(self.length):60 new_store[i] = self.store[i]...
ring_buffer.py
Source:ring_buffer.py
...21 raise IndexError("Can't pop from an empty list!")22 val = self[self.length - 1]23 self[self.length-1] = None24 self.length -= 125 self.__check_capacity()26 return val27 def append(self, val):28 self.__check_capacity()29 self[self.length] = val30 self.length += 131 def shift(self):32 val, self[0] = self[0], None33 self.start = (self.start + 1) % self.capacity34 self.length -= 135 self.__check_capacity()36 return val37 def unshift(self, val):38 self.__check_capacity()39 self.start = (self.start - 1) % self.capacity40 self[0] = val41 self.length += 142 def __check_index(self, index):43 if 0 > index > self.length:44 raise IndexError("Index out of range!")45 def __check_capacity(self):46 if self.length <= (self.capacity // 2) and self.capacity > 8:47 self.__resize(False)48 if self.length == self.capacity:49 self.__resize()50 def __resize(self, up=True):51 if up:52 new_capacity = self.capacity * 253 else:54 new_capacity = self.capacity // 255 new_store = StaticArray(new_capacity)56 for i in range(self.length):57 new_store[i] = self[i]...
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!!