public void Constructor_MapsColumnValuesToRows()
        {
            var c1 = new PartiallyCompleteGroup(2, "11");
            var c2 = new PartiallyCompleteGroup(2, "11");

            var r1 = new PartiallyCompleteGroup(2, "..");
            var r2 = new PartiallyCompleteGroup(2, "..");

            var grid = new GridPartialSolution(
                new List<IPartiallyCompleteGroup>() { r1, r2 },
                new List<IPartiallyCompleteGroup>() { c1, c2 });

            for (int rowId = 0; rowId < 2; rowId++)
            {
                var row = grid.GetRow(rowId);
                Assert.That(row.GetBlackSquares().Count, Is.EqualTo(2));
            }
        }
        public void Constructor_MapsRowValuesToColumns()
        {
            var r1 = new PartiallyCompleteGroup(2, "11");
            var r2 = new PartiallyCompleteGroup(2, "11");

            var c1 = new PartiallyCompleteGroup(2, "..");
            var c2 = new PartiallyCompleteGroup(2, "..");

            var grid = new GridPartialSolution(
                new List<IPartiallyCompleteGroup>() { r1, r2 },
                new List<IPartiallyCompleteGroup>() { c1, c2 });

            for (int columnId = 0; columnId < 2; columnId++)
            {
                var column = grid.GetColumn(columnId);
                Assert.That(column.GetBlackSquares().Count, Is.EqualTo(2));
            }
        }
        public SolveSquaresResult SolveSquares(IGridPartialSolution gridPartialSolution)
        {
            bool anySquaresSolved;
            IGridPartialSolution partialSolution;
            do
            {
                int rowId = 0;
                anySquaresSolved = false;
                var solvedRows = new List<IPartiallyCompleteGroup>();

                foreach (var row in this.rows)
                {
                    var result = row.SolveSquares(gridPartialSolution.GetRow(rowId));
                    anySquaresSolved = anySquaresSolved || result.AnyNewlySolvedSquares;

                    if (!result.StillValid)
                    {
                        return new SolveSquaresResult(gridPartialSolution, false);
                    }

                    solvedRows.Add(result.Solved);
                    
                    rowId++;
                }

                int columnId = 0;
                var solvedColumns = new List<IPartiallyCompleteGroup>();

                foreach (var column in this.columns)
                {
                    var result = column.SolveSquares(gridPartialSolution.GetColumn(columnId));
                    anySquaresSolved = anySquaresSolved || result.AnyNewlySolvedSquares;

                    if (!result.StillValid)
                    {
                        return new SolveSquaresResult(gridPartialSolution, true);
                    }

                    solvedColumns.Add(result.Solved);

                    columnId++;
                }
                
                partialSolution = new GridPartialSolution(solvedRows, solvedColumns);

                if (partialSolution.IsSolved)
                {
                    return new SolveSquaresResult(partialSolution, false);
                }

                gridPartialSolution = partialSolution.Copy();
            }
            while (anySquaresSolved);
            


            return new SolveSquaresResult(partialSolution, false);
        }