예제 #1
0
        public async Task Walk_AllPossibleDirections_SuccessfullyPosted()
        {
            Guid mazeId = Guid.NewGuid();
            Path path   = new Path
            {
                MazeId      = mazeId,
                Source      = new Point(3, 3),
                Destination = new Point(3, 4),
                Steps       = new List <Point>
                {
                    new Point(3, 4),
                    new Point(4, 4),
                    new Point(4, 3),
                    new Point(3, 3),
                    new Point(3, 3),
                }
            };

            Mock <IPonyAPIClient> mockPonyAPI     = new Mock <IPonyAPIClient>();
            Mock <IMazeFactory>   mockMazeFactory = new Mock <IMazeFactory>();

            var directions = new List <string>();

            mockPonyAPI.Setup(m => m.PostStep(mazeId, Capture.In(directions)));
            Maze maze = CreateMaze(width: 15,
                                   height: 15,
                                   difficulty: 10,
                                   ponyPosition: new Point(-1, -1),
                                   endPoint: path.Destination,
                                   monsterPosition: new Point(10, 10)
                                   );

            maze.MazeId = mazeId;
            mockMazeFactory.Setup(m => m.FromID(mazeId)).ReturnsAsync(maze);

            mazeWalker = new MazeWalker(mockPonyAPI.Object, mockMazeFactory.Object);

            await mazeWalker.Walk(path);

            Assert.AreEqual(new[] { "south", "east", "north", "west", "stay" }, directions);
        }
예제 #2
0
        public async Task Walk_WithMonster_MonsterAvoided()
        {
            // Arrange

            /* Maze with Endpoint and Monster with this positions:
             * ----|D
             * P
             * ----
             *     |E
             *
             * For the test, the monster will only move when P is about to cross.
             */
            Maze maze = CreateMaze(width: 15,
                                   height: 15,
                                   difficulty: 10,
                                   ponyPosition: new Point(1, 2),
                                   endPoint: new Point(5, 3),
                                   monsterPosition: new Point(5, 1),
                                   walls: new List <Point>
            {
                new Point(2, 1),
                new Point(2, 3),
                new Point(3, 1),
                new Point(3, 3),
                new Point(4, 1),
                new Point(4, 3),
                new Point(5, 0),
                new Point(5, 4),
            }
                                   );
            Path path = new Path
            {
                MazeId      = maze.MazeId,
                Source      = maze.Pony.Position,
                Destination = maze.EndPoint,
                Steps       = new List <Point>
                {
                    new Point(2, 2),
                    new Point(3, 2),
                    new Point(4, 2),
                    new Point(5, 2),
                    new Point(5, 3),
                }
            };

            Mock <IPonyAPIClient> mockPonyAPI    = new Mock <IPonyAPIClient>();
            Point monsterRightOfPony             = new Point(maze.Domokun.Position.X, maze.Domokun.Position.Y + 1);
            Point monsterOnTopOfPony             = new Point(maze.Domokun.Position.X - 1, maze.Domokun.Position.Y + 1);
            Point monsterLeftOfPony              = new Point(maze.Domokun.Position.X - 2, maze.Domokun.Position.Y + 1);
            MovingMonsterMazeFactory mazeFactory = new MovingMonsterMazeFactory(maze, new List <Point>
            {
                maze.Domokun.Position,
                maze.Domokun.Position,
                maze.Domokun.Position,
                maze.Domokun.Position,
                // Domokun starts walking
                monsterRightOfPony,
                monsterOnTopOfPony,
                // Domokun goes back, pony shoud wait more
                monsterRightOfPony,
                monsterOnTopOfPony,
                // Domokun goes past the pony
                monsterLeftOfPony,
                monsterLeftOfPony,
                monsterLeftOfPony,
            });

            var directions = new List <string>();

            mockPonyAPI.Setup(m => m.PostStep(maze.MazeId, Capture.In(directions)));

            mazeWalker = new MazeWalker(mockPonyAPI.Object, mazeFactory);

            // Act
            await mazeWalker.Walk(path);

            // Assert
            Assert.AreEqual(new[] { "east", "east", "east", "stay", "stay", "stay", "stay", "stay", "east", "south" }, directions);
        }