using System; using UnitTestSharp; namespace Annulus.UnitTests { public class HexDirectionsTests : TestFixture { public class CountTests : TestFixture { public void IsSix() { CheckEqual(6, HexDirections.Count); } public void MatchesTheNumberOfMembersInBothEnums() { CheckEqual(HexDirections.Count, Enum.GetValues(typeof(PointyHexDirection)).Length); CheckEqual(HexDirections.Count, Enum.GetValues(typeof(FlatHexDirection)).Length); } } public class ValidateTests : TestFixture { public void EachOfTheSixNumbers_Passes() { for (int direction = 0; direction < HexDirections.Count; ++direction) { HexDirections.Validate(direction, "direction"); } } public void NegativeNumber_ThrowsNamingTheParameter() { try { HexDirections.Validate(-1, "heading"); Check(false); } catch (ArgumentOutOfRangeException exception) { CheckEqual("heading", exception.ParamName); } } public void SixOrMore_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); HexDirections.Validate(6, "direction"); } } public class RotatedClockwiseTests : TestFixture { public void ZeroTurnsChangesNothing() { CheckEqual(4, HexDirections.RotatedClockwise(4, 0)); } public void OneSixthTurnAddsOne() { CheckEqual(3, HexDirections.RotatedClockwise(2, 1)); } public void WrapsPastTheLastDirectionBackToTheFirst() { CheckEqual(0, HexDirections.RotatedClockwise(5, 1)); } public void NegativeTurnsGoCounterclockwise() { CheckEqual(5, HexDirections.RotatedClockwise(0, -1)); } public void NegativeTurnsWrapPastTheFirstDirection() { CheckEqual(3, HexDirections.RotatedClockwise(0, -3)); } public void AFullTurnChangesNothing() { CheckEqual(2, HexDirections.RotatedClockwise(2, 6)); } public void ManyTurnsWrapInEitherDirection() { CheckEqual(1, HexDirections.RotatedClockwise(0, 61)); CheckEqual(5, HexDirections.RotatedClockwise(0, -61)); } public void NotAHexDirection_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); HexDirections.RotatedClockwise(6, 1); } } } }