def test_rectangle_big_number(): top_left = [1, 2] bottom_right = [5, 4] number = 20 nails = generate_rectangle_nail_list(top_left, bottom_right, number) expected_nails = [[1, 2], [1, 3], [1, 4], [2, 4], [3, 4], [4, 4], [5, 4], [5, 3], [5, 2], [4, 2], [3, 2], [2, 2]] assert nails == expected_nails
def test_square(): top_left = [0, 0] bottom_right = [3, 3] number = 2 nails = generate_rectangle_nail_list(top_left, bottom_right, number) expected_nails = [[0, 0], [0, 2], [0, 3], [2, 3], [3, 3], [3, 2], [3, 0], [2, 0]] assert nails == expected_nails
def test_update_thread_substraction_perfect_match(): thread = 100 * np.ones(shape=(5, 5)) nails = generate_rectangle_nail_list([0, 0], [4, 4], 4) target = np.array([[100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100]]) current_nail = [0, 2] distances = [] next_nail, next_thread = update_thread_substraction( nails, current_nail, target, thread, 50, distances) assert next_nail == [4, 2] np.testing.assert_array_equal( next_thread, [[100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100], [100, 100, 50, 100, 100]])
def test_update_thread_multiply_low_match(): thread = 100 * np.ones(shape=(5, 5)) nails = generate_rectangle_nail_list([0, 0], [4, 4], 4) target = np.array([[100, 100, 80, 100, 100], [100, 100, 90, 50, 100], [100, 100, 90, 50, 100], [100, 100, 90, 100, 50], [100, 100, 90, 100, 100]]) current_nail = [0, 2] distances = [] next_nail, next_thread = update_thread_multiply(nails, current_nail, target, thread, 0.5, distances) assert next_nail == [3, 4] np.testing.assert_array_equal( next_thread, [[100, 100, 50, 100, 100], [100, 100, 100, 50, 100], [100, 100, 100, 50, 100], [100, 100, 100, 100, 50], [100, 100, 100, 100, 100]])
def test_update_thread_substraction_for_loop(): thread = 100 * np.ones(shape=(5, 5)) nails = generate_rectangle_nail_list([0, 0], [4, 4], 4) target = np.array([[100, 100, 80, 100, 100], [100, 100, 90, 50, 100], [100, 100, 90, 50, 100], [100, 100, 90, 100, 50], [100, 100, 90, 100, 100]]) init_distance = distance_image(thread, target) current_nail = [0, 2] distances = [] for i in range(100): if current_nail is None: print(f'breaking at {i}') break current_nail, thread = update_thread_substraction( nails, current_nail, target, thread, 1, distances) new_distance = distance_image(thread, target) print(f'init_distance substraction : {init_distance}') print(f'new_distance substraction : {new_distance}') print(thread) assert new_distance < init_distance