コード例 #1
0
ファイル: UnitTest_Sodoku.cs プロジェクト: CyMark/SodokuLib
        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.
        }
コード例 #2
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