Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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));
        }