2023-08-26 18:11:29 +01:00
|
|
|
using NUnit.Framework;
|
2022-06-01 19:43:52 +01:00
|
|
|
using X10D.Drawing;
|
|
|
|
|
|
|
|
namespace X10D.Tests.Drawing;
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[TestFixture]
|
2023-08-22 17:32:47 +01:00
|
|
|
internal class SphereTests
|
2022-06-01 19:43:52 +01:00
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Circumference_ShouldBe2PiRadius_GivenUnitCircle()
|
|
|
|
{
|
|
|
|
var unitSphere = Sphere.Unit;
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(unitSphere.Circumference, Is.EqualTo(2.0f * MathF.PI * unitSphere.Radius).Within(1e-6f));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldBeNegativeOne_GivenUnitCircleAndEmpty()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty.CompareTo(Sphere.Unit), Is.EqualTo(-1));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldBeOne_GivenUnitCircleAndEmpty()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit.CompareTo(Sphere.Empty), Is.EqualTo(1));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldBeNegativeOne_GivenEmptyCircleAndUnitCircleAsObject()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty.CompareTo((object)Sphere.Unit), Is.EqualTo(-1));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldBeOne_GivenNull()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit.CompareTo(null), Is.EqualTo(1));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldBeZero_GivenUnitCircle()
|
|
|
|
{
|
|
|
|
var unitCircle = Sphere.Unit;
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(unitCircle.CompareTo(unitCircle), Is.Zero);
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void CompareTo_ShouldThrowArgumentException_GivenInvalidType()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.Throws<ArgumentException>(() => _ = Sphere.Unit.CompareTo(new object()));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Diameter_ShouldBe2_GivenUnitSphere()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit.Diameter, Is.EqualTo(2.0f).Within(1e-6f));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Equals_ShouldBeTrue_GivenTwoUnitCircles()
|
|
|
|
{
|
|
|
|
var unitCircle1 = Sphere.Unit;
|
|
|
|
var unitCircle2 = Sphere.Unit;
|
2023-04-05 22:26:31 +01:00
|
|
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
{
|
|
|
|
Assert.That(unitCircle2, Is.EqualTo(unitCircle1));
|
|
|
|
Assert.That(unitCircle1, Is.EqualTo(unitCircle2));
|
2023-04-05 23:18:14 +01:00
|
|
|
Assert.That(unitCircle2 == unitCircle1);
|
|
|
|
Assert.That(unitCircle1 == unitCircle2);
|
2023-04-05 22:26:31 +01:00
|
|
|
});
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2023-04-01 00:30:51 +01:00
|
|
|
public void Equals_ShouldBeFalse_GivenDifferentObjects()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit, Is.Not.EqualTo(null));
|
2023-04-05 23:18:14 +01:00
|
|
|
Assert.That(Sphere.Unit.Equals(null), Is.False);
|
2023-04-01 00:30:51 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Equals_ShouldBeFalse_GivenDifferentCircles()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty, Is.Not.EqualTo(Sphere.Unit));
|
|
|
|
Assert.That(Sphere.Unit, Is.Not.EqualTo(Sphere.Empty));
|
2023-04-05 23:18:14 +01:00
|
|
|
Assert.That(Sphere.Empty != Sphere.Unit);
|
|
|
|
Assert.That(Sphere.Unit != Sphere.Empty);
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void GetHashCode_ShouldBeCorrect_GivenEmptyCircle()
|
|
|
|
{
|
|
|
|
// this test is pretty pointless, it exists only for code coverage purposes
|
|
|
|
int hashCode = Sphere.Empty.GetHashCode();
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty.GetHashCode(), Is.EqualTo(hashCode));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void GetHashCode_ShouldBeCorrect_GivenUnitCircle()
|
|
|
|
{
|
|
|
|
// this test is pretty pointless, it exists only for code coverage purposes
|
|
|
|
int hashCode = Sphere.Unit.GetHashCode();
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit.GetHashCode(), Is.EqualTo(hashCode));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void op_GreaterThan_True_GivenUnitAndEmptyCircle()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit, Is.GreaterThan(Sphere.Empty));
|
|
|
|
Assert.That(Sphere.Unit, Is.GreaterThanOrEqualTo(Sphere.Empty));
|
2023-04-05 23:18:14 +01:00
|
|
|
Assert.That(Sphere.Unit > Sphere.Empty);
|
|
|
|
Assert.That(Sphere.Unit >= Sphere.Empty);
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void op_LessThan_True_GivenEmptyAndUnitCircle()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty, Is.LessThan(Sphere.Unit));
|
|
|
|
Assert.That(Sphere.Empty, Is.LessThanOrEqualTo(Sphere.Unit));
|
2023-04-05 23:18:14 +01:00
|
|
|
Assert.That(Sphere.Empty < Sphere.Unit);
|
|
|
|
Assert.That(Sphere.Empty <= Sphere.Unit);
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Radius_ShouldBe0_GivenEmptySphere()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Empty.Radius, Is.Zero);
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Radius_ShouldBe1_GivenUnitSphere()
|
|
|
|
{
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(Sphere.Unit.Radius, Is.EqualTo(1));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 22:26:31 +01:00
|
|
|
[Test]
|
2022-06-01 19:43:52 +01:00
|
|
|
public void Volume_ShouldBe4Over3TimesPi_GivenUnitCircle()
|
|
|
|
{
|
|
|
|
var unitSphere = Sphere.Unit;
|
2023-04-05 22:26:31 +01:00
|
|
|
Assert.That(unitSphere.Volume, Is.EqualTo(4.0f / 3.0f * MathF.PI));
|
2022-06-01 19:43:52 +01:00
|
|
|
}
|
|
|
|
}
|