Beispiel #1
0
 def test_position(self):
     translatable = Translatable()
     assert translatable.position() == (0, 0)
     translatable = Translatable((-4, 5))
     assert translatable.position() == (-4, 5)
     translatable.set_position((16, -1))
     assert translatable.position() == (16, -1)
Beispiel #2
0
 def test_position(self):
     translatable = Translatable()
     assert translatable.position() == (0, 0)
     translatable = Translatable((-4, 5))
     assert translatable.position() == (-4, 5)
     translatable.set_position((16, -1))
     assert translatable.position() == (16, -1)
Beispiel #3
0
 def test_run(self):
     background = Background((7, 3))
     polygon = TestUtils.generate_test_polygon(seed=0,
                                               points=12,
                                               radius_range=(1, 10))
     polygon_copy = copy.deepcopy(polygon)
     objects = [background, polygon, Translatable()]
     self.__backend.draw_objects = MagicMock()
     self.__backend.create_canvas = MagicMock()
     self.__backend.export_to_file = MagicMock()
     self.__backend.run(objects, "testname")
     self.__backend.draw_objects.assert_called(objects)
     self.__backend.create_canvas.assert_called(objects)
     self.__backend.export_to_file.assert_called_with("testname")
     assert TestUtils.unordered_lists_equal(
         self.__backend.draw_objects.call_args[0][0], objects)
Beispiel #4
0
    def test_apply_transform(self):
        translatable = Translatable((10, 20))
        angle = 145
        rotatable = Rotatable(angle)
        self.__backend.create_canvas()

        self.__backend.push_surface()
        self.__backend.apply_transform(translatable)
        matrix = self.__backend.ctx().get_matrix()
        assert matrix[4] == 10
        assert matrix[5] == 20
        self.__backend.pop_surface()

        self.__backend.push_surface()
        self.__backend.apply_transform(rotatable)
        matrix = self.__backend.ctx().get_matrix()
        c = math.cos(math.radians(angle))
        s = math.sin(math.radians(angle))
        assert sum(map(operator.sub, matrix, (c, s, -1 * s, c, 0, 0))) == 0
        self.__backend.pop_surface()
Beispiel #5
0
 def test_scale(self):
     translatable = Translatable((2, -3))
     assert translatable.position() == (2, -3)
     translatable.scale((5.5, 2.3))
     assert translatable.position() == (2 * 5.5, -3 * 2.3)
Beispiel #6
0
 def test_init(self):
     translatable = Translatable()
     assert translatable != None
Beispiel #7
0
 def test_scale(self):
     translatable = Translatable((2, -3))
     assert translatable.position() == (2, -3)
     translatable.scale((5.5, 2.3))
     assert translatable.position() == (2 * 5.5, -3 * 2.3)