コード例 #1
0
        public void WidthTest()
        {
            // Create a basic 1000x1000 square.
            Point size = new Point(1000, 1000);

            // Adjust the width.
            Assert.IsTrue(AspectRatioHelpers.AdjustWidth(ref size, ratio, 2f), "Width was not adjusted.");

            // Ensure the width is correct.
            Assert.AreEqual(1778, size.X, "Adjusted width was incorrect.");
        }
コード例 #2
0
        public void DeviationTest()
        {
            // Ensure that it cannot be adjusted with a ratio of 0.5, as no changes can be made.
            Point size = new Point(1000, 2000);

            Assert.IsFalse(AspectRatioHelpers.AdjustHeight(ref size, 0.5f, 3f), "Height was adjusted when it did not need to be.");
            size = new Point(1000, 2000);
            Assert.IsFalse(AspectRatioHelpers.AdjustWidth(ref size, 0.5f, 3f), "Width was adjusted when it did not need to be.");

            // Ensure it cannot be adjusted again, but with the deviation taken into account.
            size = new Point(1000, 2003);
            Assert.IsFalse(AspectRatioHelpers.AdjustHeight(ref size, 0.5f, 3f), "Height was adjusted when it did not need to be.");
            size = new Point(1003, 2000);
            Assert.IsFalse(AspectRatioHelpers.AdjustWidth(ref size, 0.5f, 3f), "Width was adjusted when it did not need to be.");

            // Ensure it adjusts when it's just out of the deviation zone.
            size = new Point(1000, 2003);
            Assert.IsTrue(AspectRatioHelpers.AdjustHeight(ref size, 0.5f, 2f), "Height was not adjusted when it needed to be.");
            size = new Point(1003, 2000);
            Assert.IsTrue(AspectRatioHelpers.AdjustWidth(ref size, 0.5f, 2f), "Width was not adjusted when it needed to be.");
        }