2022-05-08 12:09:30 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using X10D.Unity.Numerics;
|
|
|
|
|
|
2022-05-08 12:17:57 +01:00
|
|
|
|
namespace X10D.Unity.Tests.Numerics
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
public class RandomTests
|
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextUnitVector2_ShouldReturnVector_WithMagnitude1()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random();
|
|
|
|
|
var vector = random.NextUnitVector2();
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(vector.magnitude, Is.EqualTo(1).Within(1e-6));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextUnitVector2_ShouldThrow_GivenNullRandom()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextUnitVector2());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextUnitVector3_ShouldReturnVector_WithMagnitude1()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
|
|
|
|
var random = new Random();
|
|
|
|
|
var vector = random.NextUnitVector3();
|
2023-04-05 22:51:04 +01:00
|
|
|
|
Assert.That(vector.magnitude, Is.EqualTo(1).Within(1e-6));
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextUnitVector3_ShouldThrow_GivenNullRandom()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextUnitVector3());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextRotation_ShouldThrow_GivenNullRandom()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextRotation());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
|
[Test]
|
|
|
|
|
public void NextRotationUniform_ShouldThrow_GivenNullRandom()
|
2022-05-08 12:09:30 +01:00
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
|
Random random = null!;
|
|
|
|
|
Assert.Throws<ArgumentNullException>(() => random.NextRotationUniform());
|
2022-05-08 12:09:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|