Skip to content

Added tests for remaining untested Circle methods: Intersect(), Intersects(). #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Tests/Geometry/CircleTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Numerics;
using DsaDotnet.Geometry;
using FluentAssertions;
using FluentAssertions.Specialized;

namespace Tests.Geometry;

Expand Down Expand Up @@ -136,4 +137,57 @@ public void Circle_Contains_Returns_CorrectValue(float x, float y, float r, floa
// Assert
result.Should().Be(expected);
}

[Theory]
[InlineData(1, 0, 1, true)]
[InlineData(2, 0, 1, true)]
[InlineData(3, 0, 1, false)]
[InlineData(0, 0, 2, false)]
public void Circle_Intersects_Returns_CorrectValue(float x, float y, float r, bool expected)
{
// Arrange
var sut = new Circle(new Vector2(0, 0), 1);
var circle = new Circle(new Vector2(x, y), r);

// Act
var result = sut.Intersects(circle);

// Assert
result.Should().Be(expected);
}

[Theory]
[InlineData(1, 0, 0.5f, -0.866f, 0.5f, 0.866f)]
[InlineData(2, 0, 1, 0, 1, 0)]
public void Circle_Intersect_Returns_CorrectValues(float x, float y, float i1X, float i1Y, float i2X, float i2Y)
{
// Arrange
var sut = new Circle(new Vector2(0, 0), 1);
var circle = new Circle(new Vector2(x, y), 1);

// Act
var result = sut.Intersect(circle, out var actual);

// Assert
result.Should().BeTrue();
actual[0].X.Should().BeApproximately(i1X, 0.0001f);
actual[0].Y.Should().BeApproximately(i1Y, 0.0001f);

actual[1].X.Should().BeApproximately(i2X, 0.0001f);
actual[1].Y.Should().BeApproximately(i2Y, 0.0001f);
}

[Fact]
public void Circle_Intersect_Returns_False_When_No_Intersection()
{
// Arrange
var sut = new Circle(new Vector2(0, 0), 1);
var circle = new Circle(new Vector2(3, 0), 1);

// Act
var result = sut.Intersect(circle, out _);

// Assert
result.Should().BeFalse();
}
}
Loading