2023-08-26 18:15:04 +01:00
|
|
|
using NUnit.Framework;
|
2022-05-31 11:41:29 +01:00
|
|
|
using UnityEngine;
|
|
|
|
using X10D.Unity.Numerics;
|
|
|
|
using Random = System.Random;
|
|
|
|
|
|
|
|
namespace X10D.Unity.Tests.Numerics
|
|
|
|
{
|
|
|
|
public class Vector2IntTests
|
|
|
|
{
|
2023-04-05 19:18:06 +01:00
|
|
|
[Test]
|
|
|
|
public void Deconstruct_ShouldReturnCorrectValues()
|
2022-05-31 11:41:29 +01:00
|
|
|
{
|
|
|
|
var vector = new Vector2Int(1, 2);
|
|
|
|
(int x, int y) = vector;
|
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(x, Is.EqualTo(1));
|
|
|
|
Assert.That(y, Is.EqualTo(2));
|
2022-05-31 11:41:29 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
[Test]
|
|
|
|
public void ToSystemPoint_ShouldReturnPoint_WithEquivalentMembers()
|
2022-05-31 11:41:29 +01:00
|
|
|
{
|
|
|
|
var random = new Random();
|
|
|
|
int x = random.Next();
|
|
|
|
int y = random.Next();
|
|
|
|
|
|
|
|
var vector = new Vector2Int(x, y);
|
|
|
|
var point = vector.ToSystemPoint();
|
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(point.X, Is.EqualTo(vector.x));
|
|
|
|
Assert.That(point.Y, Is.EqualTo(vector.y));
|
2022-05-31 11:41:29 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
[Test]
|
|
|
|
public void ToSystemSize_ShouldReturnSize_WithEquivalentMembers()
|
2022-05-31 11:41:29 +01:00
|
|
|
{
|
|
|
|
var random = new Random();
|
|
|
|
int x = random.Next();
|
|
|
|
int y = random.Next();
|
|
|
|
|
|
|
|
var vector = new Vector2Int(x, y);
|
|
|
|
var point = vector.ToSystemSize();
|
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(point.Width, Is.EqualTo(vector.x));
|
|
|
|
Assert.That(point.Height, Is.EqualTo(vector.y));
|
2022-05-31 11:41:29 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
[Test]
|
|
|
|
public void WithX_ShouldReturnVectorWithNewX_GivenVector()
|
2022-05-31 11:41:29 +01:00
|
|
|
{
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(Vector2Int.one.WithX(0), Is.EqualTo(Vector2Int.up));
|
|
|
|
Assert.That(Vector2Int.zero.WithX(0), Is.EqualTo(Vector2Int.zero));
|
|
|
|
Assert.That(Vector2Int.right.WithX(0), Is.EqualTo(Vector2Int.zero));
|
|
|
|
Assert.That(Vector2Int.up.WithX(0), Is.EqualTo(Vector2Int.up));
|
2022-05-31 11:41:29 +01:00
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(Vector2Int.one.WithX(1), Is.EqualTo(Vector2Int.one));
|
|
|
|
Assert.That(Vector2Int.zero.WithX(1), Is.EqualTo(Vector2Int.right));
|
|
|
|
Assert.That(Vector2Int.right.WithX(1), Is.EqualTo(Vector2Int.right));
|
|
|
|
Assert.That(Vector2Int.up.WithX(1), Is.EqualTo(Vector2Int.one));
|
2022-05-31 11:41:29 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:18:06 +01:00
|
|
|
[Test]
|
|
|
|
public void WithY_ShouldReturnVectorWithNewY_GivenVector()
|
2022-05-31 11:41:29 +01:00
|
|
|
{
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(Vector2Int.one.WithY(0), Is.EqualTo(Vector2Int.right));
|
|
|
|
Assert.That(Vector2Int.zero.WithY(0), Is.EqualTo(Vector2Int.zero));
|
|
|
|
Assert.That(Vector2Int.right.WithY(0), Is.EqualTo(Vector2Int.right));
|
|
|
|
Assert.That(Vector2Int.up.WithY(0), Is.EqualTo(Vector2Int.zero));
|
2022-05-31 11:41:29 +01:00
|
|
|
|
2023-04-05 22:51:04 +01:00
|
|
|
Assert.That(Vector2Int.one.WithY(1), Is.EqualTo(Vector2Int.one));
|
|
|
|
Assert.That(Vector2Int.zero.WithY(1), Is.EqualTo(Vector2Int.up));
|
|
|
|
Assert.That(Vector2Int.right.WithY(1), Is.EqualTo(Vector2Int.one));
|
|
|
|
Assert.That(Vector2Int.up.WithY(1), Is.EqualTo(Vector2Int.up));
|
2022-05-31 11:41:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|