Ejemplo n.º 1
0
        public void Main()
        {
            string path = Constants.EASY_INPUT;

            string[] inputFiles = Directory.GetFiles(path);
            foreach (string file in inputFiles)
            {
                Board board;
                try
                {
                    board = FileInterface.readFromFile(file);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                Tracker tracker = new Tracker(board);
                Solver  solver  = new Solver(tracker);
                tracker = solver.run();

                if (!tracker.valid)
                {
                    Assert.IsFalse(TestUtils.isCorrectSolution(tracker.board));
                }
                else
                {
                    if (tracker.solutionCnt > 1)
                    {
                        Console.WriteLine("WARNING: More than one solution found. One is shown.");
                    }
                    Assert.IsTrue(TestUtils.isCorrectSolution(tracker.board),
                                  "ERROR: Could not find correct solution for file " + file + ".");
                }
            }
        }
Ejemplo n.º 2
0
        public void Main()
        {
            List <List <char> > a = new List <List <char> >
            {
                new List <char> {
                    '1', '2'
                },
                new List <char> {
                    '3', '4'
                }
            };
            List <List <char> > b = new List <List <char> >
            {
                new List <char> {
                    '1', '2'
                },
                new List <char> {
                    '3', '4'
                }
            };

            Assert.IsTrue(TestUtils.boardsEqual(a, b));
            a[0][0] = '0';
            Assert.IsFalse(TestUtils.boardsEqual(a, b));

            List <List <char> > c = new List <List <char> >
            {
                new List <char> {
                    '1', '2'
                }
            };

            Assert.IsFalse(TestUtils.boardsEqual(a, c));

            Assert.Catch(() => new Board(4, new CharSet(new List <char> {
                '0', '1', '2'
            })));

            List <List <char> > complete = new List <List <char> >
            {
                new List <char> {
                    '2', '4', '3', '1'
                },
                new List <char> {
                    '1', '3', '2', '4'
                },
                new List <char> {
                    '3', '1', '4', '2'
                },
                new List <char> {
                    '4', '2', '1', '3'
                }
            };

            Board board1 = new Board(4, new CharSet(new List <char> {
                '0', '1', '2', '3'
            }), complete);

            Assert.IsTrue(TestUtils.isCorrectSolution(board1));

            complete[0][0] = '4';
            Assert.IsFalse(TestUtils.isCorrectSolution(board1));

            List <List <char> > badCols = new List <List <char> >
            {
                new List <char> {
                    '2', '4', '3', '1'
                },
                new List <char> {
                    '2', '4', '3', '1'
                },
                new List <char> {
                    '2', '4', '3', '1'
                },
                new List <char> {
                    '2', '4', '3', '1'
                }
            };
            Board board2 = new Board(4, new CharSet(new List <char> {
                '0', '1', '2', '3'
            }), badCols);

            Assert.IsFalse(TestUtils.isCorrectSolution(board2));

            List <List <char> > badRegions = new List <List <char> >
            {
                new List <char> {
                    '2', '4', '3', '1'
                },
                new List <char> {
                    '4', '3', '1', '2'
                },
                new List <char> {
                    '3', '1', '2', '4'
                },
                new List <char> {
                    '1', '2', '4', '3'
                }
            };
            Board board3 = new Board(4, new CharSet(new List <char> {
                '0', '1', '2', '3'
            }), badRegions);

            Assert.IsFalse(TestUtils.isCorrectSolution(board3));
        }