From 25522f06f6c419c1456a3b4cebc04610cf6f5ebb Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 11 Dec 2023 22:41:43 +0100 Subject: [PATCH] Added Rectangle point and line tests --- .../2d-shapes/RectangleTests.cs | 122 +++++++++++++++++- 1 file changed, 116 insertions(+), 6 deletions(-) diff --git a/AdventOfCode.Tests/2d-shapes/RectangleTests.cs b/AdventOfCode.Tests/2d-shapes/RectangleTests.cs index 402aa16..2811bf8 100644 --- a/AdventOfCode.Tests/2d-shapes/RectangleTests.cs +++ b/AdventOfCode.Tests/2d-shapes/RectangleTests.cs @@ -10,13 +10,23 @@ namespace AdventOfCode.Tests._2d_shapes [SetUp] public void SetupLine() { - TestRectangle = new Rectangle(new Point(1,1), new Point(6,3)); + TestRectangle = new Rectangle(new Point(3,3), new Point(9,6)); } [Test] - public void PointDoesIntersectRectangle() + public void PointDoesIntersectOnCornerOneRectangle() { - Point testPoint = new Point(1,1); + 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); @@ -26,7 +36,7 @@ namespace AdventOfCode.Tests._2d_shapes [Test] public void PointDoesIntersectOnLineRectangle() { - Point testPoint = new Point(3, 1); + Point testPoint = new Point(3, 3); bool intersects = TestRectangle.Intersect(testPoint); @@ -36,11 +46,111 @@ namespace AdventOfCode.Tests._2d_shapes [Test] public void PointDoesIntersectInRectangle() { - Point testPoint = new Point(3, 3); + 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); + } } -} +} \ No newline at end of file