Xamarin.Forms/Xamarin.Forms.Core.UnitTests/SizeTests.cs

94 строки
2.0 KiB
C#
Исходник Обычный вид История

2016-03-22 23:02:25 +03:00
using NUnit.Framework;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class SizeTests : BaseTestFixture
{
[Test]
2020-09-29 13:15:44 +03:00
public void TestSizeIsZero()
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
var size = new Size();
2016-03-22 23:02:25 +03:00
2020-09-29 13:15:44 +03:00
Assert.True(size.IsZero);
2016-03-22 23:02:25 +03:00
2020-09-29 13:15:44 +03:00
size = new Size(10, 10);
2016-03-22 23:02:25 +03:00
2020-09-29 13:15:44 +03:00
Assert.False(size.IsZero);
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void TestSizeAdd()
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
var size1 = new Size(10, 10);
var size2 = new Size(20, 20);
2016-03-22 23:02:25 +03:00
var result = size1 + size2;
2020-09-29 13:15:44 +03:00
Assert.AreEqual(new Size(30, 30), result);
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void TestSizeSubtract()
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
var size1 = new Size(10, 10);
var size2 = new Size(2, 2);
2016-03-22 23:02:25 +03:00
var result = size1 - size2;
2020-09-29 13:15:44 +03:00
Assert.AreEqual(new Size(8, 8), result);
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void TestPointFromSize([Range(0, 2)] double x, [Range(0, 2)] double y)
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
var size = new Size(x, y);
var point = (Point)size;
2016-03-22 23:02:25 +03:00
2020-09-29 13:15:44 +03:00
Assert.AreEqual(x, point.X);
Assert.AreEqual(y, point.Y);
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void HashCode([Range(3, 5)] double w1, [Range(3, 5)] double h1, [Range(3, 5)] double w2, [Range(3, 5)] double h2)
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
bool result = new Size(w1, h1).GetHashCode() == new Size(w2, h2).GetHashCode();
2016-03-22 23:02:25 +03:00
if (w1 == w2 && h1 == h2)
2020-09-29 13:15:44 +03:00
Assert.True(result);
2016-03-22 23:02:25 +03:00
else
2020-09-29 13:15:44 +03:00
Assert.False(result);
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void Equality()
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
Assert.False(new Size().Equals(null));
Assert.False(new Size().Equals("Size"));
Assert.True(new Size(2, 3).Equals(new Size(2, 3)));
2016-03-22 23:02:25 +03:00
2020-09-29 13:15:44 +03:00
Assert.True(new Size(2, 3) == new Size(2, 3));
Assert.True(new Size(2, 3) != new Size(3, 2));
2016-03-22 23:02:25 +03:00
}
[Test]
[TestCase(0, 0, ExpectedResult = "{Width=0 Height=0}")]
[TestCase(1, 5, ExpectedResult = "{Width=1 Height=5}")]
2020-09-29 13:15:44 +03:00
public string TestToString(double w, double h)
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
return new Size(w, h).ToString();
2016-03-22 23:02:25 +03:00
}
[Test]
2020-09-29 13:15:44 +03:00
public void MultiplyByScalar([Range(12, 15)] int w, [Range(12, 15)] int h, [Values(0.0, 2.0, 7.0, 0.25)] double scalar)
2016-03-22 23:02:25 +03:00
{
2020-09-29 13:15:44 +03:00
var size = new Size(w, h);
2016-03-22 23:02:25 +03:00
var result = size * scalar;
2020-09-29 13:15:44 +03:00
Assert.AreEqual(w * scalar, result.Width);
Assert.AreEqual(h * scalar, result.Height);
2016-03-22 23:02:25 +03:00
}
}
}