Example #1
0
        public void GetLongestRoadTest(IEnumerable<EdgeCoordinate> coordinates, int expectedResult)
        {
            var board = new Board(builder);
            var player1 = new Mock<IPlayer>();
            player1.Setup(p => p.HasResources(Establishment.BUILD_RESOURCES)).Returns(true);
            //Carefull with setup, all roads should be connected to those 2 establishments
            var vertex1 = builder.Vertices.First(t => t.X == 0 && t.Y == 0 && t.Side == VertexTileSide.Left);
            var vertex2 = builder.Vertices.First(t => t.X == 2 && t.Y == 0 && t.Side == VertexTileSide.Left);
            board.BuildEstablishment(vertex1, player1.Object);
            board.BuildEstablishment(vertex2, player1.Object);

            foreach (var coordinate in coordinates)
            {
                var edge = board.FindEdge(coordinate.X, coordinate.Y, coordinate.Side);
                board.BuildRoad(edge, player1.Object);
            }

            var result = board.GetLongestRoad(player1.Object);
            Assert.Equal(expectedResult, result.Count());
        }
Example #2
0
        public void BuildRoadFailIfEdgeIsBetweenSeaTiles()
        {
            var board = new Board(builder);
            var player = new Mock<IPlayer>();
            player.Setup(p => p.HasResources(Establishment.BUILD_RESOURCES)).Returns(true);


            var vertex = board.Vertices.First(v =>
            {
                var tiles = board.Tiles.Where(t => t.IsAdjacentTo(v));
                return tiles.Count() == 3 && tiles.Count(t => t.Rawmaterial == MaterialType.Sea) == 2;
            });
            var edge = board.Edges.First(e => board.Tiles.Where(t => t.IsAdjacentTo(e)).All(t => t.Rawmaterial == MaterialType.Sea));

            board.BuildEstablishment(vertex, player.Object);
            Assert.Throws<ArgumentException>(() => board.BuildRoad(edge, player.Object));
        }
Example #3
0
        public void BuildRoadFailIfEdgeNotOnBoard()
        {
            var board = new Board(builder);
            var player = new Mock<IPlayer>();
            player.Setup(p => p.HasResources(Establishment.BUILD_RESOURCES)).Returns(true);

            var edge = new Mock<IEdge>();
            edge.Setup(e => e.X).Returns(0);
            edge.Setup(e => e.Y).Returns(0);
            edge.Setup(e => e.Side).Returns(EdgeSide.West);
            var vertex = board.Vertices.First(v => v.X == 0 && v.Y == 0 && v.Side == VertexTileSide.Left);

            board.BuildEstablishment(vertex, player.Object);
            Assert.Throws<ArgumentException>(() => board.BuildRoad(edge.Object, player.Object));
        }
Example #4
0
        public void BuildRoadFailsIfAdjcanentEstablismentFromDifferentPlayer()
        {
            var board = new Board(builder);
            var player1 = new Mock<IPlayer>();
            var player2 = new Mock<IPlayer>();
            player2.Setup(p => p.HasResources(Establishment.BUILD_RESOURCES)).Returns(true);

            var edge = board.Edges.First(e => e.X == 0 && e.Y == 0 && e.Side == EdgeSide.West);
            var vertex = board.Vertices.First(v => v.X == 0 && v.Y == 0 && v.Side == VertexTileSide.Left);

            board.BuildEstablishment(vertex, player2.Object);
            Assert.Throws<ArgumentException>(() => board.BuildRoad(edge, player1.Object));
        }
Example #5
0
        public void BuildRoadSuccesIfAdjcentToDifferentPlayerRoad()
        {
            var board = new Board(builder);
            var player = new Mock<IPlayer>();
            player.Setup(p => p.HasResources(Establishment.BUILD_RESOURCES)).Returns(true);


            var edge1 = board.Edges.First(e => e.X == 0 && e.Y == 0 && e.Side == EdgeSide.West);
            var edge2 = board.Edges.First(e => e.X == -1 && e.Y == 1 && e.Side == EdgeSide.East);
            var vertex = board.Vertices.First(v => v.X == 0 && v.Y == 0 && v.Side == VertexTileSide.Left);

            board.BuildEstablishment(vertex, player.Object);
            board.BuildRoad(edge1, player.Object);

            var road = board.BuildRoad(edge2, player.Object);

            Assert.Contains(road, board.Roads);
            Assert.NotNull(road);
            Assert.Equal(edge2, road.Edge);
            Assert.Equal(player.Object, road.Owner);
        }
Example #6
0
        public void BuildRoadFailsIfNoAdjacentEdgesOrEstablismentsOfThePlayer()
        {
            var board = new Board(builder);
            var player = new Mock<IPlayer>();
            var edge = board.Edges.First(e => e.X == 0 && e.Y == 0 && e.Side == EdgeSide.West);

            Assert.Throws<ArgumentException>(() => board.BuildRoad(edge, player.Object));
        }
Example #7
0
        public void BuildRoadNullOwnerException()
        {
            var board = new Board(builder);
            var edge = board.Edges.First(e => e.X == 0 && e.Y == 0);

            Assert.Throws<ArgumentNullException>(() => board.BuildRoad(edge, null));
        }
Example #8
0
        public void BuildRoadNullEdgeException()
        {
            var board = new Board(builder);
            var player = new Mock<IPlayer>();

            Assert.Throws<ArgumentNullException>(() => board.BuildRoad(null, player.Object));
        }