X10D/X10D.Tests/src/Drawing/SphereTests.cs

143 lines
4.1 KiB
C#
Raw Normal View History

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