public void Validate_Should_Validate_Correct_Cube() { SudokuFile file = new SudokuFile(new List <List <int> > { new List <int> { 4, 1, 7, 3, 6, 9, 8, 2, 5 }, new List <int> { 6, 3, 2, 1, 5, 8, 9, 4, 7 }, new List <int> { 9, 5, 8, 7, 2, 4, 3, 1, 6 }, new List <int> { 8, 2, 5, 4, 3, 7, 1, 6, 9 }, new List <int> { 7, 9, 1, 5, 8, 6, 4, 3, 2 }, new List <int> { 3, 4, 6, 9, 1, 2, 7, 5, 8 }, new List <int> { 2, 8, 9, 6, 4, 3, 5, 7, 1 }, new List <int> { 5, 7, 3, 2, 9, 1, 6, 8, 4 }, new List <int> { 1, 6, 4, 8, 7, 5, 2, 9, 3 } }).Validate(); }
public void ValidateColumn_Should_Validate_Correct_Column() { SudokuFile file = new SudokuFile(new List <List <int> > { new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 4, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 3, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 2, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 1, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 6, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 7, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 8, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 9, 6, 7, 8, 9 } }).ValidateColumn(4); }
public void ValidateCube_Should_Validate_Correct_Cube() { SudokuFile file = new SudokuFile(new List <List <int> > { new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 4, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 3, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 2, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 1, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 6, 6, 7, 8, 9 }, new List <int> { 1, 2, 3, 4, 7, 6, 1, 2, 3 }, new List <int> { 1, 2, 3, 4, 8, 6, 6, 5, 4 }, new List <int> { 1, 2, 3, 4, 9, 6, 7, 8, 9 } }).ValidateCube(6, 6); }
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."); }
public void ValidateRow_Should_Validate_Correct_Row() { SudokuFile file = new SudokuFile(new List <List <int> > { new List <int>(), new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 } }).ValidateRow(1); }
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()); } }
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."); } }
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])); } }
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()); } }
public Viewer() { Assets.Level1.DownloadToString( text => { var e = new SudokuFile(text); e.Mappings.Randomize(); ToTable(e); } ); }
static void Main(string[] args) { var data = File.ReadAllText("web/assets/Sudoku.Editor/Level1.txt"); var t = new SudokuFile(data); t.ToConsole(); t.Mappings.Rotated = true; t.ToConsole(); }
public ThemedViewer() { var body = Native.Document.body; body.style.backgroundColor = Color.Black; body.style.color = Color.FromRGB(0, 0xff, 00); body.style.fontFamily = IStyle.FontFamilyEnum.Consolas; var a = new List<Cell>(); CreateTable(a); Assets.Level1.DownloadToString( text => { var e = new SudokuFile(text); e.Mappings.Randomize(); for (int y = 1; y < 10; y++) { for (int x = 1; x < 10; x++) { var s = e[x, y]; var c = a.Single(i => i.X == x && i.Y == y); if (s.Hidden) { // no-break space } else { c.Text.style.fontWeight = "bold"; c.Text.innerText = s.ToString(); } } } } ); }
/// <summary> /// Default constructor /// </summary> public Sudoku() { var t = new SudokuFile(Assets.Level1.ToStringAsset()); t.Mappings.Randomize(); const int padding = 2; const int w = 28; const int h = 28; for (int y = 1; y < 10; y++) { for (int x = 1; x < 10; x++) { var s = new Sprite(); var text = new TextField { text = t[x, y].ToString(), mouseEnabled = false }.AttachTo(s); text.autoSize = TextFieldAutoSize.LEFT; text.x = -text.width / 2; text.y = -text.height / 2; s.graphics.lineStyle(3, 0xff5300, 1); s.graphics.drawRect(-w / 2, -h / 2, w, h); // s.filters = new[] { new BevelFilter() }; s.x = (w + padding) * x; s.y = (h + padding) * y; s.AttachTo(this); } } }
/// <summary> /// Default constructor /// </summary> public Sudoku() { var t = new SudokuFile(Assets.Level1.ToStringAsset()); t.Mappings.Randomize(); const int padding = 2; const int w = 28; const int h = 28; for (int y = 1; y < 10; y++) for (int x = 1; x < 10; x++) { var s = new Sprite(); var text = new TextField { text = t[x, y].ToString(), mouseEnabled = false }.AttachTo(s); text.autoSize = TextFieldAutoSize.LEFT; text.x = -text.width / 2; text.y = -text.height / 2; s.graphics.lineStyle(3, 0xff5300, 1); s.graphics.drawRect(-w / 2, -h / 2, w, h); // s.filters = new[] { new BevelFilter() }; s.x = (w + padding) * x; s.y = (h + padding) * y; s.AttachTo(this); } }
private static void ToTable(SudokuFile e) { var t = new IHTMLTable(); t.cellPadding = 0; t.cellSpacing = 0; t.style.borderWidth = "1px"; t.style.borderStyle = "solid"; t.style.borderColor = Color.Gray; var b = t.AddBody(); for (int y = 1; y < 10; y++) { var r = b.AddRow(); for (int x = 1; x < 10; x++) { var s = e[x, y]; var c = r.AddColumn(); //c.style.width = "28px"; //c.style.height = "28px"; c.style.width = "2em"; c.style.height = "2em"; c.style.borderWidth = "1px"; c.style.borderStyle = "solid"; c.style.borderColor = Color.Gray; c.style.textAlign = ScriptCoreLib.JavaScript.DOM.IStyle.TextAlignEnum.center; c.style.verticalAlign = "middle"; if (x % 3 == 1) c.style.borderLeftColor = Color.Black; if (y % 3 == 1) c.style.borderTopColor = Color.Black; if (x % 3 == 0) c.style.borderRightColor = Color.Black; if (y % 3 == 0) c.style.borderBottomColor = Color.Black; c.innerText = e[x, y].ToString(); if (s.Hidden) { // no-break space } else { c.style.fontWeight = "bold"; } } } t.AttachToDocument(); }
private static void AssertFileContainsPuzzles(string file, int expectedNumber) { List <SudokuPuzzle> morePuzzles = SudokuFile.ReadFile(file); Assert.AreEqual(morePuzzles.Count, expectedNumber); }