public Adventurer(IMap map, MapAdventurerEntry adventurerEntry) { this.map = map; this.movements = new Queue <char>(adventurerEntry.Movements.ToCharArray()); this.Orientation = adventurerEntry.Orientation; this.Name = adventurerEntry.Name; }
public void SimpleMapOneAdventurer_Move_ChangeTheOrientationToWest() { string initialOrientation = "N"; string expectedOrientation = "O"; string movements = "D"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedOrientation)); }
public void AdventurerWithOneAction_HasAction_ReturnsFalseAfterOneMoveCall() { MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "name", "0", "0", "O", "D" }); Adventurer adventurer = new Adventurer(null, adventurerEntry); bool initialHasAction = adventurer.HasAction; adventurer.Move(); bool finalHasAction = adventurer.HasAction; Assert.That(initialHasAction, Is.True); Assert.That(finalHasAction, Is.False); }
public void BuildMapWithAnAdventurer_GetMap_ReturnsAMap() { string expectedCellType = "A"; int expectedXCoordinate = 2; int expectedYCoordinate = 3; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", expectedXCoordinate.ToString(), expectedYCoordinate.ToString(), string.Empty, string.Empty }); MapBuilder builder = new MapBuilder(new MapSizeEntry("C", new[] { "5", "5" })); builder.AddEntries(new[] { adventurerEntry }); Map result = builder.GetMap(); Assert.That(result, Is.Not.Null); Assert.That(result.GetCellType(expectedXCoordinate, expectedYCoordinate), Is.EqualTo(expectedCellType)); }
public void SimpleMapOneAdventurerOneMoveRightOneMoveLeft_Move_DontChangeOrientation() { string initialOrientation = "S"; string expectedIntermediateOrientation = "E"; string expectedFinalOrientation = "S"; string movements = "DG"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedIntermediateOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFinalOrientation)); }
public void SimpleMapOneAdventurerValidateMovingCommand_Move_VerifyThatMapMoveAdventurerIsCalledToWest() { string adventurerName = "adv"; string initialOrientation = "O"; string initialXAdventurer = "1"; string initialYAdventurer = "1"; string adventurerMovements = "A"; int expectedXStep = 1; int expectedYStep = 0; Mock <IMap> mapMock = new Mock <IMap>(); IMap map = mapMock.Object; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { adventurerName, initialXAdventurer, initialYAdventurer, initialOrientation, adventurerMovements }); Adventurer adventurer = new Adventurer(map, adventurerEntry); mapMock.Setup(m => m.MoveAdventurer(adventurerName, expectedXStep, expectedYStep)); adventurer.Move(); mapMock.Verify(m => m.MoveAdventurer(adventurerName, expectedXStep, expectedYStep), Times.Once); }
public void SimpleMapOneAdventurerValidateLeftCommandOnAllOrientation_Move_RotateToLeft() { string initialOrientation = "N"; string expectedSecondOrientation = "E"; string expectedThirdOrientation = "S"; string expectedFourthOrientation = "O"; string expectedFinalOrientation = "N"; string movements = "GGGG"; MapAdventurerEntry adventurerEntry = new MapAdventurerEntry("A", new[] { "Name", "0", "0", initialOrientation, movements }); Adventurer adventurer = new Adventurer(null, adventurerEntry); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedSecondOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedThirdOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFourthOrientation)); adventurer.Move(); Assert.That(adventurer.Orientation, Is.EqualTo(expectedFinalOrientation)); }