-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b4622c
commit 088d129
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using Bearded.Utilities.Geometry; | ||
using Bearded.Utilities.Tests.Generators; | ||
using FluentAssertions; | ||
using FsCheck.Xunit; | ||
using OpenTK.Mathematics; | ||
|
||
namespace Bearded.Utilities.Tests.Geometry; | ||
|
||
public sealed class RectangleTest | ||
{ | ||
private const float epsilon = 0.01f; | ||
|
||
[Property(Arbitrary = new[] { typeof(FloatGenerators.ForArithmetic) })] | ||
public void RectangleMadeFromXyWidthHeightHasCorrectDimensions(float x, float y, float w, float h) | ||
{ | ||
if (w < 0) w *= -1; | ||
if (h < 0) h *= -1; | ||
|
||
var rectangle = new Rectangle(x, y, w, h); | ||
|
||
// from input | ||
rectangle.Left.Should().BeApproximately(x, epsilon); | ||
rectangle.Top.Should().BeApproximately(y, epsilon); | ||
rectangle.Width.Should().BeApproximately(w, epsilon); | ||
rectangle.Height.Should().BeApproximately(h, epsilon); | ||
|
||
// derived | ||
rectangle.Right.Should().BeApproximately(x + w, epsilon); | ||
rectangle.Bottom.Should().BeApproximately(y + h, epsilon); | ||
} | ||
|
||
[Property(Arbitrary = new[] { typeof(FloatGenerators.ForArithmetic) })] | ||
public void RectangleMadeFromSidesHasCorrectDimensions(float x1, float x2, float y1, float y2) | ||
{ | ||
var top = Math.Min(y1, y2); | ||
var right = Math.Max(x1, x2); | ||
var bottom = Math.Max(y1, y2); | ||
var left = Math.Min(x1, x2); | ||
|
||
var rectangle = Rectangle.WithSides(top, right, bottom, left); | ||
|
||
// from input | ||
rectangle.Top.Should().BeApproximately(top, epsilon); | ||
rectangle.Right.Should().BeApproximately(right, epsilon); | ||
rectangle.Bottom.Should().BeApproximately(bottom, epsilon); | ||
rectangle.Left.Should().BeApproximately(left, epsilon); | ||
|
||
// derived | ||
rectangle.Width.Should().BeApproximately(right - left, epsilon); | ||
rectangle.Height.Should().BeApproximately(bottom - top, epsilon); | ||
} | ||
|
||
[Property(Arbitrary = new[] { typeof(FloatGenerators.ForArithmetic) })] | ||
public void RectangleMadeFromCornersHasCorrectDimensions(float x1, float x2, float y1, float y2) | ||
{ | ||
var top = Math.Min(y1, y2); | ||
var right = Math.Max(x1, x2); | ||
var bottom = Math.Max(y1, y2); | ||
var left = Math.Min(x1, x2); | ||
|
||
var rectangle = Rectangle.WithCorners(new Vector2(left, top), new Vector2(right, bottom)); | ||
|
||
// from input | ||
rectangle.Top.Should().BeApproximately(top, epsilon); | ||
rectangle.Right.Should().BeApproximately(right, epsilon); | ||
rectangle.Bottom.Should().BeApproximately(bottom, epsilon); | ||
rectangle.Left.Should().BeApproximately(left, epsilon); | ||
|
||
// derived | ||
rectangle.Width.Should().BeApproximately(right - left, epsilon); | ||
rectangle.Height.Should().BeApproximately(bottom - top, epsilon); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters