Ejemplo n.º 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));
                    }
                }
            }
        }
Ejemplo n.º 2
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));
         }
     }
 }
Ejemplo n.º 3
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));
             }
         }
     }
 }