Add tests for NextUnitVector2/3 and NextRotation(Uniform)

This commit is contained in:
Oliver Booth 2022-04-30 11:34:15 +01:00
parent 8ba5a5ad19
commit 5d5bc1e384
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
1 changed files with 68 additions and 0 deletions

View File

@ -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<ArgumentNullException>(() => 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<ArgumentNullException>(() => 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<ArgumentNullException>(() => 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<ArgumentNullException>(() => random!.NextRotationUniform());
}
}