Beispiel #1
0
        /// <summary>
        /// If the calling DirectionEnum has more than one flag set, then verify that his directions are actually possible (cannot got upright if there is an obstacle on up OR right)
        /// </summary>
        /// <param name="direction">calling object</param>
        /// <param name="toCompare">possible directions (up, right, down, left) set to 1 if particular direction is possible</param>
        /// <returns>true if monodirectional or possible multidirectional. False if not possible multidirectional.</returns>
        public static bool IsPossibleDirection(this DirectionEnum direction, DirectionEnum toCompare)
        {
            if (!direction.HasMoreThan1Direction())
            {
                return(true);
            }

            if ((toCompare & direction) == direction)
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public void Direction_MonodirectionalShouldBeDetected()
        {
            //Arrange
            DirectionEnum down  = DirectionEnum.Down,
                          up    = DirectionEnum.Up,
                          right = DirectionEnum.Right,
                          left  = DirectionEnum.Left;
            //Act
            var testDown  = down.HasMoreThan1Direction();
            var testUp    = up.HasMoreThan1Direction();
            var testRight = right.HasMoreThan1Direction();
            var testLeft  = left.HasMoreThan1Direction();

            //Assert
            Assert.False(testDown | testUp | testRight | testLeft);
        }
Beispiel #3
0
        public void Direction_BidirectionShouldBeDetected()
        {
            //Arrange
            DirectionEnum down_left  = (DirectionEnum.Down | DirectionEnum.Left),
                          up_right   = (DirectionEnum.Up | DirectionEnum.Right),
                          down_right = (DirectionEnum.Down | DirectionEnum.Right),
                          up_left    = (DirectionEnum.Up | DirectionEnum.Left);
            //Act
            var testDownLeft  = down_left.HasMoreThan1Direction();
            var testUpRight   = up_right.HasMoreThan1Direction();
            var testDownRight = down_right.HasMoreThan1Direction();
            var testUpLeft    = up_left.HasMoreThan1Direction();

            //Assert
            Assert.True(testDownLeft & testUpRight & testDownRight & testUpLeft);
        }