Skip to content

Commit

Permalink
Few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyzxs committed Feb 10, 2018
1 parent b525cad commit 0a684e4
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
3 changes: 3 additions & 0 deletions BattleShipMicro/BattleShipMicro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

53 changes: 35 additions & 18 deletions BattleShipMicro/BattleShipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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);
}
}
3 changes: 3 additions & 0 deletions BattleShipMicro/IResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace BattleShipMicro {
public interface IResult { }
}
6 changes: 6 additions & 0 deletions BattleShipMicro/IShip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BattleShipMicro {
public interface IShip
{
IResult At(int horzCoord, int vertCoord);
}
}
9 changes: 9 additions & 0 deletions BattleShipMicro/Result.cs
Original file line number Diff line number Diff line change
@@ -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.