예제 #1
0
        public void ExactCoverProblemsWithSingleSolutionTest()
        {
            Func <int, string> makeLabel = numSolutions => string.Format(
                "Expected exactly one solution but got {0}",
                numSolutions);

            var arbMatrix = Arb.From(GenMatrixOfIntWithSingleSolution());

            var property = Prop.ForAll(arbMatrix, matrix =>
            {
                var solutions = new Dlx().Solve(matrix).ToList();
                var p1        = (solutions.Count() == 1).Label(makeLabel(solutions.Count()));
                var p2        = CheckSolutions(solutions, matrix);
                return(FsCheckUtils.And(p1, p2));
            });

            Check.One(Config, property);
        }
예제 #2
0
        public void ExactCoverProblemsWithNoSolutionsTest()
        {
            Func <int, string> makeLabel = numSolutions => string.Format(
                "Expected no solutions but got {0}",
                numSolutions);

            var arbMatrix = Arb.From(GenMatrixOfIntWithNoSolutions());

            var property = Prop.ForAll(arbMatrix, matrix =>
            {
                var solutions = new Dlx().Solve(matrix).ToList();
                return((!solutions.Any()).Label(makeLabel(solutions.Count())));
            });

            Check.One(Config, property);
        }
예제 #3
0
        private bool TryRemoveNumber(int index)
        {
            int number = _puzzle[index];

            _puzzle[index] = 0;
            SudokuExactCover();
            MakeExactCoverGridFromSudoku();
            IEnumerable <Solution> solutions = new Dlx().Solve(_problemMatrix);

            if (solutions.Count() == 1)
            {
                return(true);
            }
            _puzzle[index] = number;
            return(false);
        }
예제 #4
0
        public void ExactCoverProblemsWithMultipleSolutionsTest()
        {
            var arbNumSolutions = Arb.From(Gen.Choose(2, 5));

            var property = Prop.ForAll(arbNumSolutions, numSolutions =>
            {
                Func <int, string> makeLabel = actualNumSolutions => string.Format(
                    "Expected exactly {0} solutions but got {1}",
                    numSolutions, actualNumSolutions);

                var arbMatrix = Arb.From(GenMatrixOfIntWithMultipleSolutions(numSolutions));

                return(Prop.ForAll(arbMatrix, matrix =>
                {
                    var solutions = new Dlx().Solve(matrix).ToList();
                    var actualNumSolutions = solutions.Count();
                    var p1 = (actualNumSolutions == numSolutions).Label(makeLabel(actualNumSolutions));
                    var p2 = CheckSolutions(solutions, matrix);
                    return FsCheckUtils.And(p1, p2);
                }));
            });

            Check.One(Config, property);
        }