public int GetFlattenArrayIndexFromAxialCoordinate(int x, int z, MapConfig config) { if (x > config.GetMap2DArrayWidth() || z > config.GetMap2DArrayHeight()) { throw new ArgumentOutOfRangeException($"{x} or {z} is out of range of the given config: ${config}"); } return(z * config.GetMap2DActualWidth() + x - z % 2 - z / 2); }
public void WhenXIsOutOfRange_ThrowsArgumentOutOfRangeException() { var outOfRangeX = _3X3Config.GetMap2DArrayWidth() + 1; const int withinRangeZ = 0; void CallWithXOutOfRange() { _coordinateService.GetFlattenArrayIndexFromAxialCoordinate( outOfRangeX, withinRangeZ, _3X3Config ); } Assert.That(CallWithXOutOfRange, Throws.TypeOf <ArgumentOutOfRangeException>()); }