MoonTools.Structs/Tests/Position2DTest.cs

114 lines
2.8 KiB
C#
Raw Permalink Normal View History

2019-09-06 07:13:49 +00:00
using FluentAssertions;
using NUnit.Framework;
2019-10-31 22:57:04 +00:00
2020-02-20 23:03:34 +00:00
using MoonTools.Structs;
2019-10-31 22:57:04 +00:00
using System.Numerics;
2019-09-06 07:13:49 +00:00
namespace Tests
{
public class Position2DTest
{
[Test]
public void Negatives()
{
var position = new Position2D(-3.6f, -4.2f);
position.X.Should().Be(-3);
position.Y.Should().Be(-4);
position.ToVector2().X.Should().Be(-3.6f);
position.ToVector2().Y.Should().Be(-4.2f);
}
2019-09-06 07:13:49 +00:00
[Test]
public void PositionVectorAddition()
{
var one = new Position2D(1.3f, 3.5f);
var two = new Position2D(4.8f, 0.9f);
var result = one + two;
result.X.Should().Be(6);
result.Y.Should().Be(4);
}
[Test]
public void PositionVectorNegativeAddition()
{
var one = new Position2D(1.4f, 2.8f);
var two = new Position2D(-1, -2);
var result = one + two;
result.X.Should().Be(0);
result.Y.Should().Be(0);
}
[Test]
public void PositionVectorVector2Addition()
{
var one = new Position2D(1.6f, 3.4f);
var two = new Vector2(8.2f, 4.7f);
var result = one + two;
result.X.Should().Be(9);
result.Y.Should().Be(8);
}
[Test]
public void PositionVectorSubtraction()
{
var one = new Position2D(1.3f, 3.5f);
var two = new Position2D(4.8f, 0.9f);
var result = one - two;
result.X.Should().BeApproximately(-3.5f, 0.01f);
result.Y.Should().BeApproximately(2.6f, 0.01f);
}
[Test]
public void PositionVectorVector2Subtraction()
{
var one = new Position2D(5.4f, 7.6f);
var two = new Vector2(4.2f, 1.2f);
var result = one - two;
result.X.Should().BeApproximately(1.2f, 0.01f);
result.Y.Should().BeApproximately(6.4f, 0.01f);
}
[Test]
public void Equals()
{
var one = new Position2D(5.2f, 4.7f);
var two = new Position2D(5.1f, 4.4f);
one.Equals(two).Should().BeTrue();
}
[Test]
public void EqualsOperator()
{
var one = new Position2D(5.2f, 4.7f);
var two = new Position2D(5.1f, 4.4f);
(one == two).Should().BeTrue();
}
[Test]
public void NotEquals()
{
var one = new Position2D(5.2f, 4.7f);
var two = new Position2D(3.1f, 2.4f);
one.Equals(two).Should().BeFalse();
}
[Test]
public void NotEqualsOperator()
{
var one = new Position2D(5.2f, 4.7f);
var two = new Position2D(3.1f, 2.4f);
(one != two).Should().BeTrue();
}
2019-09-06 07:13:49 +00:00
}
}