public void ReturnTrue_ComparingWithSameXAndY() { var ship1 = new PatrolBoat(x: 1, y: 2); var ship2 = new PatrolBoat(x: 1, y: 2); Assert.AreEqual(ship1, ship2); }
public void ReturnTrue_ComparingWithSameDirection() { var ship1 = new PatrolBoat(x: 1, y: 2, direction: Direction.Vertical); var ship2 = new PatrolBoat(x: 1, y: 2, direction: Direction.Vertical); Assert.AreEqual(ship1, ship2); }
public void ReturnTrue_ComparingWithDifferentDirectionsAndLength1() { var ship1 = new PatrolBoat(x: 1, y: 2, direction: Direction.Horizontal); var ship2 = new PatrolBoat(x: 1, y: 2, direction: Direction.Vertical); Assert.AreEqual(ship1, ship2); }
public void ReturnFalse_ComparingWithDifferentLength() { var ship1 = new PatrolBoat(x: 1, y: 2); var ship2 = new Cruiser(x: 1, y: 2); Assert.AreNotEqual(ship1, ship2); }
public void ReturnFalse_ComparingDifferentXAndY() { var ship1 = new PatrolBoat(x: 1, y: 2); var ship2 = new PatrolBoat(x: 2, y: 2); var ship3 = new PatrolBoat(x: 1, y: 1); Assert.AreNotEqual(ship1, ship2); Assert.AreNotEqual(ship1, ship3); }
public Ship Parse(string notation) { if (notation == null) throw new ArgumentException(); var pattern = @"^([A-J])(10|[1-9])(x[1-4])?(-|\|)?$"; var regEx = new Regex(pattern); var match = regEx.Match(notation); if (!match.Success) throw new NotAShipException(); uint x = (uint)(match.Groups[1].Value[0] - 'A' + 1); uint y = uint.Parse(match.Groups[2].Value); var direction = Direction.Horizontal; switch (match.Groups[4].Value) { case "-": direction = Direction.Horizontal; break; case "|": direction = Direction.Vertical; break; } Ship result = null; switch (match.Groups[3].Value) { case "": case "x1": result = new PatrolBoat(x, y, direction); break; case "x2": result = new Cruiser(x, y, direction); break; case "x3": result = new Submarine(x, y, direction); break; case "x4": result = new AircraftCarrier(x, y, direction); break; } return result; }