Skip to content
Permalink
Browse files

Few more tests

  • Loading branch information...
Fyzxs committed Feb 10, 2018
1 parent b525cad commit 0a684e495bd9da84e62fd84d6dfbd63aaf03c3bf
@@ -60,8 +60,11 @@
<ItemGroup>
<Compile Include="BattleShipTests.cs" />
<Compile Include="IOrientation.cs" />
<Compile Include="IResult.cs" />
<Compile Include="IShip.cs" />
<Compile Include="Orientation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Result.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -11,15 +11,13 @@ public class BattleShipTests
[TestMethod]
public void AircraftCarrierHorizontal()
{
//Create an aircraft carrier at zero, zero horizontally
IShip subject = new AircraftCarrier(0, 0, Orientation.Horizontal);

Approvals.Verify(subject);
}
[TestMethod]
public void AircraftCarrierVerical()
{
//Create an aircraft carrier at zero, zero horizontally
IShip subject = new AircraftCarrier(0, 0, Orientation.Vertical);

Approvals.Verify(subject);
@@ -29,22 +27,45 @@ public void AircraftCarrierVerical()
[TestMethod]
public void AircraftCarrierReturnsSpecifiedIndicatorForBeingAtPoint()
{
//Create an aircraft carrier at zero, zero horizontally
IShip subject = new AircraftCarrier(0, 0, Orientation.Horizontal);
IResult result = subject.At(0, 0);
Approvals.Verify(result);
}
[TestMethod]
public void AircraftCarrierReturnsSpecifiedIndicatorForNotBeingAtPoint()
{
IShip subject = new AircraftCarrier(0, 0, Orientation.Horizontal);
IResult result = subject.At(1, 1);
Approvals.Verify(result);
}
[TestMethod]
public void AircraftCarrierReturnsSpecifiedIndicatorForHorizontalLessThanPoint()
{
IShip subject = new AircraftCarrier(1, 0, Orientation.Horizontal);
IResult result = subject.At(0, 1);
Approvals.Verify(result);
}
[TestMethod]
public void AircraftCarrierReturnsSpecifiedIndicatorForHorizontalHigherThanPoint()
{
IShip subject = new AircraftCarrier(1, 0, Orientation.Horizontal);
IResult result = subject.At(10, 1);
Approvals.Verify(result);
}

}

public interface IResult { }

public class AircraftCarrier : IShip
{
private const int _size = 5;
private readonly int _horzCoord;
private readonly int _vertCoord;
private readonly IOrientation _orientation;

public AircraftCarrier(int horzCoord, int vertCoord, IOrientation orientation)
{
_horzCoord = horzCoord;
_vertCoord = vertCoord;
_orientation = orientation;
}

@@ -55,20 +76,16 @@ public override string ToString()

public IResult At(int horzCoord, int vertCoord)
{
if (_orientation.IsHorizontal())
{
if (horzCoord < _horzCoord)
return new Result("");
if (_horzCoord + _size <= horzCoord)
return new Result("");
if (vertCoord != _vertCoord)
return new Result("");
}
return new Result("A");
}
}

public class Result : IResult
{
private readonly string _result;

public Result(string result) => _result = result;
public override string ToString() => _result;
}

public interface IShip
{
IResult At(int horzCoord, int vertCoord);
}
}
@@ -0,0 +1,3 @@
namespace BattleShipMicro {
public interface IResult { }
}
@@ -0,0 +1,6 @@
namespace BattleShipMicro {
public interface IShip
{
IResult At(int horzCoord, int vertCoord);
}
}
@@ -0,0 +1,9 @@
namespace BattleShipMicro {
public class Result : IResult
{
private readonly string _result;

public Result(string result) => _result = result;
public override string ToString() => _result;
}
}

0 comments on commit 0a684e4

Please sign in to comment.
You can’t perform that action at this time.