Beispiel #1
0
        public void SolveIncompleteBoards(string[] rowStrings, int iterations)
        {
            IEnumerable <(ushort, ushort, int)> coll = rowStrings.Select(rowString => rowString.ToRowWithMaskAndSize());

            ushort[] rows  = coll.Select(trio => trio.Item1).ToArray();
            ushort[] masks = coll.Select(trio => trio.Item2).ToArray();
            int      size  = coll.First().Item3;

            var printer = new BoardPrinter(this.output);

            printer.PrintBoard(rows, masks, size);
            var rowChecker  = new BinairoRowChecker(this.validRows, size);
            var flipper     = new MatrixFlipper();
            var checker     = new BinairoBoardChecker(rowChecker, flipper, size);
            var rowSolver   = new BinairoRowSolver(size);
            var boardSolver = new DuplicateRowSolver(size, new BitCounter());
            var solver      = new BinairoBoardSolver(checker, rowSolver, boardSolver, flipper, size)
            {
                Output     = printer,
                Iterations = iterations
            };
            //rowSolver.RowChecker = rowChecker;
            //rowSolver.Output = printer;
            bool solved = solver.Solve(rows, masks);

            Assert.True(solved);
        }
Beispiel #2
0
        public void Flip_ShouldRise_TheMatrixIsNotSquareException()
        {
            //Arrange
            int[,] matrix =
            {
                { 1,  2,  3,  4 },
                { 5,  6,  7,  8 },
                { 9, 10, 11, 12 }
            };

            var target = new MatrixFlipper();

            //Act
            Assert.Throws <TheMatrixIsNotSquareException>(() => target.FlipClockwise(ref matrix));
        }
        //[Theory(/*Timeout = 60000 /*ms*/)]
        //[InlineData(6)]
        //[InlineData(8)]
        //[InlineData(10)]
        public void GenerateBoardInReasonableTime(int size)
        {
            Debug.WriteLine($"Generating all boards for size {size}.");
            var validRows  = new BinairoRows(new BinairoRowGenerator(), size);
            var rowChecker = new BinairoRowChecker(validRows, size);
            var flipper    = new MatrixFlipper();
            var checker    = new BinairoBoardChecker(rowChecker, flipper, size);
            var sut        = new BoardGenerator(checker, validRows, size);
            //var boardPrinter = new BoardPrinter();
            var allBoards = sut.GenerateAllBoards(); // .Take(1000);
            //Debug.WriteLine($"Found {allBoards.Count()} boards.");
            int count = 0;

            foreach (ushort[] board in allBoards)
            {
                count += 1;
                if (count % 100 == 0)
                {
                    Debug.WriteLine(count);
                }
                //boardPrinter.PrintBoard(board, size);
                Assert.True(checker.IsValid(board, sut.FullMask));
            }
        }