using Azimuth; using System; using UnitTestSharp; namespace Susurrus.UnitTests { public class ViewTests : TestFixture { public static View Standard() { return new View(new Vector(100, 50), 10); } public class CtorTests : TestFixture { public void KeepsTheCenterAndHalfWidth() { View view = Standard(); CheckEqual(100.0, view.Center.X.Value); CheckEqual(50.0, view.Center.Y.Value); CheckEqual(10.0, view.HalfWidth.Value); } public void AHalfWidthOfZero_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new View(Vector.Zero, 0); } public void ANegativeHalfWidth_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new View(Vector.Zero, -1); } public void AnInfiniteHalfWidth_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new View(Vector.Zero, double.PositiveInfinity); } public void ACenterThatIsNotANumber_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); new View(Vector.NaN, 10); } } public class CheckPositionTests : TestFixture { public void AFinitePosition_Passes() { View.CheckPosition(new Vector(-5, 1e9), "position"); } public void ANaNCoordinate_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); View.CheckPosition(new Vector(0, double.NaN), "position"); } public void AnInfiniteCoordinate_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); View.CheckPosition(new Vector(double.NegativeInfinity, 0), "position"); } } public class PanOfTests : TestFixture { public void TheCenter_IsInTheMiddle() { CheckEqual(0.0, Standard().PanOf(new Vector(100, 50)).Value); } public void HalfAHalfWidthToTheRight_IsHalfwayRight() { CheckEqual(0.5, Standard().PanOf(new Vector(105, 50)).Value); } public void HalfAHalfWidthToTheLeft_IsHalfwayLeft() { CheckEqual(-0.5, Standard().PanOf(new Vector(95, 50)).Value); } public void TheRightEdge_IsAllTheWayRight() { CheckEqual(1.0, Standard().PanOf(new Vector(110, 50)).Value); } public void BeyondTheRightEdge_StaysAllTheWayRight() { CheckEqual(1.0, Standard().PanOf(new Vector(1000, 50)).Value); } public void BeyondTheLeftEdge_StaysAllTheWayLeft() { CheckEqual(-1.0, Standard().PanOf(new Vector(-1000, 50)).Value); } public void Height_MakesNoDifference() { CheckEqual(0.0, Standard().PanOf(new Vector(100, 5000)).Value); } public void APositionThatIsNotANumber_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Standard().PanOf(Vector.NaN); } } public class DistanceToTests : TestFixture { public void TheCenter_IsZero() { CheckEqual(0.0, Standard().DistanceTo(new Vector(100, 50)).Value); } public void IsStraightLine_AcrossBothAxes() { CheckEqual(5.0, Standard().DistanceTo(new Vector(103, 54)).Value); } public void APositionThatIsNotANumber_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Standard().DistanceTo(Vector.NaN); } } } }