Пример #1
0
    def test_set_centroid1(self):
        """
        Test with rectangles of zero width or height.

        Test tag: <tc>#tests#Rectangle.set_centroid</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        r.set_centroid(Point((0, 0)))
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, -2.5)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 2.5)

        r = Rectangle(10, 5, 20, 5)  # Zero height
        r.set_centroid(Point((40, 40)))
        self.assertEquals(r.left, 35)
        self.assertEquals(r.lower, 40)
        self.assertEquals(r.right, 45)
        self.assertEquals(r.upper, 40)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_centroid(Point((-4, -4)))
        self.assertEquals(r.left, -4)
        self.assertEquals(r.lower, -4)
        self.assertEquals(r.right, -4)
        self.assertEquals(r.upper, -4)
Пример #2
0
    def test_area1(self):
        """
        Test rectangles with zero width/height

        Test tag: <tc>#tests#Rectangle.area</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        self.assertEquals(r.area, 0)

        r = Rectangle(10, 5, 20, 5)  # Zero height
        self.assertEquals(r.area, 0)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        self.assertEquals(r.area, 0)
Пример #3
0
    def test_width1(self):
        """
        Test rectangles with zero width.

        Test tag: <tc>#tests#Rectangle.width</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        self.assertEquals(r.width, 0)
Пример #4
0
    def test_height1(self):
        """
        Test rectangles with zero height.

        Test tag: <tc>#tests#Rectangle.height</tc>
        """
        r = Rectangle(10, 5, 20, 5)  # Zero height
        self.assertEquals(r.height, 0)
Пример #5
0
    def test___init__1(self):
        """
        Test exceptions are thrown correctly.

        Test tag: <tc>#tests#Rectangle.__init__</tc>
        """
        try:
            r = Rectangle(1, 1, -1, 5)  # right < left
        except ArithmeticError:
            pass
        else:
            self.fail()

        try:
            r = Rectangle(1, 1, 5, -1)  # upper < lower
        except ArithmeticError:
            pass
        else:
            self.fail()
Пример #6
0
    def test_set_scale1(self):
        """
        Test repeated scaling.

        Test tag: <tc>#tests#Rectangle.set_scale</tc>
        """
        r = Rectangle(2, 2, 4, 4)

        r.set_scale(0.5)
        self.assertEquals(r.left, 2.5)
        self.assertEquals(r.lower, 2.5)
        self.assertEquals(r.right, 3.5)
        self.assertEquals(r.upper, 3.5)

        r.set_scale(2)
        self.assertEquals(r.left, 2)
        self.assertEquals(r.lower, 2)
        self.assertEquals(r.right, 4)
        self.assertEquals(r.upper, 4)
Пример #7
0
    def test_set_scale1(self):
        """
        Test repeated scaling.

        Test tag: <tc>#tests#Rectangle.set_scale</tc>
        """
        r = Rectangle(2, 2, 4, 4)

        r.set_scale(0.5)
        self.assertEquals(r.left, 2.5)
        self.assertEquals(r.lower, 2.5)
        self.assertEquals(r.right, 3.5)
        self.assertEquals(r.upper, 3.5)

        r.set_scale(2)
        self.assertEquals(r.left, 2)
        self.assertEquals(r.lower, 2)
        self.assertEquals(r.right, 4)
        self.assertEquals(r.upper, 4)
Пример #8
0
    def test_set_scale2(self):
        """
        Test scaling of rectangles with zero width/height..

        Test tag: <tc>#tests#Rectangle.set_scale</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        r.set_scale(2)
        self.assertEquals(r.left, 5)
        self.assertEquals(r.lower, 2.5)
        self.assertEquals(r.right, 5)
        self.assertEquals(r.upper, 12.5)

        r = Rectangle(10, 5, 20, 5)  # Zero height
        r.set_scale(2)
        self.assertEquals(r.left, 5)
        self.assertEquals(r.lower, 5)
        self.assertEquals(r.right, 25)
        self.assertEquals(r.upper, 5)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_scale(100)
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, 0)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 0)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_scale(0.01)
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, 0)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 0)
Пример #9
0
    def test_set_centroid1(self):
        """
        Test with rectangles of zero width or height.

        Test tag: <tc>#tests#Rectangle.set_centroid</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        r.set_centroid(Point((0, 0)))
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, -2.5)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 2.5)

        r = Rectangle(10, 5, 20, 5)  # Zero height
        r.set_centroid(Point((40, 40)))
        self.assertEquals(r.left, 35)
        self.assertEquals(r.lower, 40)
        self.assertEquals(r.right, 45)
        self.assertEquals(r.upper, 40)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_centroid(Point((-4, -4)))
        self.assertEquals(r.left, -4)
        self.assertEquals(r.lower, -4)
        self.assertEquals(r.right, -4)
        self.assertEquals(r.upper, -4)
Пример #10
0
    def test_set_scale2(self):
        """
        Test scaling of rectangles with zero width/height..

        Test tag: <tc>#tests#Rectangle.set_scale</tc>
        """
        r = Rectangle(5, 5, 5, 10)  # Zero width
        r.set_scale(2)
        self.assertEquals(r.left, 5)
        self.assertEquals(r.lower, 2.5)
        self.assertEquals(r.right, 5)
        self.assertEquals(r.upper, 12.5)

        r = Rectangle(10, 5, 20, 5)  # Zero height
        r.set_scale(2)
        self.assertEquals(r.left, 5)
        self.assertEquals(r.lower, 5)
        self.assertEquals(r.right, 25)
        self.assertEquals(r.upper, 5)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_scale(100)
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, 0)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 0)

        r = Rectangle(0, 0, 0, 0)  # Zero width and height
        r.set_scale(0.01)
        self.assertEquals(r.left, 0)
        self.assertEquals(r.lower, 0)
        self.assertEquals(r.right, 0)
        self.assertEquals(r.upper, 0)