示例#1
0
        public void ShouldMainFieldResetToInitialState()
        {
            var fieldSetting = CreateDefaultFieldSetting();
            var testValues   = new List <TestMainFieldSquare>()
            {
                TSA(3, 3, 2, Direction.Left, Color.Red),
                TSA(5, 3, 2, Direction.Left, Color.Red),
            };

            var mainField = TestMainField.Create(fieldSetting, testValues);

            mainField.Reset();
            mainField.Matrix.ForEach(item =>
            {
                var initialSquare = fieldSetting.InitialSquares.FirstOrDefault(initItem => initItem.X == item.X && initItem.Y == item.Y);
                if (initialSquare != null)
                {
                    item.State.IsActive.ShouldBeTrue();
                    item.State.Obstacle.ShouldBe((uint)(fieldSetting.InitialSquares.IndexOf(initialSquare) + 1));
                    item.State.Direction.Value.ShouldBe(Direction.None);
                    item.Color.ShouldBe(initialSquare.Color);
                    return;
                }

                item.State.IsActive.ShouldBeFalse();
                item.State.Obstacle.ShouldBe(0u);
                item.State.Direction.Value.ShouldBe(Direction.None);
                item.Color.ShouldBe(Color.None);
            });
        }
示例#2
0
        public void ShouldCreateMainField()
        {
            var fieldSetting = CreateDefaultFieldSetting();
            var mainField    = TestMainField.Create(fieldSetting, new List <TestMainFieldSquare>());

            mainField.Width.ShouldBe(fieldSetting.HorzDimension);
            mainField.Height.ShouldBe(fieldSetting.VertDimension);
        }
示例#3
0
        public void ShouldFindAvalibleDestinationInDirection(Direction dir, uint lineIdx, int result)
        {
            var fieldSetting = CreateDefaultFieldSetting();
            var testValues   = new List <TestMainFieldSquare>()
            {
                TSA(2, 4, color: Color.Blue),
            };

            var mainField = TestMainField.Create(fieldSetting, testValues);
            var dest      = mainField.FindAvalibleDestinationInDirection(new MoveDirection(dir), lineIdx);

            dest.ShouldBe(result);
        }
示例#4
0
        public void ShouldMainFieldGetSquareCombinations()
        {
            var fieldSetting     = CreateDefaultFieldSetting();
            var firstCombination = new List <TestMainFieldSquare>()
            {
                TSA(2, 4, color: Color.Blue),
                TSA(2, 5, color: Color.Blue),
                TSA(2, 6, color: Color.Blue),
                TSA(3, 5, color: Color.Blue),
                TSA(3, 6, color: Color.Blue),
                TSA(3, 7, color: Color.Blue),
            };

            var secondCombination = new List <TestMainFieldSquare>()
            {
                TSA(3, 3, color: Color.Red),
                TSA(4, 3, color: Color.Red),
                TSA(5, 3, color: Color.Red),
            };

            var thirdNotCompleteCombination = new List <TestMainFieldSquare>()
            {
                TSA(4, 4, color: Color.Green),
                TSA(5, 4, color: Color.Green),
                TSA(7, 4, color: Color.Green),
            };

            var testValues = new List <TestMainFieldSquare>();

            testValues.AddRange(firstCombination);
            testValues.AddRange(secondCombination);
            testValues.AddRange(thirdNotCompleteCombination);

            var mainField    = TestMainField.Create(fieldSetting, testValues);
            var combinations = mainField.GetSquareCombinations();

            combinations.Count().ShouldBe(2);
            var result1 = combinations.ElementAt(0);

            result1.Count().ShouldBe(6);
            firstCombination.ShouldAllBe(item => result1.Any(resItem => item.X == resItem.X && item.Y == resItem.Y));

            var result2 = combinations.ElementAt(1);

            result2.Count().ShouldBe(3);
            secondCombination.ShouldAllBe(item => result2.Any(resItem => item.X == resItem.X && item.Y == resItem.Y));
        }
示例#5
0
        public void ShouldMainFieldResetSquareState()
        {
            var fieldSetting = CreateDefaultFieldSetting();
            var testValues   = new List <TestMainFieldSquare>()
            {
                TS(3, 3, true, 2, Direction.Left, Color.Red),
            };

            var mainField = TestMainField.Create(fieldSetting, testValues);
            var item      = mainField[3, 3].Value;

            item.State.IsActive.ShouldBeTrue();
            item.State.Obstacle.ShouldBe(2u);
            item.State.Direction.Value.ShouldBe(Direction.Left);
            item.Color.ShouldBe(Color.Red);
            mainField.ResetSquareState(3, 3);
            item.State.IsActive.ShouldBeFalse();
            item.State.Obstacle.ShouldBe(0u);
            item.State.Direction.Value.ShouldBe(Direction.None);
            item.Color.ShouldBe(Color.None);
        }