From 8b768f824c225cf250d595f9fe9f2e5427c4608a Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 1 Apr 2023 00:30:04 +0100 Subject: [PATCH] test: add tests for Point.IsOnLine and PointF.IsOnLine --- X10D.Tests/src/Drawing/PointFTests.cs | 22 ++++++++++++++++++++++ X10D.Tests/src/Drawing/PointTests.cs | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/X10D.Tests/src/Drawing/PointFTests.cs b/X10D.Tests/src/Drawing/PointFTests.cs index db74ae3..52c33bc 100644 --- a/X10D.Tests/src/Drawing/PointFTests.cs +++ b/X10D.Tests/src/Drawing/PointFTests.cs @@ -7,6 +7,28 @@ namespace X10D.Tests.Drawing; [TestClass] public class PointFTests { + [TestMethod] + public void IsOnLine_ShouldReturnTrue_GivenPointOnLine() + { + var point = new PointF(1.0f, 0.0f); + var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f)); + + Assert.IsTrue(point.IsOnLine(line)); + Assert.IsTrue(point.IsOnLine(line.Start, line.End)); + Assert.IsTrue(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); + } + + [TestMethod] + public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine() + { + var point = new PointF(1.0f, 1.0f); + var line = new LineF(PointF.Empty, new PointF(2.0f, 0.0f)); + + Assert.IsFalse(point.IsOnLine(line)); + Assert.IsFalse(point.IsOnLine(line.Start, line.End)); + Assert.IsFalse(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); + } + [TestMethod] public void Round_ShouldRoundToNearestInteger_GivenNoParameters() { diff --git a/X10D.Tests/src/Drawing/PointTests.cs b/X10D.Tests/src/Drawing/PointTests.cs index e03fd2f..19e5890 100644 --- a/X10D.Tests/src/Drawing/PointTests.cs +++ b/X10D.Tests/src/Drawing/PointTests.cs @@ -7,6 +7,28 @@ namespace X10D.Tests.Drawing; [TestClass] public class PointTests { + [TestMethod] + public void IsOnLine_ShouldReturnTrue_GivenPointOnLine() + { + var point = new Point(1, 0); + var line = new Line(Point.Empty, new Point(2, 0)); + + Assert.IsTrue(point.IsOnLine(line)); + Assert.IsTrue(point.IsOnLine(line.Start, line.End)); + Assert.IsTrue(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); + } + + [TestMethod] + public void IsOnLine_ShouldReturnFalse_GivenPointNotOnLine() + { + var point = new Point(1, 1); + var line = new Line(Point.Empty, new Point(2, 0)); + + Assert.IsFalse(point.IsOnLine(line)); + Assert.IsFalse(point.IsOnLine(line.Start, line.End)); + Assert.IsFalse(point.IsOnLine(line.Start.ToVector2(), line.End.ToVector2())); + } + [TestMethod] public void ToSize_ShouldReturnSize_WithEquivalentMembers() {