Skip to content

Commit fbaad65

Browse files
committed
Added tests for size extensions
1 parent ae61cf0 commit fbaad65

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Windows.Foundation;
6+
using Microsoft.Toolkit.Uwp.Extensions;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
9+
namespace UnitTests.Extensions
10+
{
11+
[TestClass]
12+
public class Test_SizeExtensions
13+
{
14+
[TestCategory("SizeExtensions")]
15+
[TestMethod]
16+
[DataRow(0d, 0d)]
17+
[DataRow(3.14d, 6.55f)]
18+
[DataRow(double.MinValue, double.Epsilon)]
19+
public static void Test_SizeExtensions_ToRect_FromSize(double width, double height)
20+
{
21+
Size s = new Size(width, height);
22+
Rect
23+
a = s.ToRect(),
24+
b = new Rect(0, 0, s.Width, s.Height);
25+
26+
Assert.AreEqual(a, b);
27+
}
28+
29+
[TestCategory("SizeExtensions")]
30+
[TestMethod]
31+
[DataRow(0d, 0d, 0, 0)]
32+
[DataRow(0d, 0d, 22, 6.89d)]
33+
[DataRow(3.14d, 6.55f, 3838d, 3.24724928d)]
34+
[DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)]
35+
public static void Test_SizeExtensions_ToRect_FromSizeAndPosition(double width, double height, int x, int y)
36+
{
37+
Size s = new Size(width, height);
38+
Rect
39+
a = s.ToRect(x, y),
40+
b = new Rect(x, y, s.Width, s.Height);
41+
42+
Assert.AreEqual(a, b);
43+
}
44+
45+
[TestCategory("SizeExtensions")]
46+
[TestMethod]
47+
[DataRow(0d, 0d, 0, 0)]
48+
[DataRow(0d, 0d, 22, 6.89d)]
49+
[DataRow(3.14d, 6.55f, 3838d, 3.24724928d)]
50+
[DataRow(double.MinValue, double.Epsilon, 22, 0.3248d)]
51+
public static void Test_SizeExtensions_ToRect_FromSizeAndPoint(double width, double height, int x, int y)
52+
{
53+
Point p = new Point(x, y);
54+
Size s = new Size(width, height);
55+
Rect
56+
a = s.ToRect(p),
57+
b = new Rect(p, s);
58+
59+
Assert.AreEqual(a, b);
60+
}
61+
}
62+
}

UnitTests/UnitTests.UWP/UnitTests.UWP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
<Compile Include="Converters\Test_StringFormatConverter.cs" />
139139
<Compile Include="Converters\Test_TypeToObjectConverter.cs" />
140140
<Compile Include="Extensions\Helpers\ObjectWithNullableBoolProperty.cs" />
141+
<Compile Include="Extensions\Test_SizeExtensions.cs" />
141142
<Compile Include="Extensions\Test_BitmapIconExtensionMarkupExtension.cs" />
142143
<Compile Include="Extensions\Test_FontIconSourceExtensionMarkupExtension.cs" />
143144
<Compile Include="Extensions\Test_FontIconExtensionMarkupExtension.cs" />

0 commit comments

Comments
 (0)