Ejemplo n.º 1
0
        public void CalculateBlockTest()
        {
            // Not Testing every cell, but there in each block: a one upper corner, center, and one lower corner
            Puzzle calcBlockTest = new Puzzle();
            Assert.AreEqual(1, calcBlockTest.CalculateBlock(0, 0), "Coord [0, 0, 1] Failed");
            Assert.AreEqual(1, calcBlockTest.CalculateBlock(1, 1), "Coord [1, 1, 1] Failed");
            Assert.AreEqual(1, calcBlockTest.CalculateBlock(2, 2), "Coord [2, 2, 1] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(3, 3), "Coord [3, 3, 5] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(4, 4), "Coord [4, 4, 5] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(5, 5), "Coord [5, 5, 5] Failed");
            Assert.AreEqual(9, calcBlockTest.CalculateBlock(6, 6), "Coord [6, 6, 9] Failed");
            Assert.AreEqual(9, calcBlockTest.CalculateBlock(7, 7), "Coord [7, 7, 9] Failed");
            Assert.AreEqual(9, calcBlockTest.CalculateBlock(8, 8), "Coord [8, 8, 9] Failed");
            Assert.AreEqual(3, calcBlockTest.CalculateBlock(8, 0), "Coord [8, 0, 3] Failed");
            Assert.AreEqual(3, calcBlockTest.CalculateBlock(7, 1), "Coord [7, 1, 3] Failed");
            Assert.AreEqual(3, calcBlockTest.CalculateBlock(6, 2), "Coord [6, 2, 3] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(5, 3), "Coord [5, 3, 5] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(4, 4), "Coord [4, 4, 5] Failed");
            Assert.AreEqual(5, calcBlockTest.CalculateBlock(3, 5), "Coord [3, 5, 5] Failed");
            Assert.AreEqual(7, calcBlockTest.CalculateBlock(2, 6), "Coord [2, 6, 7] Failed");
            Assert.AreEqual(7, calcBlockTest.CalculateBlock(1, 7), "Coord [1, 7, 7] Failed");
            Assert.AreEqual(7, calcBlockTest.CalculateBlock(0, 8), "Coord [0, 8, 7] Failed");
            Assert.AreEqual(2, calcBlockTest.CalculateBlock(3, 0), "Coord [3, 0, 2] Failed");
            Assert.AreEqual(2, calcBlockTest.CalculateBlock(4, 1), "Coord [4, 1, 2] Failed");
            Assert.AreEqual(2, calcBlockTest.CalculateBlock(5, 2), "Coord [5, 2, 2] Failed");
            Assert.AreEqual(8, calcBlockTest.CalculateBlock(3, 6), "Coord [3, 6, 8] Failed");
            Assert.AreEqual(8, calcBlockTest.CalculateBlock(4, 7), "Coord [4, 7, 8] Failed");
            Assert.AreEqual(8, calcBlockTest.CalculateBlock(5, 8), "Coord [5, 8, 8] Failed");

        }
Ejemplo n.º 2
0
 public void CorrectPuzzleTest()
 {
     var correctTest = new Puzzle(VALID_STARTING_PUZZLE);
     Assert.IsNotNull(correctTest, "Puzzle not created");
     Assert.AreEqual(27, correctTest.Sections.Count, "Section NodeGroups failed");
     Assert.AreEqual("", correctTest.Status);
 }
Ejemplo n.º 3
0
 public void ShortPuzzleTest()
 {
     var shortTest = new Puzzle("123456789");
     Assert.IsNull(shortTest.Grid);
     Assert.IsNull(shortTest.Sections);
     Assert.AreEqual("Invalid Starting Puzzle String", shortTest.Status);
 }
Ejemplo n.º 4
0
 public void EmptyPuzzleTest()
 {
     var emptyTest = new Puzzle("");
     Assert.IsNull(emptyTest.Grid);
     Assert.IsNull(emptyTest.Sections);
     Assert.AreEqual("Invalid Starting Puzzle String", emptyTest.Status);
 }
Ejemplo n.º 5
0
 public void LongPuzzleTest()
 {
     var longPuzzle = new StringBuilder();
     while (longPuzzle.Length < 82)
     {
         longPuzzle.Append("1");
     }
     var longTest = new Puzzle(longPuzzle.ToString());
     Assert.IsNull(longTest.Grid);
     Assert.IsNull(longTest.Grid);
     Assert.IsNull(longTest.Sections);
     Assert.AreEqual("Invalid Starting Puzzle String", longTest.Status);
 }
Ejemplo n.º 6
0
 public PartialViewResult Solve(string startingPuzzle)
 {
     Puzzle puzzle = new Puzzle(startingPuzzle);
     puzzle.Solve();
     return PartialView(puzzle);
 }
Ejemplo n.º 7
0
 public ActionResult Index()
 {
     Puzzle emptyPuzzle = new Puzzle();
     return View(emptyPuzzle);
 }
Ejemplo n.º 8
0
 public void SetupPuzzleTest()
 {
     Puzzle setupTest = new Puzzle();
     Assert.AreEqual(81, setupTest.Grid.Count, "Incorrect number of nodes in grid");
 }
Ejemplo n.º 9
0
 public void NoPuzzleTest()
 {
     var noTest = new Puzzle();
     Assert.IsNotNull(noTest.Grid);
     Assert.IsNotNull(noTest.Sections);
 }
Ejemplo n.º 10
0
        public void CloneTest()
        {
            Puzzle puzzleTest = new Puzzle(VALID_STARTING_PUZZLE);
            Puzzle puzzleTestClone1 = (Puzzle)puzzleTest.Clone();
            Assert.AreEqual(puzzleTest.ToString(), puzzleTestClone1.ToString());
            CollectionAssert.AreEqual(puzzleTest.Grid[2].Possibilities, puzzleTestClone1.Grid[2].Possibilities);

            puzzleTest.Grid[2].Possibilities.Remove(2);
            Puzzle puzzleTestClone2 = (Puzzle)puzzleTest.Clone();
            Assert.AreEqual(puzzleTest.ToString(), puzzleTestClone2.ToString());
            CollectionAssert.AreEqual(puzzleTest.Grid[2].Possibilities, puzzleTestClone2.Grid[2].Possibilities);

            puzzleTest = new Puzzle(VALID_STARTING_PUZZLE);
            Puzzle puzzleTestClone3 = (Puzzle)puzzleTest.Clone();
            puzzleTest.Solve();
            puzzleTestClone1.Solve();
            Assert.AreEqual(puzzleTest.ToString(), puzzleTestClone1.ToString());
        }
Ejemplo n.º 11
0
 public void ProcessTest()
 {
     Puzzle p = new Puzzle(VALID_STARTING_PUZZLE);
     p.Solve();
     Assert.AreEqual(VALID_FINISHED_PUZZLE, p.ToString());
 }
Ejemplo n.º 12
0
        public void ValidatePuzzleTest()
        {
            Puzzle validStartingPuzzle = new Puzzle(VALID_STARTING_PUZZLE);
            Assert.IsTrue(validStartingPuzzle.IsValid(), "Starting puzzle failed");

            Puzzle validFinishedPuzzle = new Puzzle(VALID_FINISHED_PUZZLE);
            Assert.IsTrue(validFinishedPuzzle.IsValid(), "Finished puzzle failed");

            Puzzle invalidColumnPuzzle = new Puzzle(INVALID_COLUMN_STARTING_PUZZLE);
            Assert.IsFalse(invalidColumnPuzzle.IsValid(), "Invalid column puzzle failed");

            Puzzle invalidRowPuzzle = new Puzzle(INVALID_ROW_STARTING_PUZZLE);
            Assert.IsFalse(invalidRowPuzzle.IsValid(), "Invalid row puzzle failed");

            Puzzle invalidBlockPuzzle = new Puzzle(INVALID_BLOCK_STARTING_PUZZLE);
            Assert.IsFalse(invalidBlockPuzzle.IsValid(), "Invalid block puzzle failed");

            Puzzle invalidFinishedPuzzle = new Puzzle(INVALID_FINISHED_PUZZLE);
            Assert.IsFalse(invalidFinishedPuzzle.IsValid(), "Invalid finished puzzle failed");
        }
Ejemplo n.º 13
0
 public void InitializeValuesTest()
 {
     Puzzle initValueTest = new Puzzle();
     initValueTest.InitializeValues(VALID_STARTING_PUZZLE);
     Assert.AreEqual(6, initValueTest.Grid[0].Value, "[1,1] not set correctly");
     Assert.AreEqual(9, initValueTest.Grid[12].Value, "[4,2] not set correctly");
     Assert.AreEqual(2, initValueTest.Grid[17].Value, "[9,2] not set correctly");
     Assert.AreEqual(8, initValueTest.Grid[45].Value, "[1,6] not set correctly");
     Assert.AreEqual(7, initValueTest.Grid[51].Value, "[7,6] not set correctly");
     Assert.AreEqual(9, initValueTest.Grid[63].Value, "[1,8] not set correctly");
     Assert.AreEqual(1, initValueTest.Grid[58].Value, "[5,7] not set correctly");
     Assert.AreEqual(8, initValueTest.Grid[80].Value, "[9,9] not set correctly");
 }
Ejemplo n.º 14
0
        public object Clone()
        {
            var clonedPuzzle = new Puzzle();
            clonedPuzzle.Grid = new List<Node>();
            foreach(Node n in Grid)
            {
                clonedPuzzle.Grid.Add((Node)n.Clone());
            }
            for (int i = 1; i < 10; i++)
            {
                NodeGroup newRow = new NodeGroup(clonedPuzzle.Grid.Where(n => n.Row == i).ToList());
                newRow.PropertyChanged += TrackActivity;
                clonedPuzzle.Sections.Add(newRow);
                NodeGroup newColumn = new NodeGroup(clonedPuzzle.Grid.Where(n => n.Column == i).ToList());
                newColumn.PropertyChanged += TrackActivity;
                clonedPuzzle.Sections.Add(newColumn);
                NodeGroup newBlock = new NodeGroup(clonedPuzzle.Grid.Where(n => n.Block == i).ToList());
                newBlock.PropertyChanged += TrackActivity;
                clonedPuzzle.Sections.Add(newBlock);
            }

            return clonedPuzzle;
        }