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:...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!