"""This test suite evaluates and tests behavior of the ``ImageRectangle`` class""" # Testing from unittest import TestCase # Hypothesis from hypothesis import given from hypothesis.strategies import integers # Module under test from pyrate.sense.vision.image_rectangle import ImageRectangle class TestImageRectangle(TestCase): """Tests functionality of the ``ImageRectangle`` class""" @given( integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), ) # pylint: disable=too-many-arguments def test_bottom_center(self, position_x, position_y, width, height, offset_x, offset_y): """Parametrized test that tests correct functionality of the bottom_center property Args: position_x: x position of the rectangle position_y: y position of the rectangle width: width of the rectangle height: height of the rectangle offset_x: x component of the offset offset_y: y component of the offset """ offset = (offset_x, offset_y) rectangle_without_offset = ImageRectangle((position_x, position_y, width, height)) self.assertTupleEqual(rectangle_without_offset.offset, (0, 0)) self.assertAlmostEqual(rectangle_without_offset.bottom_center[0], position_x + (width / 2), delta=0.5) self.assertAlmostEqual(rectangle_without_offset.bottom_center[1], position_y + height) rectangle_with_offset = ImageRectangle((position_x, position_y, width, height), offset=offset) self.assertTupleEqual(rectangle_with_offset.offset, offset) self.assertAlmostEqual( rectangle_with_offset.bottom_center[0], position_x + offset_x + (width / 2), delta=0.5 ) self.assertAlmostEqual(rectangle_with_offset.bottom_center[1], position_y + offset_y + height) @given( integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), integers(0, 10000), ) # pylint: disable=too-many-arguments def test_rectangle_to_corner(self, position_x, position_y, width, height, offset_x, offset_y): """Parametrized test that tests correct functionality of the rectangle_to_corner method Args: position_x: x position of the rectangle position_y: y position of the rectangle width: width of the rectangle height: height of the rectangle offset_x: x component of the offset offset_y: y component of the offset """ offset = (offset_x, offset_y) # rectangle without offset rectangle_without_offset = ImageRectangle((position_x, position_y, width, height)) self.assertTupleEqual(rectangle_without_offset.offset, (0, 0)) cornerlu, cornerrb = rectangle_without_offset.rectangle_to_corner(offset=False) self.assertTrue( cornerlu[0] == position_x and cornerlu[1] == position_y, msg=f"Left upper corner: {cornerlu}", ) self.assertTrue( cornerrb[0] == position_x + width and cornerrb[1] == position_y + height, msg=f"Right bottom corner: {cornerrb}", ) # rectangle with offset rectangle_with_offset = ImageRectangle((position_x, position_y, width, height), offset) self.assertTupleEqual(rectangle_with_offset.offset, offset) cornerlu, cornerrb = rectangle_with_offset.rectangle_to_corner(offset=True) self.assertTrue( cornerlu[0] == position_x + offset_x and cornerlu[1] == position_y + offset_y, msg=f"Left upper corner: {cornerlu}", ) self.assertTrue( cornerrb[0] == position_x + offset_x + width and cornerrb[1] == position_y + offset_y + height, msg=f"Right bottom corner: {cornerrb}", )