Exemplo n.º 1
0
        public void ReadTest()
        {
            PuzzleReader target   = new PuzzleReader();
            string       filename = @"..\..\..\TestSolverLib\puzzlefiles\puzzle4.txt";
            IList <int>  values   = target.Read(filename);

            Assert.AreEqual(81, values.Count, "PuzzleReader didn't read all 81 values");
        }
Exemplo n.º 2
0
        public void Load(string filename)
        {
            PuzzleReader reader        = new PuzzleReader();
            IList <int>  list          = reader.Read(filename);
            ISpace <int> initialValues = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            reader.ConvertToInitialValues(list, initialValues);
            Engine.SetInitialValues(initialValues);
        }
Exemplo n.º 3
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Solve
        ///</summary>
        public void SolveTestHelper <TKey>()
        {
            SudokuPuzzle        sudokuPuzzle = new SudokuPuzzle();
            IPuzzleEngine <int> engine       = new PuzzleEngine <int>(sudokuPuzzle);

            // Read values
            PuzzleReader reader   = new PuzzleReader();
            const string filename = "C:\\projects\\src\\2009\\Solver\\superfiend.txt";
            IList <int>  list     = reader.Read(filename);

            ISpace <int> initialValues = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            reader.ConvertToInitialValues(list, initialValues);

            engine.SetInitialValues(initialValues);
            int remaining = sudokuPuzzle.Space.Unsolved();

            Assert.AreEqual(53, remaining, "Did not read 28 values");

            // debug handler
            foreach (KeyValuePair <int, IPossible> pair in engine.Puzzle.Space)
            {
                pair.Value.NoValuesLeft += new Possible.NoValuesLeftFunction(Value_NoValuesLeft);
            }

            //const bool expected = true;
            engine.Solve(false);
            remaining = sudokuPuzzle.Space.Unsolved();
            SpaceAdapter <int> .WriteConsole(sudokuPuzzle.Space);

            string message = string.Format("Puzzle did not get solved. {0} spaces remaining.", remaining);

            Assert.AreEqual(0, engine.Count, "Not all tasks have completed");
            Assert.AreEqual(0, remaining, message);
        }