示例#1
0
        public void TestCompatibilityStartEnd()
        {
            var startEndShipFields =
                new BimaruValue[]
            {
                BimaruValue.SHIP_CONT_DOWN,
                BimaruValue.SHIP_CONT_LEFT,
                BimaruValue.SHIP_CONT_RIGHT,
                BimaruValue.SHIP_CONT_UP
            };

            foreach (Direction direction in Directions.GetNonDiagonalDirections())
            {
                foreach (BimaruValue value in startEndShipFields)
                {
                    foreach (BimaruValue neighbourValue in BimaruValues.AllBimaruValues())
                    {
                        bool isValidShipContinuation =
                            neighbourValue == BimaruValue.SHIP_MIDDLE ||
                            neighbourValue == BimaruValue.SHIP_UNDETERMINED ||
                            neighbourValue == BimaruValue.UNDETERMINED ||
                            neighbourValue == direction.GetLastShipValue();

                        bool shouldBeCompatible =
                            (value != direction.GetFirstShipValue() && !neighbourValue.IsShip()) ||
                            (value == direction.GetFirstShipValue() && isValidShipContinuation);

                        Assert.AreEqual(shouldBeCompatible, value.IsCompatibleWith(direction, neighbourValue));
                        Assert.AreEqual(shouldBeCompatible, neighbourValue.IsCompatibleWith(direction.GetOpposite(), value));
                    }
                }
            }
        }
示例#2
0
        public void TestFieldValuesOfShipLengthTwo()
        {
            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_CONT_RIGHT,
                BimaruValue.SHIP_CONT_LEFT
            },
                BimaruValues.FieldValuesOfShip(Direction.RIGHT, 2));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_CONT_LEFT,
                BimaruValue.SHIP_CONT_RIGHT
            },
                BimaruValues.FieldValuesOfShip(Direction.LEFT, 2));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_CONT_UP,
                BimaruValue.SHIP_CONT_DOWN
            },
                BimaruValues.FieldValuesOfShip(Direction.UP, 2));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_CONT_DOWN,
                BimaruValue.SHIP_CONT_UP
            },
                BimaruValues.FieldValuesOfShip(Direction.DOWN, 2));
        }
示例#3
0
        public void TestFieldValuesOfShipLengthOne()
        {
            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_SINGLE
            },
                BimaruValues.FieldValuesOfShip(Direction.RIGHT, 1));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_SINGLE
            },
                BimaruValues.FieldValuesOfShip(Direction.LEFT, 1));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_SINGLE
            },
                BimaruValues.FieldValuesOfShip(Direction.UP, 1));

            AssertEqualFieldValues(
                new List <BimaruValue>()
            {
                BimaruValue.SHIP_SINGLE
            },
                BimaruValues.FieldValuesOfShip(Direction.DOWN, 1));
        }
示例#4
0
 public void TestCompatibilitySingleShip()
 {
     foreach (Direction direction in Directions.GetAllDirections())
     {
         foreach (BimaruValue value in BimaruValues.AllBimaruValues())
         {
             // Single ships are incompatible with any ship neighbours
             bool shouldBeCompatible = !value.IsShip();
             Assert.AreEqual(shouldBeCompatible, BimaruValue.SHIP_SINGLE.IsCompatibleWith(direction, value));
             Assert.AreEqual(shouldBeCompatible, value.IsCompatibleWith(direction, BimaruValue.SHIP_SINGLE));
         }
     }
 }
示例#5
0
 public void TestCompatibilityDiagonal()
 {
     foreach (Direction direction in Directions.GetDirections(DirectionType.DIAGONAL))
     {
         foreach (BimaruValue value in BimaruValues.AllBimaruValues())
         {
             foreach (BimaruValue neighbourValue in BimaruValues.AllBimaruValues())
             {
                 // Ship fields are incompatible with neighbour ship fields at the diagonal
                 bool shouldBeCompatible = !value.IsShip() || !neighbourValue.IsShip();
                 Assert.AreEqual(shouldBeCompatible, value.IsCompatibleWith(direction, neighbourValue));
                 Assert.AreEqual(shouldBeCompatible, neighbourValue.IsCompatibleWith(direction, value));
             }
         }
     }
 }
示例#6
0
 public void TestFieldValuesOfShipLengthZero()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(
         () => BimaruValues.FieldValuesOfShip(Direction.RIGHT, 0).GetEnumerator().MoveNext());
 }