MoonTools.Bonk/Test/Equality.cs

481 lines
14 KiB
C#
Raw Normal View History

2019-10-25 23:20:43 +00:00
using NUnit.Framework;
using FluentAssertions;
using MoonTools.Core.Bonk;
using MoonTools.Core.Structs;
2019-10-31 23:19:30 +00:00
using System.Numerics;
2019-10-25 23:20:43 +00:00
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();
}
2019-12-02 05:51:52 +00:00
[Test]
public void PolygonRectangleEqual()
{
var a = new Polygon(
new Position2D(1, 1),
new Position2D(1, -1),
new Position2D(-1, -1),
new Position2D(-1, 1)
);
var b = new Rectangle(-1, -1, 1, 1);
a.Should().BeEquivalentTo(b);
}
[Test]
public void PolygonRectangleNotEqual()
{
var a = new Polygon(
new Position2D(2, 1),
new Position2D(1, -1),
new Position2D(-1, -1),
new Position2D(-2, 1)
);
var b = new Rectangle(-1, -1, 1, 1);
a.Should().NotBeEquivalentTo(b);
}
[Test]
public void PolygonRectangleEqualOperator()
{
var a = new Polygon(
new Position2D(1, 1),
new Position2D(1, -1),
new Position2D(-1, -1),
new Position2D(-1, 1)
);
var b = new Rectangle(-1, -1, 1, 1);
(a == b).Should().BeTrue();
}
[Test]
public void PolygonRectangleNotEqualOperator()
{
var a = new Polygon(
new Position2D(2, 1),
new Position2D(1, -1),
new Position2D(-1, -1),
new Position2D(-2, 1)
);
var b = new Rectangle(-1, -1, 1, 1);
(a != b).Should().BeTrue();
}
2019-10-25 23:20:43 +00:00
}
public class SimplexTests
{
[Test]
2019-10-26 05:00:34 +00:00
public void ZeroSimplexEquals()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One);
var simplexB = new Simplex2D(Vector2.One);
2019-10-25 23:20:43 +00:00
simplexA.Equals(simplexB).Should().BeTrue();
}
[Test]
2019-10-26 05:00:34 +00:00
public void ZeroSimplexEqualsOperator()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One);
var simplexB = new Simplex2D(Vector2.One);
2019-10-25 23:20:43 +00:00
(simplexA == simplexB).Should().BeTrue();
}
[Test]
2019-10-26 05:00:34 +00:00
public void ZeroSimplexNotEquals()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexB).Should().BeFalse();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.Zero, Vector2.One);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexC).Should().BeFalse();
}
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
[Test]
public void ZeroSimplexNotEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
(simplexA != simplexB).Should().BeTrue();
2019-10-25 23:20:43 +00:00
}
[Test]
2019-10-26 05:00:34 +00:00
public void OneSimplexEquals()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexB).Should().BeTrue();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexC.Equals(simplexD).Should().BeTrue();
}
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
[Test]
public void OneSimplexEqualsOperator()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero);
2019-10-25 23:20:43 +00:00
(simplexA == simplexB).Should().BeTrue();
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One);
(simplexC == simplexD).Should().BeTrue();
2019-10-25 23:20:43 +00:00
}
[Test]
2019-10-26 05:00:34 +00:00
public void OneSimplexNotEquals()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexB).Should().BeFalse();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexC.Equals(simplexD).Should().BeFalse();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexE = new Simplex2D(Vector2.Zero);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexE).Should().BeFalse();
2019-10-25 23:20:43 +00:00
}
[Test]
2019-10-26 05:00:34 +00:00
public void OneSimplexNotEqualsOperator()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexB = new Simplex2D(Vector2.One, Vector2.UnitX);
(simplexA == simplexB).Should().BeFalse();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitX);
(simplexC == simplexD).Should().BeFalse();
}
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
[Test]
public void TwoSimplexEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexA.Equals(simplexB).Should().BeTrue();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
simplexC.Equals(simplexD).Should().BeTrue();
2019-10-25 23:20:43 +00:00
}
[Test]
2019-10-26 05:00:34 +00:00
public void TwoSimplexEqualsOperator()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
(simplexA == simplexB).Should().BeTrue();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.One, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
(simplexC == simplexD).Should().BeTrue();
}
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
[Test]
public void TwoSimplexNotEquals()
{
var simplexA = new Simplex2D(Vector2.One, Vector2.UnitY, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
simplexA.Equals(simplexB).Should().BeFalse();
2019-10-26 05:00:34 +00:00
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();
2019-10-25 23:20:43 +00:00
}
[Test]
2019-10-26 05:00:34 +00:00
public void TwoSimplexNotEqualsOperator()
2019-10-25 23:20:43 +00:00
{
2019-10-26 05:00:34 +00:00
var simplexA = new Simplex2D(Vector2.One, Vector2.UnitY, Vector2.UnitX);
var simplexB = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
(simplexA == simplexB).Should().BeFalse();
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
var simplexC = new Simplex2D(Vector2.One, Vector2.Zero, Vector2.UnitX);
var simplexD = new Simplex2D(Vector2.Zero, Vector2.UnitY, Vector2.UnitX);
2019-10-25 23:20:43 +00:00
2019-10-26 05:00:34 +00:00
(simplexC == simplexD).Should().BeFalse();
2019-10-25 23:20:43 +00:00
}
}
}
}