2022-05-09 10:33:21 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.TestTools;
|
2022-05-09 20:40:55 +01:00
|
|
|
|
using X10D.Core;
|
2022-05-09 10:33:21 +01:00
|
|
|
|
using X10D.Unity.Numerics;
|
2022-05-09 20:40:55 +01:00
|
|
|
|
using Random = System.Random;
|
2022-05-09 10:33:21 +01:00
|
|
|
|
|
|
|
|
|
namespace X10D.Unity.Tests.Numerics
|
|
|
|
|
{
|
|
|
|
|
public class Vector3Tests
|
|
|
|
|
{
|
2022-05-09 20:40:55 +01:00
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator ToSystemVector_ShouldReturnVector_WithEqualComponents()
|
|
|
|
|
{
|
|
|
|
|
var random = new Random();
|
|
|
|
|
float x = random.NextSingle();
|
|
|
|
|
float y = random.NextSingle();
|
|
|
|
|
float z = random.NextSingle();
|
|
|
|
|
|
|
|
|
|
var vector = new Vector3(x, y, z);
|
|
|
|
|
var systemVector = vector.ToSystemVector();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(vector.magnitude, systemVector.Length(), 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.x, systemVector.X, 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.y, systemVector.Y, 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.z, systemVector.Z, 1e-6f);
|
|
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator ToUnityVector_ShouldReturnVector_WithEqualComponents()
|
|
|
|
|
{
|
|
|
|
|
var random = new Random();
|
|
|
|
|
float x = random.NextSingle();
|
|
|
|
|
float y = random.NextSingle();
|
|
|
|
|
float z = random.NextSingle();
|
|
|
|
|
|
|
|
|
|
var vector = new System.Numerics.Vector3(x, y, z);
|
|
|
|
|
var unityVector = vector.ToUnityVector();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(vector.Length(), unityVector.magnitude, 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.X, unityVector.x, 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.Y, unityVector.y, 1e-6f);
|
|
|
|
|
Assert.AreEqual(vector.Z, unityVector.z, 1e-6f);
|
|
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 10:33:21 +01:00
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator WithX_ShouldReturnVectorWithNewX_GivenVector()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.one.WithX(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.zero.WithX(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.right.WithX(0));
|
|
|
|
|
Assert.AreEqual(Vector3.up, Vector3.up.WithX(0));
|
|
|
|
|
Assert.AreEqual(Vector3.forward, Vector3.forward.WithX(0));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Vector3.one, Vector3.one.WithX(1));
|
|
|
|
|
Assert.AreEqual(Vector3.right, Vector3.zero.WithX(1));
|
|
|
|
|
Assert.AreEqual(Vector3.right, Vector3.right.WithX(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.up.WithX(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.forward.WithX(1));
|
|
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator WithY_ShouldReturnVectorWithNewY_GivenVector()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.one.WithY(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.zero.WithY(0));
|
|
|
|
|
Assert.AreEqual(Vector3.right, Vector3.right.WithY(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.up.WithY(0));
|
|
|
|
|
Assert.AreEqual(Vector3.forward, Vector3.forward.WithY(0));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Vector3.one, Vector3.one.WithY(1));
|
|
|
|
|
Assert.AreEqual(Vector3.up, Vector3.zero.WithY(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.right.WithY(1));
|
|
|
|
|
Assert.AreEqual(Vector3.up, Vector3.up.WithY(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.forward.WithY(1));
|
|
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UnityTest]
|
|
|
|
|
public IEnumerator WithZ_ShouldReturnVectorWithNewZ_GivenVector()
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.one.WithZ(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.zero.WithZ(0));
|
|
|
|
|
Assert.AreEqual(Vector3.right, Vector3.right.WithZ(0));
|
|
|
|
|
Assert.AreEqual(Vector3.up, Vector3.up.WithZ(0));
|
|
|
|
|
Assert.AreEqual(Vector3.zero, Vector3.forward.WithZ(0));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(Vector3.one, Vector3.one.WithZ(1));
|
|
|
|
|
Assert.AreEqual(Vector3.forward, Vector3.zero.WithZ(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.right.WithZ(1));
|
|
|
|
|
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.up.WithZ(1));
|
|
|
|
|
Assert.AreEqual(Vector3.forward, Vector3.forward.WithZ(1));
|
|
|
|
|
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|