using System; using Dakota.Utils; using Microsoft.Xna.Framework; using NUnit.Framework; namespace DakotaTests { public class DakotaUtilTests { [SetUp] public void Setup() { } private Vector2 UpVector = new(0, -1); private Vector2 RightVector = new(1, 0); private Vector2 DownVector = new(0, 1); private Vector2 LeftVector = new(-1, 0); private const float Epsilon = 0.00001f; private const float UpAngle = 0f; private const float RightAngle = (float) Math.PI / 2f; private const float DownAngle = (float) Math.PI; private const float LeftAngle = (float) Math.PI * 1.5f; [Test] public void TestToAngle() { // going around the clock Assert.AreEqual(UpAngle, DakotaUtils.ToAngle(UpVector)); Assert.AreEqual(RightAngle, DakotaUtils.ToAngle(RightVector)); Assert.AreEqual(DownAngle, DakotaUtils.ToAngle(DownVector)); Assert.AreEqual(LeftAngle, DakotaUtils.ToAngle(LeftVector)); } [Test] public void TestFromAngle() { Assert.AreEqual(UpVector.X, DakotaUtils.VecFromAngle(UpAngle).X, Epsilon); Assert.AreEqual(UpVector.Y, DakotaUtils.VecFromAngle(UpAngle).Y, Epsilon); Assert.AreEqual(RightVector.X, DakotaUtils.VecFromAngle(RightAngle).X, Epsilon); Assert.AreEqual(RightVector.Y, DakotaUtils.VecFromAngle(RightAngle).Y, Epsilon); Assert.AreEqual(DownVector.X, DakotaUtils.VecFromAngle(DownAngle).X, Epsilon); Assert.AreEqual(DownVector.Y, DakotaUtils.VecFromAngle(DownAngle).Y, Epsilon); Assert.AreEqual(LeftVector.X, DakotaUtils.VecFromAngle(LeftAngle).X, Epsilon); Assert.AreEqual(LeftVector.Y, DakotaUtils.VecFromAngle(LeftAngle).Y, Epsilon); } } }