2012-08-09 09:45:04 +00:00
|
|
|
#region Using Statements
|
2011-10-31 05:36:24 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
#endregion // Using Statements
|
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
using XNARect = Microsoft.Xna.Framework.Rectangle;
|
|
|
|
using ANXRect = ANX.Framework.Rectangle;
|
|
|
|
|
|
|
|
namespace ANX.Framework.TestCenter.Strukturen
|
|
|
|
{
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
class RectangleTest
|
|
|
|
{
|
2012-10-14 09:02:26 +00:00
|
|
|
private static object[] ninefloats =
|
|
|
|
{
|
|
|
|
new object[] {0, 0, 0, 0},
|
|
|
|
new object[] {1, 2, 3, 4},
|
|
|
|
new object[] {-1, -2, 3, 4},
|
|
|
|
new object[] {1, -2, 0, 0}
|
|
|
|
};
|
2011-10-31 05:36:24 +00:00
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
private static object[] ninefloats6 =
|
|
|
|
{
|
|
|
|
new object[] {0, 0, 0, 0, 0, 0, 0, 0},
|
|
|
|
new object[] {1, 2, 3, 4, 0, 0, 2, 5},
|
|
|
|
new object[] {-1, -2, 3, 4, 1, 10, 1, 5},
|
|
|
|
new object[] {1, -2, 0, 0, 3, 1, 2, 1}
|
|
|
|
};
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
#region properties
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Bottom(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Bottom, anx.Bottom, "Bottom");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Center(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
|
|
|
int xnaRX = xna.Center.X;
|
|
|
|
int anxRX = anx.Center.X;
|
|
|
|
|
|
|
|
int xnaRY = xna.Center.Y;
|
|
|
|
int anxRY = anx.Center.Y;
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
Assert.AreEqual(xnaRX, anxRX);
|
|
|
|
Assert.AreEqual(xnaRY, anxRY);
|
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test]
|
|
|
|
public void Empty()
|
|
|
|
{
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(XNARect.Empty, ANXRect.Empty, "Empty");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void ToString(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
2012-10-14 09:02:26 +00:00
|
|
|
|
|
|
|
AssertHelper.ConvertEquals(xna.ToString(), anx.ToString(), "ToString");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void IsEmpty(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
Assert.AreEqual(xna.IsEmpty, anx.IsEmpty);
|
|
|
|
Assert.IsTrue(XNARect.Empty.IsEmpty);
|
|
|
|
Assert.IsTrue(ANXRect.Empty.IsEmpty);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Left(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Left, anx.Left, "Left");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Location(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
|
|
|
int xnaRX = xna.Location.X;
|
|
|
|
int anxRX = anx.Location.X;
|
|
|
|
|
|
|
|
int xnaRY = xna.Location.Y;
|
|
|
|
int anxRY = anx.Location.Y;
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
Assert.AreEqual(xnaRX, anxRX);
|
|
|
|
Assert.AreEqual(xnaRY, anxRY);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Right(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Right, anx.Right, "Right");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Top(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Top, anx.Top, "Top");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region constructors
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
|
|
|
public void Constructor(int x1, int y1, int w1, int h1)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(xna, anx, "Constructor");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region public methods
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void ContainsPoint(int x1, int y1, int w1, int h1, int u, int v, int nop1, int nop2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Contains(u, v), anx.Contains(u, v), "ContainsPoint");
|
|
|
|
}
|
2011-10-31 05:36:24 +00:00
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void ContainsRect(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna2 = new XNARect(x2, y2, w2, h2);
|
|
|
|
ANXRect anx2 = new ANXRect(x2, y2, w2, h2);
|
|
|
|
|
2012-10-14 09:02:26 +00:00
|
|
|
AssertHelper.ConvertEquals(xna.Contains(xna2), anx.Contains(anx2), "ContainsRect");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats")]
|
2012-10-14 09:02:26 +00:00
|
|
|
public void GetHashCode(int x1, int y1, int w1, int h1)
|
2011-10-31 05:36:24 +00:00
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
|
|
|
Assert.AreEqual(xna.GetHashCode(), anx.GetHashCode());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void Inflate(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
|
|
|
xna.Inflate(x2, y2);
|
|
|
|
anx.Inflate(x2, y2);
|
|
|
|
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(xna, anx, "Inflate");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void Intersects(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna2 = new XNARect(x2, y2, w2, h2);
|
|
|
|
ANXRect anx2 = new ANXRect(x2, y2, w2, h2);
|
2012-10-14 09:02:26 +00:00
|
|
|
|
2011-10-31 05:36:24 +00:00
|
|
|
Assert.AreEqual(xna.Intersects(xna2), anx.Intersects(anx2));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void Offset(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
|
|
|
|
xna.Offset(x2, y2);
|
|
|
|
anx.Offset(x2, y2);
|
|
|
|
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(xna, anx, "Offset");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void IntersectStatic(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna2 = new XNARect(x2, y2, w2, h2);
|
|
|
|
ANXRect anx2 = new ANXRect(x2, y2, w2, h2);
|
|
|
|
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(XNARect.Intersect(xna, xna2), ANXRect.Intersect(anx, anx2), "Intersection");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void Union(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna2 = new XNARect(x2, y2, w2, h2);
|
|
|
|
ANXRect anx2 = new ANXRect(x2, y2, w2, h2);
|
|
|
|
|
2011-11-04 06:46:24 +00:00
|
|
|
AssertHelper.ConvertEquals(XNARect.Union(xna, xna2), ANXRect.Union(anx, anx2), "Union");
|
2011-10-31 05:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test, TestCaseSource("ninefloats6")]
|
|
|
|
public void Equals(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
|
|
|
|
{
|
|
|
|
XNARect xna = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna1 = new XNARect(x1, y1, w1, h1);
|
|
|
|
ANXRect anx1 = new ANXRect(x1, y1, w1, h1);
|
|
|
|
XNARect xna2 = new XNARect(x1 + 1, y1 + 1, w1 + 1, h1 + 1);
|
|
|
|
ANXRect anx2 = new ANXRect(x1 + 1, y1 + 1, w1 + 1, h1 + 1);
|
|
|
|
|
|
|
|
Assert.IsTrue(xna.Equals(xna1));
|
|
|
|
Assert.IsTrue(anx.Equals(anx1));
|
|
|
|
|
|
|
|
Assert.IsFalse(xna.Equals(xna2));
|
|
|
|
Assert.IsFalse(anx.Equals(anx2));
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|