MoonTools.Bonk/Test/Equality.cs

421 lines
13 KiB
C#

using NUnit.Framework;
using FluentAssertions;
using MoonTools.Core.Bonk;
using MoonTools.Core.Structs;
using System.Numerics;
namespace Tests
{
public class EqualityTests
{
public class CircleTests
{
[Test]
public void CircleEqual()
{
var a = new Circle(2);
var b = new Circle(2);
(a.Equals(b)).Should().BeTrue();
}
[Test]
public void CircleNotEqual()
{
var a = new Circle(2);
var b = new Circle(3);
(a.Equals(b)).Should().BeFalse();
}
[Test]
public void CircleEqualOperator()
{
var a = new Circle(2);
var b = new Circle(2);
(a == b).Should().BeTrue();
}
[Test]
public void CircleNotEqualOperator()
{
var a = new Circle(2);
var b = new Circle(3);
(a != b).Should().BeTrue();
}
}
public class LineTests
{
[Test]
public void LineEqual()
{
var a = new Line(new Position2D(0, 2), new Position2D(2, 4));
var b = new Line(new Position2D(0, 2), new Position2D(2, 4));
a.Equals(b).Should().BeTrue();
}
[Test]
public void LineEqualOperator()
{
var a = new Line(new Position2D(0, 2), new Position2D(2, 4));
var b = new Line(new Position2D(0, 2), new Position2D(2, 4));
(a == b).Should().BeTrue();
}
[Test]
public void LineNotEqual()
{
var a = new Line(new Position2D(-2, 4), new Position2D(2, 4));
var b = new Line(new Position2D(0, 3), new Position2D(5, 1));
a.Equals(b).Should().BeFalse();
}
[Test]
public void LineNotEqualOperator()
{
var a = new Line(new Position2D(-2, 4), new Position2D(2, 4));
var b = new Line(new Position2D(0, 3), new Position2D(5, 1));
(a != b).Should().BeTrue();
}
[Test]
public void LineReversedEqual()
{
var a = new Line(new Position2D(0, 2), new Position2D(2, 4));
var b = new Line(new Position2D(2, 4), new Position2D(0, 2));
a.Equals(b).Should().BeTrue();
}
[Test]
public void LineReversedEqualOperator()
{
var a = new Line(new Position2D(0, 2), new Position2D(2, 4));
var b = new Line(new Position2D(2, 4), new Position2D(0, 2));
(a == b).Should().BeTrue();
}
}
public class RectangleTests
{
[Test]
public void RectangleEqual()
{
var a = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
var b = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
a.Equals(b).Should().BeTrue();
}
[Test]
public void RectangleEqualOperator()
{
var a = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
var b = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
(a == b).Should().BeTrue();
}
[Test]
public void RectangleNotEqual()
{
var a = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
var b = new MoonTools.Core.Bonk.Rectangle(-1, -1, 5, 5);
a.Equals(b).Should().BeFalse();
}
[Test]
public void RectangleNotEqualOperator()
{
var a = new MoonTools.Core.Bonk.Rectangle(0, 0, 3, 3);
var b = new MoonTools.Core.Bonk.Rectangle(-1, -1, 5, 5);
(a != b).Should().BeTrue();
}
}
public class PolygonTests
{
[Test]
public void PolygonEqual()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
a.Equals(b).Should().BeTrue();
}
[Test]
public void PolygonEqualOperator()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
(a == b).Should().BeTrue();
}
[Test]
public void PolygonDifferentOrderEqual()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(1, 2),
new Position2D(-1, -1),
new Position2D(0, 1)
);
a.Equals(b).Should().BeTrue();
}
[Test]
public void PolygonDifferentOrderEqualOperator()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(1, 2),
new Position2D(-1, -1),
new Position2D(0, 1)
);
(a == b).Should().BeTrue();
}
[Test]
public void PolygonNotEqual()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(1, 0),
new Position2D(2, 1),
new Position2D(-1, -1)
);
a.Equals(b).Should().BeFalse();
}
[Test]
public void PolygonNotEqualOperator()
{
var a = new Polygon(
new Position2D(0, 1),
new Position2D(1, 2),
new Position2D(-1, -1)
);
var b = new Polygon(
new Position2D(1, 0),
new Position2D(2, 1),
new Position2D(-1, -1)
);
(a != b).Should().BeTrue();
}
}
public class SimplexTests
{
[Test]
public void ZeroSimplexEquals()
{
var simplexA = new Simplex2D(Vector2.One);
var simplexB = new Simplex2D(Vector2.One);
simplexA.Equals(simplexB).Should().BeTrue();
}
[Test]
public void ZeroSimplexEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One);
var simplexB = new Simplex2D(Vector2.One);
(simplexA == simplexB).Should().BeTrue();
}
[Test]
public void ZeroSimplexNotEquals()
{
var simplexA = new Simplex2D(Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One);
simplexA.Equals(simplexB).Should().BeFalse();
var simplexC = new Simplex2D(Vector2.Zero, Vector2.One);
simplexA.Equals(simplexC).Should().BeFalse();
}
[Test]
public void ZeroSimplexNotEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One);
(simplexA != simplexB).Should().BeTrue();
}
[Test]
public void OneSimplexEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero);
simplexA.Equals(simplexB).Should().BeTrue();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One);
simplexC.Equals(simplexD).Should().BeTrue();
}
[Test]
public void OneSimplexEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero);
(simplexA == simplexB).Should().BeTrue();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One);
(simplexC == simplexD).Should().BeTrue();
}
[Test]
public void OneSimplexNotEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.UnitX);
simplexA.Equals(simplexB).Should().BeFalse();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitX);
simplexC.Equals(simplexD).Should().BeFalse();
var simplexE = new Simplex2D(Vector2.Zero);
simplexA.Equals(simplexE).Should().BeFalse();
}
[Test]
public void OneSimplexNotEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.UnitX);
(simplexA == simplexB).Should().BeFalse();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitX);
(simplexC == simplexD).Should().BeFalse();
}
[Test]
public void TwoSimplexEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
simplexA.Equals(simplexB).Should().BeTrue();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One, Vector2.UnitX);
simplexC.Equals(simplexD).Should().BeTrue();
}
[Test]
public void TwoSimplexEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
(simplexA == simplexB).Should().BeTrue();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One, Vector2.UnitX);
(simplexC == simplexD).Should().BeTrue();
}
[Test]
public void TwoSimplexNotEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.UnitY, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
simplexA.Equals(simplexB).Should().BeFalse();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitY, Vector2.UnitX);
simplexC.Equals(simplexD).Should().BeFalse();
var simplexE = new Simplex2D(Vector2.Zero);
simplexA.Equals(simplexE).Should().BeFalse();
}
[Test]
public void TwoSimplexNotEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.UnitY, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
(simplexA == simplexB).Should().BeFalse();
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitY, Vector2.UnitX);
(simplexC == simplexD).Should().BeFalse();
}
}
}
}