From 6035e4884323f82ebd14e034cf2c77f97ecd2b4f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 8 Mar 2021 00:48:27 +0100 Subject: [PATCH] Fixed unit tests for Point/Rect/Size extensions --- .../Extensions/Test_PointExtensions.cs | 40 +++++++++---------- .../Extensions/Test_RectExtensions.cs | 9 +++-- .../Extensions/Test_SizeExtensions.cs | 36 ++++++++--------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/UnitTests/UnitTests.UWP/Extensions/Test_PointExtensions.cs b/UnitTests/UnitTests.UWP/Extensions/Test_PointExtensions.cs index 122061fb422..c5808d2b838 100644 --- a/UnitTests/UnitTests.UWP/Extensions/Test_PointExtensions.cs +++ b/UnitTests/UnitTests.UWP/Extensions/Test_PointExtensions.cs @@ -13,51 +13,51 @@ public class Test_PointExtensions { [TestCategory("PointExtensions")] [TestMethod] - [DataRow(0d, 0d, 0, 0)] - [DataRow(0d, 0d, 22, 6.89d)] + [DataRow(0d, 0d, 0d, 0d)] + [DataRow(0d, 0d, 22d, 6.89d)] [DataRow(3.14d, 6.55f, 3838d, 3.24724928d)] - [DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)] - public static void Test_PointExtensions_ToRect_FromWidthHeight(double width, double height, int x, int y) + [DataRow(double.MaxValue / 2, double.Epsilon, 22d, 0.3248d)] + public void Test_PointExtensions_ToRect_FromWidthHeight(double width, double height, double x, double y) { - Point p = new Point(x, y); + Point p = new(x, y); Rect a = p.ToRect(width, height), - b = new Rect(x, y, width, height); + b = new(x, y, width, height); Assert.AreEqual(a, b); } [TestCategory("SizeExtensions")] [TestMethod] - [DataRow(0d, 0d, 0, 0)] - [DataRow(0d, 0d, 22, 6.89d)] + [DataRow(0d, 0d, 0d, 0d)] + [DataRow(0d, 0d, 22d, 6.89d)] [DataRow(3.14d, 6.55f, 3838d, 3.24724928d)] - [DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)] - public static void Test_PointExtensions_ToRect_FromPoint(double width, double height, int x, int y) + [DataRow(double.MaxValue / 2, double.Epsilon, 22, 0.3248d)] + public void Test_PointExtensions_ToRect_FromPoint(double width, double height, double x, double y) { Point - p1 = new Point(x, y), - p2 = new Point(x + width, y + height); + p1 = new(x, y), + p2 = new(x + width, y + height); Rect a = p1.ToRect(p2), - b = new Rect(p1, p2); + b = new(p1, p2); Assert.AreEqual(a, b); } [TestCategory("SizeExtensions")] [TestMethod] - [DataRow(0d, 0d, 0, 0)] - [DataRow(0d, 0d, 22, 6.89d)] + [DataRow(0d, 0d, 0d, 0d)] + [DataRow(0d, 0d, 22d, 6.89d)] [DataRow(3.14d, 6.55f, 3838d, 3.24724928d)] - [DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)] - public static void Test_PointExtensions_ToRect_FromSize(double width, double height, int x, int y) + [DataRow(double.MaxValue / 2, double.Epsilon, 22, 0.3248d)] + public void Test_PointExtensions_ToRect_FromSize(double width, double height, double x, double y) { - Point p = new Point(x, y); - Size s = new Size(width, height); + Point p = new(x, y); + Size s = new(width, height); Rect a = p.ToRect(s), - b = new Rect(p, s); + b = new(p, s); Assert.AreEqual(a, b); } diff --git a/UnitTests/UnitTests.UWP/Extensions/Test_RectExtensions.cs b/UnitTests/UnitTests.UWP/Extensions/Test_RectExtensions.cs index 3eb0544e7bc..7c2ebf0f650 100644 --- a/UnitTests/UnitTests.UWP/Extensions/Test_RectExtensions.cs +++ b/UnitTests/UnitTests.UWP/Extensions/Test_RectExtensions.cs @@ -26,14 +26,15 @@ public class Test_RectExtensions [DataRow(0, 0, 2, 2, -2, 2, 2, 2, true)]// Left bottom corner(0, 2) intersection. [DataRow(0, 0, 2, 2, 3, 0, 2, 2, false)]// No intersection. [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1117:Parameters should be on same line or separate lines", Justification = "Put the parameters of the same rectangle on the same line is clearer.")] - public static void Test_RectExtensions_IntersectsWith( + public void Test_RectExtensions_IntersectsWith( double rect1X, double rect1Y, double rect1Width, double rect1Height, double rect2X, double rect2Y, double rect2Width, double rect2Height, bool shouldIntersectsWith) { - var rect1 = new Rect(rect1X, rect1Y, rect1Width, rect1Height); - var rect2 = new Rect(rect2X, rect2Y, rect2Width, rect2Height); - var isIntersectsWith = rect1.IntersectsWith(rect2); + Rect rect1 = new(rect1X, rect1Y, rect1Width, rect1Height); + Rect rect2 = new(rect2X, rect2Y, rect2Width, rect2Height); + bool isIntersectsWith = rect1.IntersectsWith(rect2); + Assert.IsTrue(isIntersectsWith == shouldIntersectsWith); } } diff --git a/UnitTests/UnitTests.UWP/Extensions/Test_SizeExtensions.cs b/UnitTests/UnitTests.UWP/Extensions/Test_SizeExtensions.cs index 510695ef21d..3cfbd0c062a 100644 --- a/UnitTests/UnitTests.UWP/Extensions/Test_SizeExtensions.cs +++ b/UnitTests/UnitTests.UWP/Extensions/Test_SizeExtensions.cs @@ -14,47 +14,47 @@ public class Test_SizeExtensions [TestCategory("SizeExtensions")] [TestMethod] [DataRow(0d, 0d)] - [DataRow(3.14d, 6.55f)] - [DataRow(double.MinValue, double.Epsilon)] - public static void Test_SizeExtensions_ToRect_FromSize(double width, double height) + [DataRow(3.14d, 6.55d)] + [DataRow(double.MaxValue / 2, double.Epsilon)] + public void Test_SizeExtensions_ToRect_FromSize(double width, double height) { - Size s = new Size(width, height); + Size s = new(width, height); Rect a = s.ToRect(), - b = new Rect(0, 0, s.Width, s.Height); + b = new(0, 0, s.Width, s.Height); Assert.AreEqual(a, b); } [TestCategory("SizeExtensions")] [TestMethod] - [DataRow(0d, 0d, 0, 0)] - [DataRow(0d, 0d, 22, 6.89d)] + [DataRow(0d, 0d, 0d, 0d)] + [DataRow(0d, 0d, 22d, 6.89d)] [DataRow(3.14d, 6.55f, 3838d, 3.24724928d)] - [DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)] - public static void Test_SizeExtensions_ToRect_FromSizeAndPosition(double width, double height, int x, int y) + [DataRow(double.MaxValue / 2, double.Epsilon, 22, 0.3248d)] + public void Test_SizeExtensions_ToRect_FromSizeAndPosition(double width, double height, double x, double y) { - Size s = new Size(width, height); + Size s = new(width, height); Rect a = s.ToRect(x, y), - b = new Rect(x, y, s.Width, s.Height); + b = new(x, y, s.Width, s.Height); Assert.AreEqual(a, b); } [TestCategory("SizeExtensions")] [TestMethod] - [DataRow(0d, 0d, 0, 0)] - [DataRow(0d, 0d, 22, 6.89d)] + [DataRow(0d, 0d, 0d, 0d)] + [DataRow(0d, 0d, 22d, 6.89d)] [DataRow(3.14d, 6.55f, 3838d, 3.24724928d)] - [DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)] - public static void Test_SizeExtensions_ToRect_FromSizeAndPoint(double width, double height, int x, int y) + [DataRow(double.MaxValue / 2, double.Epsilon, 22d, 0.3248d)] + public void Test_SizeExtensions_ToRect_FromSizeAndPoint(double width, double height, double x, double y) { - Point p = new Point(x, y); - Size s = new Size(width, height); + Point p = new(x, y); + Size s = new(width, height); Rect a = s.ToRect(p), - b = new Rect(p, s); + b = new(p, s); Assert.AreEqual(a, b); }