Ejemplo n.º 1
0
 def when_imager_is_constructed(self):
     self.imager = ImageSensor(
         unit=self.unit,
         width=self.width,
         height=self.height,
         central_view=self.central_view,
         horizontal_direction=self.horizontal_direction,
         vertical_direction=self.vertical_direction,
         placement=self.central_view)
Ejemplo n.º 2
0
class TestImageSensor(unittest.TestCase):
    """
    Test ImageSensor class
    """

    def clean_state(self):
        self.imager = None
        self.width = None
        self.height = None
        self.area = None
        self.unit = None

    def setUp(self):
        self.clean_state()
        self.width = 8.0
        self.height = 6.0
        self.area = self.width * self.height
        self.unit = "smidgen"
        self.facing_direction = Direction.up
        self.horizontal_direction = Direction.right
        self.vertical_direction = Direction.forward
        self.position = Position.from_xyz((10.0, 20.0, 30))
        self.central_view = Ray(self.position, self.facing_direction)
        self.location_expectations = {
            (0.0, 0.0): (10.0, 20.0, 30.0),
            (1.0, 0.0): (14.0, 20.0, 30.0),
            (-1.0, 0.0): (6.0, 20.0, 30.0),
            (0.0, 1.0): (10.0, 23.0, 30.0),
            (0.0, -1.0): (10.0, 17.0, 30.0),
            (1.0, 1.0): (14.0, 23.0, 30.0),
            (1.0, -1.0): (14.0, 17.0, 30.0),
            (-1.0, 1.0): (6.0, 23.0, 30.0),
            (-1.0, -1.0): (6.0, 17.0, 30.0),
        }

    def tearDown(self):
        self.clean_state()

    def test_normal_image_sensor_construction(self):
        self.when_imager_is_constructed()
        self.then_imager_has_correct_dimensions()

    def when_imager_is_constructed(self):
        self.imager = ImageSensor(
            unit=self.unit,
            width=self.width,
            height=self.height,
            central_view=self.central_view,
            horizontal_direction=self.horizontal_direction,
            vertical_direction=self.vertical_direction,
            placement=self.central_view
        )

    def then_imager_has_correct_dimensions(self):
        self.assertEqual(self.width, self.imager.width)
        self.assertEqual(self.height, self.imager.height)
        self.assertEqual(self.area, self.imager.area)
        self.assertEqual(self.unit, self.imager.unit_of_distance)

    def test_imager_viewing_positions(self):
        self.when_imager_is_constructed()
        self.then_imager_correct_has_view_locations()

    def then_imager_correct_has_view_locations(self):
        for self.image_location, self.expected_sensor_location in self.location_expectations.items():
            self.then_sensor_has_correct_location()

    def then_sensor_has_correct_location(self):
        actual_location_ray = self.imager.view_at_location(self.image_location)
        actual_location_direction = actual_location_ray.direction
        self.assertTupleEqual(self.facing_direction.xyz, actual_location_direction.xyz)
        actual_positon = actual_location_ray.position
        self.assertTupleEqual(self.expected_sensor_location, actual_positon.xyz)