Esempio n. 1
0
        private static void CellTest2()
        {
            Debug.WriteLine( "Testing Accessors..." );

            const int range = 9;

            // Locked accessors
            SudokuEngine.Cell cell = new SudokuEngine.Cell( range );
            bool locked = cell.Locked;
            cell.Locked = !locked;
            Debug.Assert( locked != cell.Locked, "FAILURE: Locked interface" );

            // Entry accessors
            cell.Locked = false;
            int entry = 1;        // entry must be in [1, range - 1] for test to be valid.
            cell.Entry = entry;   // Attempt to set in range
            Debug.Assert( cell.Entry == entry, "FAILURE: Entry interface" );

            cell.Entry = entry + range; // Attempt to set out of range.
            Debug.Assert( cell.Entry == range, "FAILURE: Entry interface" );

            cell.Locked = true;
            cell.Entry = entry + 1; // Attempt to set when locked.
            Debug.Assert( cell.Entry == range, "FAILURE: Entry interface" );

            // Hints accessors
            bool[] hints = { true, false, true, true, false, false, false, true, true };
            cell.Hints = hints; // Attempt to set when locked
            Debug.Assert( hints[ 0 ] != cell.Hints[ 0 ], "FAILURE: Hints interface" );

            cell.Locked = false;
            cell.Hints = hints;
            for ( int idx = 0; idx < range; ++idx )
            {
                Debug.Assert( hints[ idx ] == cell.Hints[ idx ], "FAILURE: Hints interface" );
            }

            bool[] shortHints = { false, false, true }; // MUST BE LAST TEST OF FUNCTION!
            try
            {
                cell.Hints = shortHints;
            }
            catch ( ArgumentOutOfRangeException )
            {
                return;
            }
            Debug.Assert( false, "FAILURE: Hints interface" );
        }
Esempio n. 2
0
        private static void CellTest3()
        {
            Debug.WriteLine( "Testing Interfaces..." );

            const int range = 9;

            // toggleHint()
            SudokuEngine.Cell cell = new SudokuEngine.Cell( range );
            bool[] hints = cell.Hints;
            for ( int idx = 0; idx < range; ++idx )
            {
                cell.toggleHint( idx );
                hints[ idx ] = !hints[ idx ];

                for ( int chk = 0; chk < range; ++chk )
                {
                    Debug.Assert( hints[ chk ] == cell.Hints[ chk ], "FAILURE: toggleHints interface" );
                }
            }

            cell.Locked = true;
            for ( int idx = 0; idx < range; ++idx )
            {
                cell.toggleHint( idx );
                hints[ idx ] = !hints[ idx ];
                Debug.Assert( hints[ idx ] != cell.Hints[ idx ], "FAILURE: toggleHints interface" );
            }
        }
Esempio n. 3
0
        private static void CellTest1()
        {
            Debug.WriteLine( "Testing Construction and Initialization..." );

            const int range = 9;
            SudokuEngine.Cell cell = new SudokuEngine.Cell( range );
            Debug.Assert( cell.Entry == 0, "FAILURE: member initialization" );
            Debug.Assert( !cell.Locked, "FAILURE: member initialization" );
            Debug.Assert( cell.Hints.Length == range, "FAILURE: member initialization" );

            foreach ( bool hint in cell.Hints )
            {
                Debug.Assert( !hint, "FAILURE: hint initialization" );
            }
        }