From 5d5bc1e384d4dfd113136fd45fe2a5c3ea6e4b2f Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 30 Apr 2022 11:34:15 +0100 Subject: [PATCH] Add tests for NextUnitVector2/3 and NextRotation(Uniform) --- X10D.Tests/src/Numerics/RandomTests.cs | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 X10D.Tests/src/Numerics/RandomTests.cs diff --git a/X10D.Tests/src/Numerics/RandomTests.cs b/X10D.Tests/src/Numerics/RandomTests.cs new file mode 100644 index 0000000..3864574 --- /dev/null +++ b/X10D.Tests/src/Numerics/RandomTests.cs @@ -0,0 +1,68 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using X10D.Numerics; + +namespace X10D.Tests.Numerics; + +[TestClass] +public class RandomTests +{ + [TestMethod] + public void NextUnitVector2_ShouldReturnVector_WithMagnitude1() + { + var random = new Random(); + var vector = random.NextUnitVector2(); + Assert.AreEqual(1, vector.Length(), 1e-6); + } + + [TestMethod] + public void NextUnitVector2_ShouldThrow_GivenNullRandom() + { + Random? random = null; + Assert.ThrowsException(() => random!.NextUnitVector2()); + } + + [TestMethod] + public void NextUnitVector3_ShouldReturnVector_WithMagnitude1() + { + var random = new Random(); + var vector = random.NextUnitVector3(); + Assert.AreEqual(1, vector.Length(), 1e-6); + } + + [TestMethod] + public void NextUnitVector3_ShouldThrow_GivenNullRandom() + { + Random? random = null; + Assert.ThrowsException(() => random!.NextUnitVector3()); + } + + [TestMethod] + public void NextRotation_ShouldReturnQuaternion_WithMagnitude1() + { + var random = new Random(); + var rotation = random.NextRotation(); + Assert.AreEqual(1, rotation.Length(), 1e-6); + } + + [TestMethod] + public void NextRotation_ShouldThrow_GivenNullRandom() + { + Random? random = null; + Assert.ThrowsException(() => random!.NextRotation()); + } + + [TestMethod] + public void NextRotationUniform_ShouldReturnQuaternion_WithMagnitude1() + { + var random = new Random(); + var rotation = random.NextRotationUniform(); + Assert.AreEqual(1, rotation.Length(), 1e-6); + } + + [TestMethod] + public void NextRotationUniform_ShouldThrow_GivenNullRandom() + { + Random? random = null; + Assert.ThrowsException(() => random!.NextRotationUniform()); + } +}