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 WhenZIsOutOfRange_ThrowsArgumentOutOfRangeException() { var outOfRangeZ = _3X3Config.GetMap2DArrayHeight() + 1; const int withinRangeX = 0; void CallWithXOutOfRange() { _coordinateService.GetFlattenArrayIndexFromAxialCoordinate( withinRangeX, outOfRangeZ, _3X3Config ); } Assert.That(CallWithXOutOfRange, Throws.TypeOf <ArgumentOutOfRangeException>()); }