コード例 #1
0
        static void RulesMatrixTest()
        {
            RulesMatrix r = new RulesMatrix();

            string[][] inputData = new string[6][];
            inputData[0] = new string[] { ";", "!N", ";" };
            inputData[1] = new string[] { ";", ";", "!N", ";" };
            inputData[2] = new string[] { "!N" };
            inputData[3] = new string[] { "!N", ";" };
            inputData[4] = new string[] { ";", "!N" };
            inputData[5] = new string[] { "a", ">", "a" };

            bool[] trueRez1 = { true, false, false, true, false, true };
            Debug.Assert(r.IsContains(inputData[0]) == true);
            Debug.Assert(r.IsContains(inputData[1]) == false);
            Debug.Assert(r.IsContains(inputData[2]) == false);
            Debug.Assert(r.IsContains(inputData[3]) == true);
            Debug.Assert(r.IsContains(inputData[4]) == false);
            Debug.Assert(r.IsContains(inputData[5]) == true);

            int [] trueRez2 = { 7, -1, -1, 1, -1, 9 };
            Debug.Assert(r.GetNumberOfRule(inputData[0]) == 7);
            Debug.Assert(r.GetNumberOfRule(inputData[1]) == -1);
            Debug.Assert(r.GetNumberOfRule(inputData[2]) == -1);
            Debug.Assert(r.GetNumberOfRule(inputData[3]) == 1);
            Debug.Assert(r.GetNumberOfRule(inputData[4]) == -1);
            Debug.Assert(r.GetNumberOfRule(inputData[5]) == 9);
        }
コード例 #2
0
ファイル: SyntaxScanner.cs プロジェクト: Fkame/AlmostCompiler
        public SyntaxScanner(List <LexemDataCell> table)
        {
            lexemTable    = new List <LexemDataCell>(table);
            stack         = new SymbolsStack(SpecialSymbs.START_SYMB);
            movingMatrix  = new MovingMatrix();
            rules         = new RulesMatrix();
            usedRulesList = new List <int>();

            //Logger.Debug("SyntaxScanner created!");
        }
コード例 #3
0
        public void BoardWithMatrix()
        {
            /*
             * x_x
             * xx_
             */

            var topRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >()
            {
                new List <int>()
                {
                    2
                },
                new List <int>()
                {
                    1
                },
                new List <int>()
                {
                    1
                }
            });

            var leftRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >()
            {
                new List <int>()
                {
                    1, 1
                },
                new List <int>()
                {
                    2
                }
            });

            CellState[,] matrix = new CellState[3, 2];
            matrix[2, 1]        = CellState.Blocked;
            var board = Board.MakeBoard(topRules, leftRules, matrix);

            Assert.NotNull(board);
            Assert.Equal(matrix[2, 1], board[2, 1]);
        }
コード例 #4
0
        public void BoardNoMatrix()
        {
            /*
             * x_x
             * xx_
             */

            var topRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >()
            {
                new List <int>()
                {
                    2
                },
                new List <int>()
                {
                    1
                },
                new List <int>()
                {
                    1
                }
            });

            var leftRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >()
            {
                new List <int>()
                {
                    1, 1
                },
                new List <int>()
                {
                    2
                }
            });
            var board = Board.MakeBoard(topRules, leftRules);
        }
コード例 #5
0
        private static RulesMatrix ParseConstraint(StreamReader reader)
        {
            List <List <int> >?rules = new List <List <int> >();

            while (true)
            {
                string?line = reader.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                List <int>?values = new List <int>();
                string[]? items = line.Split(",");
                foreach (string?item in items)
                {
                    int value = int.Parse(item);
                    values.Add(value);
                }
                rules.Add(values);
            }

            return(RulesMatrix.MakeRulesMatrix(rules));
        }
コード例 #6
0
        public void SampleBoard1()
        {
            var loadedBoard = NonFileLoader.LoadFile("TestBoards/Example1.non");

            Assert.Equal("Demo Puzzle from Front Page", loadedBoard.Title);
            Assert.Equal("Jan Wolter", loadedBoard.Author);

            var expectedTopRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >
            {
                new List <int> {
                    2, 1
                },
                new List <int> {
                    2, 1, 3
                },
                new List <int> {
                    7
                },
                new List <int> {
                    1, 3
                },
                new List <int> {
                    2, 1
                }
            });

            Assert.Equal(expectedTopRules, loadedBoard.Board.TopRules);

            var expectedLeftRules = RulesMatrix.MakeRulesMatrix(new List <List <int> >
            {
                new List <int> {
                    2
                },
                new List <int> {
                    2, 1
                },
                new List <int> {
                    1, 1
                },
                new List <int> {
                    3
                },
                new List <int> {
                    1, 1
                },
                new List <int> {
                    1, 1
                },
                new List <int> {
                    2
                },
                new List <int> {
                    1, 1
                },
                new List <int> {
                    1, 2
                },
                new List <int> {
                    2
                }
            });

            Assert.Equal(expectedLeftRules, loadedBoard.Board.LeftRules);
        }