Exemplo n.º 1
0
        public void PositionCount()
        {
            var context   = new BoardProperties();
            var positions = new PositionFactory().Create(context);

            Assert.AreEqual(context.RowSize * context.ColSize, positions.Positions.Count());
        }
Exemplo n.º 2
0
        public void TestFactoryManagerInstance()
        {
            var mgr = PositionFactory.Get(0);

            Assert.IsNotNull(mgr);
            Assert.IsInstanceOfType(mgr, typeof(Position));
        }
Exemplo n.º 3
0
        public void WhenOpponentHasOpenThreeThenBlockIt2()
        {
            var boardString = new[]
            {
                // 23456
                "       ", // 0
                "       ", // 1
                "  X    ", // 2
                "  XO   ", // 3
                "  XXO  ", // 4
                "    O  ", // 5
                "       ", // 6
                "       ", // 7
            };

            var context   = new BoardProperties(boardString.Length, boardString[0].Length);
            var positions = new PositionFactory().Create(context);
            var board     = Utils.ParseBoard(boardString, context, positions);
            var expected  = new[] { new Position(1, 2), new Position(5, 2) };

            int count = 0;

            foreach (var aiPlayer in GetAiPlayers(context, positions, PieceType.P2))
            {
                var move = aiPlayer.MakeAMove(board);
                Assert.IsTrue(expected.Contains(move), $"Assertion failed on player {count}, whose move is {move.ToString()}.");

                count++;
            }
        }
Exemplo n.º 4
0
        public void TestFactoryDeveloperInstance()
        {
            var developer = PositionFactory.Get(1);

            Assert.IsNotNull(developer);
            Assert.IsInstanceOfType(developer, typeof(Position));
        }
Exemplo n.º 5
0
 public PositionCreateHandler(GlobalSolusindoDb db, tblM_User user, PositionValidator positionValidator, PositionFactory positionFactory, PositionQuery positionQuery, AccessControl accessControl) : base(db, user)
 {
     this.positionValidator         = positionValidator;
     this.positionFactory           = positionFactory;
     this.positionQuery             = positionQuery;
     this.positionEntryDataProvider = new PositionEntryDataProvider(db, user, accessControl, positionQuery);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Builds the components.
 /// </summary>
 private void BuildComponents()
 {
     this.frame = new Frame(this.Width, this.Height, this.FrameColor, PositionFactory.Center(), this.Border);
     this.frame.Initialise(this.GetBounds());
     this.textGraphics = new TextGraphics(this.Text, this.Font, this.TextColor, this.Width - (Gutter * 2), FontFlow.Scale, PositionFactory.Center());
     this.textGraphics.Initialise(this.GetContentBounds());
 }
Exemplo n.º 7
0
        public void IsFull()
        {
            var context        = new BoardProperties(4, 4, 5);
            var positions      = new PositionFactory().Create(context);
            var patterns       = new PatternFactory().Create();
            var matcher        = new PatternMatcher(patterns);
            var boardFactories = new IBoardFactory[]
            {
                new BoardFactory(context, positions),
                new PatternBoardFactory(context, positions, matcher)
            };

            foreach (var boardFactory in boardFactories)
            {
                IGame game = new GameFactory().CreateGame(
                    boardFactory,
                    new NextAvailablePlayer(positions),
                    new NextAvailablePlayer(positions),
                    new BasicJudge(context, positions)
                    );

                game.Start();

                foreach (var i in Enumerable.Range(0, context.RowSize * context.ColSize))
                {
                    Assert.AreEqual(game.GameStatus, GameStatus.NotEnd);
                    game.Run();
                }

                Assert.AreEqual(game.GameStatus, GameStatus.Tie);
                Assert.IsTrue(game.Board.IsFull());
            }
        }
        private static IJudge GetJudge()
        {
            var context     = new BoardProperties();
            var positions   = new PositionFactory().Create(context);
            var patternRepo = new PatternFactory().Create();

            return(new PatternJudge(positions, patternRepo, new PatternMatcher(patternRepo)));
        }
        public void Test_GetPosition_ThrowsArgumentOutOfRangeException_WhenIDIsInvalid()
        {
            // Arrange
            PositionFactory factory = new PositionFactory();

            // Act
            Position position = factory.GetPosition(999);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets the y offset of the text within the textbox.
        /// </summary>
        private void SetTextOffsetY(int offsety)
        {
            PositionProfile positionProfile = PositionFactory.TopCenter();

            positionProfile.OffsetY           = offsety;
            this.textGraphics.PositionProfile = positionProfile;
            this.textGraphics.Initialise(this.GetContentBounds());
        }
        public void TestEmpty()
        {
            var context   = new BoardProperties();
            var positions = new PositionFactory().Create(context);

            Board     board  = new Board(context);
            PieceType result = GetJudge().GetWinner(board);
            PieceType expect = PieceType.Empty;

            Assert.AreEqual(expect, result);
        }
Exemplo n.º 12
0
        public void mars_rover_move_tests_and_position_test(string startPosition, string moves, string endPosition)
        {
            Vehicle.MarsRover marsRoverVehicle = new Vehicle.MarsRover(startPosition);
            marsRoverVehicle.Move(moves);

            var position = new PositionFactory().Create(endPosition);

            marsRoverVehicle.GetPosition().Location.XCoordinate.Should().Be(position.Location.XCoordinate);
            marsRoverVehicle.GetPosition().Location.YCoordinate.Should().Be(position.Location.YCoordinate);
            marsRoverVehicle.GetPosition().Direction.Should().Be(position.Direction);
        }
Exemplo n.º 13
0
        public void Test_GetPosition_ReturnsCorrectObjectType_WhenIDIsTwo()
        {
            // Arrange
            PositionFactory factory = new PositionFactory();

            // Act
            Position position = factory.GetPosition(2);

            // Assert
            Assert.IsInstanceOfType(position, typeof(Clerk));
        }
Exemplo n.º 14
0
        public void Test_GetPosition_ReturnsCorrectObjectType_WhenIDIsThree()
        {
            // Arrange
            PositionFactory factory = new PositionFactory();

            // Act
            Position position = factory.GetPosition(3);

            // Assert
            Assert.IsInstanceOfType(position, typeof(Programmer));
        }
Exemplo n.º 15
0
        public void Movements_GivenRelativePositionsNull_Throws_ArgumentNullException()
        {
            // Arrange
            IPosition[]      relativesPosition = null;
            IPositionFactory positionFactory   = new PositionFactory();

            // Act
            Action act = () => new Movements(relativesPosition, positionFactory);

            // Assert
            Assert.Throws <ArgumentNullException>(act);
        }
Exemplo n.º 16
0
        public void Create(int x, int y)
        {
            // Arrange
            var sut = new PositionFactory();

            // Act
            var result = sut.Create(x, y);

            // Assert
            Assert.Equal(x, result.X);
            Assert.Equal(y, result.Y);
        }
Exemplo n.º 17
0
        public void Movements()
        {
            // Arrange
            IPosition[]      relativesPosition = new IPosition[0];
            IPositionFactory positionFactory   = new PositionFactory();

            // Act
            var sut = new Movements(relativesPosition, positionFactory);

            // Assert
            Assert.Equal(relativesPosition, sut.RelativePositions);
            Assert.Equal(positionFactory, sut.PositionFactory);
        }
Exemplo n.º 18
0
 /* Method that converts a Position Service to a Position Service */
 public void PositionServiceToPositionFactory(WorldObject wObji, WorldObject wObjf)
 {
     if (wObji.ContainService(typeof(PositionService)))
     {
         PositionService pos     = (PositionService)wObji.GetService(typeof(PositionService));
         PositionFactory posFact = new PositionFactory();
         posFact.position  = pos.position;
         posFact.rotation  = pos.rotation;
         posFact.reference = pos.reference;
         /* Save the factory in the object builder list */
         wObjf.objectBuilder.Add(posFact);
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Builds the components.
        /// </summary>
        private void BuildComponents()
        {
            this.defaultImageGraphics = new ImageGraphics(this.Texture, PositionFactory.Center());
            this.defaultImageGraphics.Initialise(this.GetBounds());

            if (this.HoverTexture != null)
            {
                this.hoverImageGraphics = new ImageGraphics(this.HoverTexture, PositionFactory.Center());
                this.hoverImageGraphics.Initialise(this.GetBounds());
            }

            this.imageGraphics = this.defaultImageGraphics;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Builds the components.
        /// </summary>
        private void BuildComponents()
        {
            int textMaxWidth = this.Width - (Gutter * 2);

            if (this.Border != null && this.Border.Width > 0)
            {
                textMaxWidth -= this.Border.Width * 2;
            }

            this.frame = new Frame(this.Width, this.Height, Color.Cyan, PositionFactory.Center(), this.Border);
            this.frame.Initialise(this.GetBounds());
            this.textGraphics = new TextGraphics(this.Text, this.Font, Color.Yellow, textMaxWidth, FontFlow.Wrap, PositionFactory.TopCenter());
            this.textGraphics.Initialise(this.GetContentBounds());
        }
Exemplo n.º 21
0
        public void DeepClone()
        {
            var context   = new BoardProperties();
            var positions = new PositionFactory().Create(context);

            Board board  = new Board(context);
            var   board2 = (Board)board.DeepClone();

            board2.Set(new Position(0, 0), PieceType.P1);

            // Assert
            Assert.AreEqual(PieceType.P1, board2.Get(new Position(0, 0)));
            Assert.AreEqual(PieceType.Empty, board.Get(new Position(0, 0)));
        }
Exemplo n.º 22
0
        public void Create_PositionFactoryNull_Throws_ArgumentNullException()
        {
            // Arrange
            IPosition[]     relativePositions = new IPosition[0];
            PositionFactory positionFactory   = null;

            var sut = new MovementsFactory();

            // Act
            Action act = () => sut.Create(relativePositions, positionFactory);

            // Assert
            Assert.Throws <ArgumentNullException>(act);
        }
Exemplo n.º 23
0
        public void Create()
        {
            // Arrange
            var relativePositions = new IPosition[0];
            var positionFactory   = new PositionFactory();

            var sut = new MovementsFactory();

            // Act
            var result = sut.Create(relativePositions, positionFactory);

            // Assert
            Assert.Equal(relativePositions, result.RelativePositions);
            Assert.Equal(positionFactory, result.PositionFactory);
        }
        public void TestRow1()
        {
            var context   = new BoardProperties();
            var positions = new PositionFactory().Create(context);

            Board board = new Board(context);

            board.Set(new Position(3, 3), PieceType.P1);
            board.Set(new Position(3, 4), PieceType.P1);
            board.Set(new Position(3, 5), PieceType.P1);
            board.Set(new Position(3, 6), PieceType.P1);
            board.Set(new Position(3, 7), PieceType.P1);
            PieceType result = GetJudge().GetWinner(board);
            PieceType expect = PieceType.P1;

            Assert.AreEqual(expect, result);
        }
        public void TestD24()
        {
            var       context   = new BoardProperties();
            var       positions = new PositionFactory().Create(context);
            Board     board     = new Board(context);
            PieceType result;
            PieceType expect;

            board.Set(new Position(6, 10), PieceType.P1);
            board.Set(new Position(7, 9), PieceType.P1);
            board.Set(new Position(8, 8), PieceType.P1);
            board.Set(new Position(9, 7), PieceType.P2);
            board.Set(new Position(10, 6), PieceType.P1);
            result = GetJudge().GetWinner(board);
            expect = PieceType.Empty;
            Assert.AreEqual(expect, result);
        }
        public void TestD22()
        {
            var       context   = new BoardProperties();
            var       positions = new PositionFactory().Create(context);
            Board     board     = new Board(context);
            PieceType result;
            PieceType expect;

            board.Set(new Position(0, 5), PieceType.P1);
            board.Set(new Position(1, 4), PieceType.P1);
            board.Set(new Position(2, 3), PieceType.P1);
            board.Set(new Position(3, 2), PieceType.P2);
            board.Set(new Position(4, 1), PieceType.P1);
            result = GetJudge().GetWinner(board);
            expect = PieceType.Empty;
            Assert.AreEqual(expect, result);
        }
Exemplo n.º 27
0
        private static void GetMovements_Test(
            IPosition[] expectedResult,
            Position position,
            IPosition[] relativePositions,
            int minX = int.MinValue, int minY = int.MinValue,
            int maxX = int.MaxValue, int maxY = int.MaxValue)
        {
            // Arrange
            var positionFactory = new PositionFactory();

            var sut = new Movements(relativePositions, positionFactory);

            // Act
            var result = sut.GetMovements(position, minX, minY, maxX, maxY)
                         .ToArray();

            // Assert
            Assert.Equal(expectedResult, result);
        }
 /// <summary>
 /// 转换为岗位实体
 /// </summary>
 /// <param name="dto">岗位数据传输对象</param>
 public static Position ToEntity3(this PositionDto dto)
 {
     if (dto == null)
     {
         return(new Position());
     }
     return(PositionFactory.Create(
                postId: dto.Id.ToGuid(),
                name: dto.Name,
                isEnabled: dto.IsEnabled,
                sortId: dto.SortId,
                creationTime: dto.CreationTime,
                creatorId: dto.CreatorId,
                lastModificationTime: dto.LastModificationTime,
                lastModifierId: dto.LastModifierId,
                isDeleted: dto.IsDeleted,
                merchantId: dto.MerchantId,
                version: dto.Version
                ));
 }
Exemplo n.º 29
0
        public void TestDiagonalIndexes()
        {
            var b         = new BoardProperties();
            var positions = new PositionFactory().Create(b);

            var d1Lines = positions.LineGroups[LineType.DiagonalOne];

            foreach (var p in positions.Positions)
            {
                int index = positions.GetDiagonalOneIndex(p);
                Assert.IsTrue(d1Lines.Lines[index].Positions.Contains(p));
            }

            var d2Lines = positions.LineGroups[LineType.DiagonalTwo];

            foreach (var p in positions.Positions)
            {
                int index = positions.GetDiagonalTwoIndex(p);
                Assert.IsTrue(d2Lines.Lines[index].Positions.Contains(p));
            }
        }
        public void Run()
        {
            // Vi vill skapa objekt utifrån en lista av strängar

            var positionStringList = new[] { "manager", "clerk", "programmer", "clerk", "programmer" };

            var list = new List <Position>();

            // Gå igenom listan av strängar och skapa listan av Position-objekt

            foreach (var position in positionStringList)
            {
                list.Add(PositionFactory.Create(position));
            }

            // Skriv ut den nya listan

            foreach (var p in list)
            {
                Console.WriteLine($"En instans av objektet {p.GetType().Name}");
            }
        }