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)); } } } }
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)); }
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)); }
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)); } } }
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)); } } } }
public void TestFieldValuesOfShipLengthZero() { Assert.ThrowsException <ArgumentOutOfRangeException>( () => BimaruValues.FieldValuesOfShip(Direction.RIGHT, 0).GetEnumerator().MoveNext()); }