Ejemplo n.º 1
0
        public void TestFixedItems()
        {
            List <CellContent> contentlist = new List <CellContent>
            {
                new CellContent(0),       // 0, 0
                new CellContent(1, true), // 0, 1
                new CellContent(0),       // 0, 2
                new CellContent(2),       // 1, 0
                new CellContent(0),       // 1, 1
                new CellContent(3),       // 1, 2
                new CellContent(9, true), // 2, 0
                new CellContent(4),       // 2, 1
                new CellContent(5),       // 2, 2
            };

            SodokuItem item = new SodokuItem(contentlist);

            Assert.IsTrue(item[1].IsFixed);

            item.ReplaceItem(new CellContent(1), 1);
            Assert.AreEqual(new CellContent(1), item[1]);
            Assert.IsTrue(item[1].IsFixed);
            Assert.IsFalse(item[1].IsEmpty);

            item.ReplaceItem(new CellContent(7), 1);

            Assert.AreEqual(new CellContent(1), item[1]);
        }
Ejemplo n.º 2
0
        public void TestCopyConstructor()
        {
            List <CellContent> contentlist = new List <CellContent>
            {
                new CellContent(0), // 0, 0
                new CellContent(1), // 0, 1
                new CellContent(0), // 0, 2
                new CellContent(2), // 1, 0
                new CellContent(0), // 1, 1
                new CellContent(3), // 1, 2
                new CellContent(9), // 2, 0
                new CellContent(4), // 2, 1
                new CellContent(5), // 2, 2
            };

            SodokuItem item1 = new SodokuItem(contentlist);

            Assert.IsTrue(item1[1] == new CellContent(1));
            Assert.IsTrue(item1[8] == new CellContent(5));

            SodokuItem copy = new SodokuItem(item1);

            for (int i = 0; i < 9; i++)
            {
                Assert.IsTrue(copy[i] == item1[i]);
            }
        } //
Ejemplo n.º 3
0
        public void Test_Sodoku_Grid()
        {
            Sodoku sodoku = new Sodoku();

            // top left
            sodoku[2, 2] = new CellContent(9);
            int rank = sodoku[2, 2].Rank;

            Assert.AreEqual(9, sodoku[2, 2].Rank);
            SodokuItem row = sodoku.GetRowAt(2);

            Assert.AreEqual(9, row[2].Rank);
            SodokuItem col = sodoku.GetColumnAt(2);

            Assert.AreEqual(9, col[2].Rank);
            Sodoku3x3 sgrid = sodoku.GetSodoku3x3AtGridPosition(2, 2);

            Assert.AreEqual(9, sgrid[2, 2].Rank);

            // bottom right
            sodoku[7, 8] = new CellContent(1);
            rank         = sodoku[7, 8].Rank;
            Assert.AreEqual(rank, sodoku[7, 8].Rank);
            row = sodoku.GetRowAt(8);
            Assert.AreEqual(rank, row[7].Rank);
            col = sodoku.GetColumnAt(7);
            Assert.AreEqual(rank, col[8].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(7, 8);
            Assert.AreEqual(rank, sgrid[1, 2].Rank);

            // middle
            sodoku[4, 5] = new CellContent(5);
            rank         = sodoku[4, 5].Rank;
            Assert.AreEqual(rank, sodoku[4, 5].Rank);
            row = sodoku.GetRowAt(5);
            Assert.AreEqual(rank, row[4].Rank);
            col = sodoku.GetColumnAt(4);
            Assert.AreEqual(rank, col[5].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(4, 5);
            Assert.AreEqual(rank, sgrid[1, 2].Rank);

            // middle bottom
            sodoku[5, 7] = new CellContent(2);
            rank         = sodoku[5, 7].Rank;
            Assert.AreEqual(rank, sodoku[5, 7].Rank);
            row = sodoku.GetRowAt(7);
            Assert.AreEqual(rank, row[5].Rank);
            col = sodoku.GetColumnAt(5);
            Assert.AreEqual(rank, col[7].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(5, 7);
            Assert.AreEqual(rank, sgrid[2, 1].Rank);

            Assert.IsTrue(sodoku.Validate());
            //sodoku.
        }
Ejemplo n.º 4
0
        public void TestBasics()
        {
            SodokuItem row = new SodokuItem();

            Assert.IsTrue(row.IsEmpty);
            Assert.AreEqual(9, row.EmptyCount);
            Assert.AreEqual(0, row.ContentCount);

            Assert.IsTrue(row.HasContent(new CellContent(0)));
            Assert.IsFalse(row.HasContent(new CellContent(1)));
            Assert.IsTrue(row.Validate());
        }
Ejemplo n.º 5
0
        public void TestDataManipulation()
        {
            List <CellContent> contentlist = new List <CellContent>
            {
                new CellContent(0), // 0, 0
                new CellContent(1), // 1, 0
                new CellContent(0), // 2, 0
                new CellContent(2), // 0, 1
                new CellContent(0), // 1, 1
                new CellContent(3), // 2, 1
                new CellContent(0), // 0, 2
                new CellContent(4), // 1, 2
                new CellContent(5), // 2, 2
            };

            Sodoku3x3 grid = new Sodoku3x3(contentlist);

            Assert.AreEqual(grid[0, 0], new CellContent(0));
            Assert.AreEqual(grid[1, 0], new CellContent(1));
            Assert.AreEqual(grid[0, 1], new CellContent(2));
            Assert.AreEqual(grid[2, 1], new CellContent(3));
            Assert.AreEqual(grid[2, 2], new CellContent(5));

            SodokuItem t1 = new SodokuItem(contentlist);
            SodokuItem t2 = grid.ToSodokuItem();

            for (int idx = 0; idx < 9; idx++)
            {
                Assert.AreEqual(t1[idx], t2[idx]);
            }

            List <CellContent> col = grid.GetColumn(2);

            Assert.AreEqual(col[0], grid[2, 0]);
            Assert.AreEqual(col[1], grid[2, 1]);
            Assert.AreEqual(col[2], grid[2, 2]);

            List <CellContent> row = grid.GetRow(1);

            Assert.AreEqual(row[0], grid[0, 1]);
            Assert.AreEqual(row[1], grid[1, 1]);
            Assert.AreEqual(row[2], grid[2, 1]);
        } // TestDataManipulation
Ejemplo n.º 6
0
        public void TestAddReplaceContent()
        {
            SodokuItem column = new SodokuItem();

            column[0] = new CellContent(9);
            Assert.IsFalse(column.IsEmpty);
            Assert.AreEqual(1, column.ContentCount);
            column[1] = new CellContent(8);

            Assert.ThrowsException <ArgumentException>(() => column[2] = new CellContent(9));
            Assert.AreEqual(2, column.ContentCount);

            column.ClearCell(1);
            Assert.AreEqual(1, column.ContentCount);
            column[1] = new CellContent(8);
            column[2] = new CellContent(7);

            Assert.ThrowsException <InvalidOperationException>(() => column.InsertItem(new CellContent(6), 2));
            List <int> ranks = column.AvailableRanks();

            Assert.AreEqual(6, ranks.Count);
            Assert.AreEqual(1, ranks[0]);
            Assert.AreEqual(2, ranks[1]);
            Assert.AreEqual(6, ranks[5]);

            column[3] = new CellContent(6);
            column[4] = new CellContent(5);
            column[5] = new CellContent(4);
            column[6] = new CellContent(3);
            column[7] = new CellContent(2);
            Assert.AreEqual(8, column.ContentCount);
            ranks = column.AvailableRanks();
            Assert.AreEqual(1, ranks.Count);
            Assert.AreEqual(1, ranks[0]);

            column[8] = new CellContent(1);
            Assert.IsTrue(column.IsFull);
            Assert.IsTrue(column.Validate());

            //Assert.ThrowsException<InvalidOperationException>(() => column.InsertItem(new CellContent(9), 5) );
        }
Ejemplo n.º 7
0
        public void TestAvailbleItems()
        {
            SodokuItem item = new SodokuItem();

            Assert.AreEqual(9, item.AvailableRanks().Count);
        }