Best Python code snippet using hypothesis
common.py
Source:common.py  
...92        Return True if it works.93        """94        value = self.make_immutable(value)95        self.check_invariants(value)96        if not self.left_is_better(value, self.current):97            if value != self.current and (value == value):98                self.debug(99                    "Rejected %r as worse than self.current=%r" % (value, self.current)100                )101            return False102        if value in self.__seen:103            return False104        self.__seen.add(value)105        if self.__predicate(value):106            self.debug("shrinking to %r" % (value,))107            self.changes += 1108            self.current = value109            return True110        return False111    def consider(self, value):112        """Returns True if make_immutable(value) == self.current after calling113        self.incorporate(value)."""114        value = self.make_immutable(value)115        if value == self.current:116            return True117        return self.incorporate(value)118    def make_immutable(self, value):119        """Convert value into an immutable (and hashable) representation of120        itself.121        It is these immutable versions that the shrinker will work on.122        Defaults to just returning the value.123        """124        return value125    def check_invariants(self, value):126        """Make appropriate assertions about the value to ensure that it is127        valid for this shrinker.128        Does nothing by default.129        """130        raise NotImplementedError()131    def short_circuit(self):132        """Possibly attempt to do some shrinking.133        If this returns True, the ``run`` method will terminate early134        without doing any more work.135        """136        raise NotImplementedError()137    def left_is_better(self, left, right):138        """Returns True if the left is strictly simpler than the right139        according to the standards of this shrinker."""140        raise NotImplementedError()141    def run_step(self):142        """Run a single step of the main shrink loop, attempting to improve the143        current value."""...navigation.py
Source:navigation.py  
1# Concept: Just get the centre of all the bounding boxes that are present(mine, all others)2# Find the distance between mine and the other boxes from 3 positions, current, 10 pixels to the left and right.3# If the distance of position to the right or left is more than the current go there, instead stay here.4import numpy as np5#* Refactoring calc_distance to be faster6def calc_distance(rectangles:list):7    '''8    Calculates the distance of our car from other cars and borders.9    '''10    rectangles = np.array(rectangles)11    # if len(rectangles) == 1:12    #     mine = rectangles[np.where((rectangles[:,2] == 32) * (rectangles[:,3] == 45))][:, 0:2]13    #     if mine[:,0] < 150:14    #         return (0,0,1)15    #     else:16    #         return (0,1,0)17        # center_dist = np.sum((mine - [150, int(mine[:,1])])**2, axis=1)18        # return (0,0,0)19    try:20        mine = rectangles[np.where((rectangles[:,2] == 32) * (rectangles[:,3] == 45))][:, 0:2]21        mine_right = mine + [10,0]22        mine_left = mine - [10,0]23        points = rectangles[:,0:2]24        weights = rectangles[:,-1]25        dists = np.dot(weights, np.sum((points - mine)** 2, axis=1))26        dists_right = np.dot(weights, np.sum((points - mine_right)** 2, axis=1))27        dists_left = np.dot(weights, np.sum((points - mine_left)** 2, axis=1))28        center_dist = np.sum((mine - [150, int(mine[:,1])])**2, axis=1)29        if mine[:,0] < 150:30            dists_right += center_dist31        else:32            dists_left += center_dist33        if len(rectangles) == 1:34            return (dists, dists_left, dists_right)35        # print('distance without center_dist', (dists, dists_left, dists_right))36        # dists = dists - int(center_dist)*537        # dists_left = dists_left - int(center_dist)*538        # dists_right = dists_right - int(center_dist)*539        # print('distance with center_dist', (dists, dists_left, dists_right))40        return (dists, dists_left, dists_right)41    except:42        pass43def navigate(distances:tuple):44    '''45    Makes a decision based on the distance calculated in calc_distance function46    '''47    try:48        dist_curr, dist_left, dist_right = distances[0], distances[1], distances[2]49        right_is_better = False50        left_is_better = False51        if dist_right > dist_curr:52            right_is_better = True53        elif dist_left > dist_curr:54            left_is_better = True55        if right_is_better:56            return 157        elif left_is_better:58            return -159        else:60            return 061    except:...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!!
