public void FasterPuzzleSolutionGenerator_CreatePuzzleSolution_Test2()
        {
            var t = new Stopwatch();

            t.Start();
            for (var count = 0; count < 100; count++)
            {
                var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

                var result = sut.CreatePuzzleSolution();

                Assert.NotNull(result);

                foreach (var box in result.ByBox())
                {
                    AssertIfNotFullSet(box, PuzzleSize.NineByNine);
                }

                foreach (var row in result.ByRow())
                {
                    AssertIfNotFullSet(row, PuzzleSize.NineByNine);
                }

                foreach (var col in result.ByCol())
                {
                    AssertIfNotFullSet(col, PuzzleSize.NineByNine);
                }
            }
            t.Stop();

            TestHelper.WriteLine($"{100} puzzles created in {t.ToString()}");
        }
        public void FasterPuzzleSolutionGenerator_SeedFirstBox_Test1()
        {
            var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

            sut.Random = new TestNotSoRandom();

            sut.SeedFirstBox();

            var solution = sut.PuzzleGrid;

            Approvals.Verify(solution);
        }
        public void FasterPuzzleSolutionGenerator_SeedSecondBox_SetBased_Test1()
        {
            HashSet <int>[] CreateBoxRowSet(Puzzle puzzleGrid)
            {
                return(Enumerable.Range(0, puzzleGrid.Size.BoxSize())
                       .Select(i => new HashSet <int>())
                       .ToArray());
            }

            var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

            sut.Random = new TestNotSoRandom();
            sut.SeedFirstBox();

            // to make code look like class method
            var PuzzleGrid   = new Puzzle(PuzzleSize.NineByNine);
            var puzzleValues = new List <int>(Enumerable.Range(1, PuzzleGrid.Size.ToInt32()));

            // get box0 values by row
            var box0 = CreateBoxRowSet(PuzzleGrid);

            foreach (var row in Enumerable.Range(0, PuzzleGrid.Size.BoxSize()))
            {
                foreach (var col in Enumerable.Range(0, PuzzleGrid.Size.BoxSize()))
                {
                    box0[row].Add(sut.PuzzleGrid[new PuzzleCoordinate(row, col)] ?? -1);
                }
            }

            var box1            = CreateBoxRowSet(PuzzleGrid);
            var box1Row0Choices = Enumerable.Range(1, PuzzleGrid.Size.BoxSize() - 1)
                                  .SelectMany(i => box0[i])
                                  .OrderBy(x => sut.Random.GetRandomNumber())
                                  .Take(PuzzleGrid.Size.BoxSize());

            foreach (var value in box1Row0Choices)
            {
                box1[0].Add(value);
            }

            // TODO:  more to do!!!
            // TODO:  more to do!!!
            // TODO:  more to do!!!
            // TODO:  more to do!!!
            // TODO:  more to do!!!

            var solution = sut.PuzzleGrid;

            Approvals.Verify(solution);
        }
        public void FasterPuzzleSolutionGenerator_SeedFirstBox_Test2()
        {
            for (var count = 0; count < 1000; count++)
            {
                var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

                sut.SeedFirstBox();

                var solution = sut.PuzzleGrid;

                var box = solution.ByBox().First();

                AssertIfNotFullSet(box, PuzzleSize.NineByNine);
            }
        }
        public void FasterPuzzleSolutionGenerator_SeedFirstColumn_Test2()
        {
            for (var count = 0; count < 1000; count++)
            {
                var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

                sut.SeedFirstBox();
                sut.SeedSecondBox();
                sut.SeedThirdBox();
                sut.SeedFirstColumn();

                var solution = sut.PuzzleGrid;

                var column = solution.ByCol().First();

                AssertIfNotFullSet(column, PuzzleSize.NineByNine);
            }
        }
        public void FasterPuzzleSolutionGenerator_CreatePuzzleSolution_Test1()
        {
            var sut = new OptimizedPuzzleSolutionGenerator(PuzzleSize.NineByNine);

            var result = sut.CreatePuzzleSolution();

            Assert.NotNull(result);

            foreach (var box in result.ByBox())
            {
                AssertIfNotFullSet(box, PuzzleSize.NineByNine);
            }

            foreach (var row in result.ByRow())
            {
                AssertIfNotFullSet(row, PuzzleSize.NineByNine);
            }

            foreach (var col in result.ByCol())
            {
                AssertIfNotFullSet(col, PuzzleSize.NineByNine);
            }
        }