How to use inverted_test method in hypothesis

Best Python code snippet using hypothesis

trench.py

Source:trench.py Github

copy

Full Screen

1with open('data.txt', 'r') as file:2 data = file.read().split('\n')3# cut trailing newline4data.pop(-1)5# Further data processing6algorithm_line = data.pop(0)7# discard the blank line8data.pop(0)9lit_pixels = set()10for row, row_data in enumerate(data):11 for col, col_data in enumerate(row_data):12 if col_data == '#':13 lit_pixels.add((row, col))14# breakpoint()15# Part 116def enhance(lit_pixels, algorithm_line, steps):17 inverted = False18 tracked_pixels = lit_pixels19 for _ in range(steps):20 new_tracked_pixels = set()21 neighbor_pixels = set()22 # add unlit pixels neighboring neighbor pixels to set to evaluate23 # this might be a problem for the real algorithm, looks like 0 = lit24 # can solve by flipping it every other time25 for tracked_pixel in tracked_pixels:26 for i in range (-1, 2, 1):27 for k in range(-1, 2, 1):28 # breakpoint()29 row_i = tracked_pixel[0] + i30 col_k = tracked_pixel[1] + k31 if (row_i, col_k) not in tracked_pixels:32 neighbor_pixels.add((row_i, col_k))33 tracked_symbol = "." if not inverted else "#"34 # If inverted, we are tracking dark pixels because of algo[0] = On35 for tracked_pixel in tracked_pixels:36 # Find the correct number, regardless of inversion37 number = get_pixel_number(tracked_pixel, tracked_pixels, inverted)38 enhanced_pixel = algorithm_line[number]39 if enhanced_pixel == tracked_symbol:40 new_tracked_pixels.add(tracked_pixel)41 for neighbor_pixel in neighbor_pixels:42 number = get_pixel_number(neighbor_pixel, tracked_pixels, inverted)43 enhanced_pixel = algorithm_line[number]44 if enhanced_pixel == tracked_symbol:45 new_tracked_pixels.add(neighbor_pixel)46 tracked_pixels = new_tracked_pixels47 print(len(tracked_pixels))48 inverted = not inverted49 # print(tracked_pixels)50 return len(tracked_pixels)51def get_pixel_number(pixel, tracked_pixels, inverted):52 neighbors = []53 for i in range (-1, 2, 1):54 for k in range(-1, 2, 1):55 # breakpoint()56 row_i = pixel[0] + i57 col_k = pixel[1] + k58 # TODO: DRY59 if not inverted:60 if (row_i, col_k) in tracked_pixels:61 neighbors.append('1')62 else:63 neighbors.append('0')64 else:65 if (row_i, col_k) in tracked_pixels:66 neighbors.append('0')67 else:68 neighbors.append('1')69 # breakpoint()70 return int("".join(neighbors), 2)71normal_test = set([(1, 0), (2, 1)])72inverted_test = set([(0, 0),73 (0, 1),74 (0, 2),75 (1, 1),76 (1, 2),77 (2, 0),78 (2, 2)]79)80# print(get_pixel_number((1, 1), normal_test, False))81# print(get_pixel_number((1, 1), inverted_test, True))82# print(get_pixel_number((2, 2), lit_pixels))83print(f"Result: {enhance(lit_pixels, algorithm_line, 50)}")84# incorrect = {(3, -1), (3, 1), (5, 4), (5, 1), (0, 5), (2, 2), (1, 6), (1, 3), (6, 2), (-1, -2), (-1, 4), (-2, 4), (-2, -1), (-2, 1), (4, 2), (4, 5), (3, 3), (3, 6), (5, 3), (0, -2), (2, -1), (2, -2), (1, 2), (2, 4), (-2, 5), (6, 4), (-2, 2), (5, 2), (4, 4), (0, 0), (0, 3), (0, 6), (6, 3), (-1, 5)}85# correct = {(4, 0), (3, -1), (3, 4), (4, 3), (3, 1), (5, 4), (4, 6), (5, 1), (0, 5), (1, 3), (6, 2), (-1, -1), (-1, 4), (4, 2), (4, 5), (3, 3), (0, -2), (2, -2), (2, 4), (1, 2), (0, 4), (1, 5), (6, 4), (3, 2), (-1, 2), (3, 5), (5, 2), (4, 4), (5, 5), (0, 0), (1, -2), (0, 6), (2, 6), (6, 3), (-2, 5)}86# for pair in correct:87# if pair not in incorrect:...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...44 return45def fails_with(e):46 def accepts(f):47 @proxies(f)48 def inverted_test(*arguments, **kwargs):49 with raises(e):50 f(*arguments, **kwargs)51 return inverted_test52 return accepts...

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