156 lines
3.8 KiB
C#
156 lines
3.8 KiB
C#
using AdventOfCode.Core.Shared.Grid;
|
|
|
|
namespace AdventOfCode.Tests._2d_shapes
|
|
{
|
|
[TestFixture]
|
|
public class RectangleTests
|
|
{
|
|
private Rectangle TestRectangle;
|
|
|
|
[SetUp]
|
|
public void SetupLine()
|
|
{
|
|
TestRectangle = new Rectangle(new Point(3,3), new Point(9,6));
|
|
}
|
|
|
|
[Test]
|
|
public void PointDoesIntersectOnCornerOneRectangle()
|
|
{
|
|
Point testPoint = new Point(3,3);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void PointDoesIntersectOnCornerTwoRectangle()
|
|
{
|
|
Point testPoint = new Point(9, 6);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void PointDoesIntersectOnLineRectangle()
|
|
{
|
|
Point testPoint = new Point(3, 3);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void PointDoesIntersectInRectangle()
|
|
{
|
|
Point testPoint = new Point(5, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void PointDoesNotIntersectInRectangle()
|
|
{
|
|
Point testPoint = new Point(1, 1);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void LineIntersectFrontRectangle()
|
|
{
|
|
Line testPoint = new Line(1, 4, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LineIntersectBackRectangle()
|
|
{
|
|
Line testPoint = new Line(6, 4, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LineIntersectInsideRectangle()
|
|
{
|
|
Line testPoint = new Line(1, 3, 3);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LineIntersectFrontTopRectangle()
|
|
{
|
|
Line testPoint = new Line(1, 3, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LinetersectTopCornerEndRectangle()
|
|
{
|
|
Line testPoint = new Line(9, 6, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LineIntersectBottomCornerRectangle()
|
|
{
|
|
Line testPoint = new Line(9, 6, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void LineNotIntersectTopRectangle()
|
|
{
|
|
Line testPoint = new Line(4, 1, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void LineNotIntersectBeforeEndAtStartRectangle()
|
|
{
|
|
Line testPoint = new Line(10, 5, 5);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void LineNotIntersectStartFromEndRectangle()
|
|
{
|
|
Line testPoint = new Line(0, 5, 3);
|
|
|
|
bool intersects = TestRectangle.Intersect(testPoint);
|
|
|
|
Assert.That(intersects, Is.False);
|
|
}
|
|
}
|
|
} |