dysin = dy * math.sin(angle) center = np.array(center) return [ center + np.array([-dxcos + dysin, -dxsin - dycos]), center + np.array([dxcos + dysin, dxsin - dycos]), center + np.array([dxcos - dysin, dxsin + dycos]), center + np.array([-dxcos - dysin, -dxsin + dycos]), ] @given( length_a=h_int(min_value=1, max_value=100), width_a=h_int(min_value=1, max_value=100), center_ax=h_float(min_value=-100, max_value=100), center_ay=h_float(min_value=-100, max_value=100), length_b=h_int(min_value=1, max_value=100), width_b=h_int(min_value=1, max_value=100), center_bx=h_float(min_value=-100, max_value=100), center_by=h_float(min_value=-100, max_value=100), ) def test_vs_shapely_zero_angle(length_a, width_a, center_ax, center_ay, length_b, width_b, center_bx, center_by): rectangle_a = to_coords((center_ax, center_ay), length_a, width_a, 0) rectangle_b = to_coords((center_bx, center_by), length_b, width_b, 0) rectangle_a_shapely = Polygon(rectangle_a + [rectangle_a[0]]) rectangle_b_shapely = Polygon(rectangle_b + [rectangle_b[0]]) assert math.isclose(
def test_fix_center(position, width): new_position = fix_center(position, IMAGE_WIDTH, width=width) if width < IMAGE_WIDTH: assert math.ceil(width / 2) <= new_position < IMAGE_WIDTH - math.floor(width / 2) + 1 if width > IMAGE_WIDTH: assert new_position == math.ceil(IMAGE_WIDTH / 2) @given( x_min=h_int(min_value=0, max_value=int(IMAGE_WIDTH * 3 / 4) - 1), y_min=h_int(min_value=0, max_value=int(IMAGE_HEIGHT * 5 / 6) - 1), x_max=h_int(min_value=int(IMAGE_WIDTH * 3 / 4), max_value=IMAGE_WIDTH - 1), y_max=h_int(min_value=int(IMAGE_HEIGHT * 5 / 6), max_value=IMAGE_HEIGHT - 1), resize_coeff=h_float(min_value=1, max_value=10), ) def test_resize(x_min, y_min, x_max, y_max, resize_coeff): x_min_1, y_min_1, x_max_1, y_max_1 = resize( x_min, y_min, x_max, y_max, image_height=IMAGE_HEIGHT, image_width=IMAGE_WIDTH, resize_coeff=resize_coeff ) assert 0 <= x_min_1 < x_max_1 < IMAGE_WIDTH assert 0 <= y_min_1 < y_max_1 < IMAGE_HEIGHT new_width = min(math.floor(resize_coeff * (x_max - x_min)), IMAGE_WIDTH) if new_width < IMAGE_WIDTH: assert x_max_1 - x_min_1 == new_width else: assert x_min_1 == 0
from hypothesis.strategies import characters as h_char from hypothesis.strategies import floats as h_float from help_functions.utils.tabular_utils import ( CyclicEncoder, LabelEncoderUnseen, GeneralEncoder, ) MIN_VALUE = -11 MAX_VALUE = 17 ARRAY_SHAPE = 3 @given( x=h_arrays(dtype=float, shape=ARRAY_SHAPE, elements=h_float(-MIN_VALUE, MAX_VALUE)) ) def test_cyclic_day_hours(x): amplitude = MAX_VALUE - MIN_VALUE encoder = CyclicEncoder(amplitude) transformed = encoder.fit_transform(x) assert transformed.shape[1] == 2 encoder2 = CyclicEncoder(amplitude) encoder2.fit(x) transformed2 = encoder2.transform(x) assert transformed2.shape[1] == 2
from iglovikov_helper_functions.utils.tabular_utils import ( CyclicEncoder, GeneralEncoder, LabelEncoderUnseen, MinMaxScaler, ) MIN_VALUE = -11 MAX_VALUE = 17 ARRAY_SHAPE = 3 @given(x=h_arrays(dtype=float, shape=ARRAY_SHAPE, elements=h_float(-MIN_VALUE, MAX_VALUE))) def test_cyclic_day_hours(x): amplitude = MAX_VALUE - MIN_VALUE encoder = CyclicEncoder(amplitude) transformed = encoder.fit_transform(x) assert transformed.shape == (len(x), 2) encoder2 = CyclicEncoder(amplitude) encoder2.fit(x) transformed2 = encoder2.transform(x) assert transformed.shape == (len(x), 2)