Ejemplo n.º 1
0
        public void TestConstructors()
        {
            // Test that all constructors work the same
            MRectangleInt a = new MRectangleInt(-5, -5);
            MRectangleInt b = new MRectangleInt(new MPoint2(0, 0), new MPoint2(-5, -5));
            MRectangleInt c = new MRectangleInt(0, 0, -5, -5);
            MRectangleInt d = new MRectangleInt(new MPoint2(-5, -5));

            Assert.AreEqual(a, b);
            Assert.AreEqual(b, c);
            Assert.AreEqual(c, d);

            // Test negative size
            Assert.AreEqual(new MRectangleInt(0, 0, 10, 10), new MRectangleInt(10, 10, -10, -10));
            Assert.AreEqual(new MRectangleInt(-10, -10, 10, 10), new MRectangleInt(0, 0, -10, -10));
            Assert.AreEqual(new MRectangleInt(-30, -30, 20, 20), new MRectangleInt(-10, -10, -20, -20));
        }
Ejemplo n.º 2
0
        public void TestWidthHeight()
        {
            for (int i = 0; i < IntAreaTest.RANDOM_TEST_AMOUNT; i++)
            {
                int x = random.Next(-100, 100);
                int y = random.Next(-100, 100);
                int x2 = random.Next(-100, 100);
                int y2 = random.Next(-100, 100);

                MRectangleInt a = new MRectangleInt(x, y, x2 - x, y2 - y);
                Assert.AreEqual(Math.Abs(y2 - y), a.Height);
                Assert.AreEqual(Math.Abs(x2 - x), a.Width);
            }
        }
Ejemplo n.º 3
0
        public void TestTranslate()
        {
            for (int i = 0; i < IntAreaTest.RANDOM_TEST_AMOUNT; i++)
            {
                int x = random.Next(-100, 100);
                int y = random.Next(-100, 100);
                int w = random.Next(0, 100);
                int h = random.Next(0, 100);

                int tx = random.Next(-100, 100);
                int ty = random.Next(-100, 100);

                MRectangleInt a = new MRectangleInt(x, y, w, h);
                Assert.AreEqual(new MRectangleInt(x + tx, y + ty, w, h), a.Translate(new MPoint2(tx, ty)));

                // Assert X Y methods
                Assert.AreEqual(a.Translate(new MPoint2(tx, 0)), a.TranslateX(tx));
                Assert.AreEqual(a.Translate(new MPoint2(0, ty)), a.TranslateY(ty));
            }
        }