using System; using Chernobyl.Mathematics.Measures; using Chernobyl.Mathematics.Vectors; using NUnit.Framework; namespace Chernobyl.Mathematics.Movement { /// /// Tests for the type. /// public class CellTransformTests { //----------------------------------------------------------------- // CellTransform Constructor Argument Set Tests //----------------------------------------------------------------- [Test, Description("A test which ensures the CellTransform(Vector2) " + "constructor properly sets the arguments given to it.")] public void ConstructorVector2ArgumentsProperlySet() { Vector2 cellSize = new Vector2(10, 10); CellTransform cellTransform = new CellTransform(cellSize); Assert.AreEqual(cellSize, cellTransform.CellSize, "The CellTransform.CellSize value is not what was expected."); } //----------------------------------------------------------------- // CellTransform(Vector2) ArgumentOutOfRangeException Tests //----------------------------------------------------------------- // ReSharper disable ObjectCreationAsStatement [Test, Description("A test which ensures the CellTransform(Vector2) " + "constructor throws an ArgumentOutOfRangeException when the Vector2.X " + "of its first argument is less than 0.")] public void ConstructorVector2VectorXLessThanZeroException() { var cellSize = new Vector2(-0.1f, 1); Assert.Throws(() => new CellTransform(cellSize)); } [Test, Description("A test which ensures the CellTransform(Vector2) " + "constructor throws an ArgumentOutOfRangeException when the Vector2.X " + "of its first argument is equal to 0.")] public void ConstructorVector2VectorXEqualToZeroException() { var cellSize = new Vector2(0, 1); Assert.Throws(() => new CellTransform(cellSize)); } [Test, Description("A test which ensures the CellTransform(Vector2) " + "constructor throws an ArgumentOutOfRangeException when the Vector2.Y " + "of its first argument is less than 0.")] public void ConstructorVector2VectorYLessThanZeroException() { var cellSize = new Vector2(1, 0); Assert.Throws(() => new CellTransform(cellSize)); } [Test, Description("A test which ensures the CellTransform(Vector2) " + "constructor throws an ArgumentOutOfRangeException when the Vector2.X " + "of its first argument is equal to 0.")] public void ConstructorVector2VectorYEqualToZeroException() { var cellSize = new Vector2(1, -0.1f); Assert.Throws(() => new CellTransform(cellSize)); } // ReSharper restore ObjectCreationAsStatement //----------------------------------------------------------------- // Transform Positioning Tests //----------------------------------------------------------------- [Test, Description("A test that ensures the CellTransform positions " + "properly when set and when the CellTransform is not parented.")] public void TransformPositionsProperlyWhenNotParented() { CellTransform cellTransform = new CellTransform(new Vector2(10, 10)); cellTransform.Position = new Vector3(24, 16, 0); Assert.AreEqual(new Vector2(25, 15), cellTransform.Position.Xy, "The CellTransform was not at the expected position."); Assert.AreEqual(new RowColumn(1, 2), cellTransform.Cell, "The CellTransform was not in the expected cell."); } [Test, Description("A test that ensures the CellTransform positions " + "properly when set and when the CellTransform is parented.")] public void TransformPositionsProperlyWhenParented() { ITransform parent = new MatrixTransform(); parent.Translate(24, 16); CellTransform cellTransform = new CellTransform(new Vector2(10, 10)); Transform.MakeParentChild(parent, cellTransform); Assert.AreEqual(new Vector2(25, 15), cellTransform.Position.Xy, "The CellTransform was not at the expected position."); Assert.AreEqual(new RowColumn(1, 2), cellTransform.Cell, "The CellTransform was not in the expected cell."); } [Test, Description("A test that ensures the CellTransform positions " + "properly after it has been move only a slight amount inside the cell " + "its in.")] public void TransformPositionsProperlyWhenMovedSlightly() { CellTransform cellTransform = new CellTransform(new Vector2(10, 10)); cellTransform.Position = new Vector3(24, 16, 0); Assert.AreEqual(new Vector2(25, 15), cellTransform.Position.Xy, "The CellTransform was not at the expected position."); Assert.AreEqual(new RowColumn(1, 2), cellTransform.Cell, "The CellTransform was not in the expected cell."); cellTransform.Position = new Vector3(23, 17, 0); Assert.AreEqual(new Vector2(25, 15), cellTransform.Position.Xy, "The CellTransform was not at the expected position."); Assert.AreEqual(new RowColumn(1, 2), cellTransform.Cell, "The CellTransform was not in the expected cell."); } } }