Beispiel #1
0
        public void SolveTest()
        {
            //Arrange
            IMatrixSolver target = new MatrixSolver();
            var           matrix = new int[7, 7]
            {
                { 1, 0, 1, 0, 0, 0, 2 },
                { 0, 1, 0, 1, 0, 0, 3 },

                { 1, 0, 0, 0, 1, 0, 4 },
                { 0, 1, 0, 0, 0, 1, 8 },

                { 0, 0, 1, 0, 1, 0, 6 },
                { 1, 0, 0, 0, 0, 0, 5 },
                { 0, 1, 0, 0, 0, 0, 10 }
            };

            var expected = new int[7, 7]
            {
                { 1, 0, 0, 0, 0, 0, 5 },
                { 0, 1, 0, 0, 0, 0, 10 },
                { 0, 0, 1, 0, 0, 0, 7 },
                { 0, 0, 0, 1, 0, 0, 9 },
                { 0, 0, 0, 0, 1, 0, 1 },
                { 0, 0, 0, 0, 0, 1, 2 },
                { 0, 0, 0, 0, 0, 0, 0 }
            };

            //Act
            var result = target.Solve(matrix);

            //Assert
            Assert.IsTrue(result, "couldnt solve matrix");
            Common.CheckArraysAreEqual(matrix, expected);
        }
Beispiel #2
0
        private void StandardTest(string testName, int correctCount)
        {
            Console.WriteLine("Test name: " + testName);

            var grammarFileDot    = "Resources\\Grammars\\" + testName + ".dot";
            var grammarFileSimple = "Resources\\Grammars\\" + testName + ".txt";
            var graphFile         = "Resources\\Automata\\" + testName + ".dot";

            var graphDot      = File.ReadAllText(graphFile, Encoding.Default);
            var grammarDot    = File.ReadAllText(grammarFileDot, Encoding.Default);
            var grammarSimple = File.ReadAllText(grammarFileSimple, Encoding.Default);

            var graph            = new Graph(graphDot);
            var grammar          = Grammar.FromDot(grammarDot);
            var grammarForMatrix = Grammar.FromSimpleFormat(grammarSimple);

            var gllSolver      = new GLLSolver();
            var matrixSolver   = new MatrixSolver();
            var bottomUpSolver = new BottomUpSolver();

            var resultGll      = gllSolver.Solve(graph, grammar);
            var resultMatrix   = matrixSolver.Solve(graph, grammarForMatrix);
            var resultBottomUp = bottomUpSolver.Solve(graph, grammar);

            var all = new List <string>()
            {
                resultBottomUp, resultMatrix, resultGll
            };

            foreach (var result in all)
            {
                var count = result.Split('S').Length - 1;  // count of triplets (i,S,j)
                if (count != correctCount)
                {
                    Console.WriteLine("Test failed: " + testName + Environment.NewLine);
                    return;
                }
            }
            Console.WriteLine("Test passed: " + testName);
            Console.WriteLine();
        }
Beispiel #3
0
        public void MatrixSolverTest()
        {
            var sudoku = new Sudoku(new ICell[, ] {
                { new Cell(6), new Cell(4), new Cell(0), new Cell(2), new Cell(9), new Cell(8), new Cell(5), new Cell(0), new Cell(7) },
                { new Cell(0), new Cell(5), new Cell(2), new Cell(1), new Cell(0), new Cell(6), new Cell(9), new Cell(8), new Cell(4) },
                { new Cell(7), new Cell(9), new Cell(8), new Cell(0), new Cell(4), new Cell(5), new Cell(0), new Cell(6), new Cell(2) },

                { new Cell(9), new Cell(0), new Cell(3), new Cell(6), new Cell(1), new Cell(4), new Cell(8), new Cell(7), new Cell(0) },
                { new Cell(0), new Cell(8), new Cell(6), new Cell(5), new Cell(3), new Cell(0), new Cell(4), new Cell(2), new Cell(9) },
                { new Cell(5), new Cell(7), new Cell(4), new Cell(0), new Cell(8), new Cell(2), new Cell(6), new Cell(0), new Cell(3) },

                { new Cell(8), new Cell(3), new Cell(0), new Cell(7), new Cell(6), new Cell(9), new Cell(2), new Cell(4), new Cell(1) },
                { new Cell(4), new Cell(1), new Cell(9), new Cell(8), new Cell(0), new Cell(3), new Cell(7), new Cell(5), new Cell(6) },
                { new Cell(2), new Cell(0), new Cell(7), new Cell(4), new Cell(5), new Cell(1), new Cell(3), new Cell(0), new Cell(8) }
            });

            var solver = new MatrixSolver(sudoku);

            solver.Solve();

            //TODO: check if result is correct
        }