public void ReadingBadFilesThrowsExceptions()
 {
     Assert.ThrowsException <FileNotFoundException>(() => SudokuFile.ReadFile(NONEXISTANTFILENAME),
                                                    "Exception expected for bad filename.");
     Assert.ThrowsException <ArgumentException>(() => SudokuFile.ReadFile(EMPTYFILENAME),
                                                "Exception expected for file that contains no information.");
     Assert.ThrowsException <ArgumentException>(() => SudokuFile.ReadFile(WRONGFILEFORMATFILENAME),
                                                "Exception expected for file that contains bad information.");
 }
Пример #2
0
        public void ProgramOutputsSolutionsToDefaultFileNameIfAsked()
        {
            Program.ReadInput(GOODFILENAME, "-f");
            Assert.IsTrue(File.Exists(TESTFILENAME));
            List <SudokuPuzzle> solvedPuzzles = SudokuFile.ReadFile(TESTFILENAME);

            foreach (var puzzle in solvedPuzzles)
            {
                Assert.IsTrue(puzzle.IsSolved());
            }
        }
Пример #3
0
        public void ProgramOutputsSolutionsToProvidedFileName()
        {
            Program.ReadInput(GOODFILENAME, OUTPUTABSPATH);
            Assert.IsTrue(File.Exists(OUTPUTABSPATH));
            List <SudokuPuzzle> solvedPuzzles = SudokuFile.ReadFile(OUTPUTABSPATH);

            foreach (var puzzle in solvedPuzzles)
            {
                Assert.IsTrue(puzzle.IsSolved());
            }
        }
 public void ReadingGoodFilesDoesNotThrowExceptions()
 {
     try
     {
         SudokuFile.ReadFile(GOODFILENAME);
         SudokuFile.ReadFile(GOODSINGLEPUZZLEFILE);
     }
     catch (Exception)
     {
         Assert.Fail("Good files should not throw exceptions.");
     }
 }
Пример #5
0
        public void SavesAllTheThings()
        {
            List <SudokuPuzzle> puzzles = SudokuFile.ReadFile(GOODFILENAME);

            SudokuFile.SaveFile(puzzles, TESTFILENAMEABS);
            List <SudokuPuzzle> puzzlesRead = SudokuFile.ReadFile(TESTFILENAMEABS);

            Assert.IsTrue(puzzles.Count == puzzlesRead.Count);
            for (int i = 0; i < puzzles.Count; i++)
            {
                Assert.IsTrue(puzzles[i].Equals(puzzlesRead[i]));
            }
        }
Пример #6
0
        public void SolvesAllTheThings()
        {
            List <SudokuPuzzle> puzzles = SudokuFile.ReadFile(GOODFILENAME);
            SudokuRoot          Solver  = new SudokuRoot();

            foreach (var puzzle in puzzles)
            {
                Solver.SolveSudoku(puzzle);
            }
            foreach (var puz in puzzles)
            {
                Assert.IsTrue(puz.IsSolved());
            }
        }
        private static void AssertFileContainsPuzzles(string file, int expectedNumber)
        {
            List <SudokuPuzzle> morePuzzles = SudokuFile.ReadFile(file);

            Assert.AreEqual(morePuzzles.Count, expectedNumber);
        }