Пример #1
0
 public Board()
 {
     for (int i = 0; i < 9; i++)
     {
         sectors[i] = new Sector();
     }
 }
Пример #2
0
        static void SectorTests()
        {
            Sector s = new Sector();
            Debug.Assert(s[0] == Sector.UNKNOWN && s[8] == Sector.UNKNOWN, "Incorrect initialization of UNKNOWN values");

            Debug.Assert(s.ValidColumn(1), "ValidColumn fails for three UNKNOWNs");
            Debug.Assert(s.ValidRow(1), "ValidRow fails for three UNKNOWNs");

            s[4] = '4';
            Debug.Assert(s[4] == '4', "Sector assignment does not work");

            Debug.Assert(s.ValidRow(2), "ValidRow returns false for two UNKNOWN values in a row");
            s[5] = '5';
            Debug.Assert(s.ValidRow(2), "ValidRow returns false for two unique values in a row");
            s[5] = '4';
            Debug.Assert(s.ValidRow(2) == false, "ValidRow returns true for two nonunique values in a row");
            s[3] = '3';
            s[5] = '5';
            Debug.Assert(s.ValidRow(2), "ValidRow returns false for three unique values in a row");

            Debug.Assert(s.ValidRow(1), "ValidRow works on row 1");
            Debug.Assert(s.ValidRow(3), "ValidRow works on row 3");

            Debug.Assert(s.ValidColumn(1) && s.ValidColumn(2) && s.ValidColumn(3), "ValidColumn fails with 1 unique value in column");

            // Current state:
            // . . .
            // 3 4 5
            // . . .

            s[0] = '5';
            Debug.Assert(s.ValidColumn(1), "ValidColumn fails with 2 uniques");

            s[6] = '5';
            Debug.Assert(s.ValidColumn(1) == false, "ValidColumn should return false for two nonunique numbers");

            Debug.Assert(s.ValidSector() == false, "ValidSector fails with two repeating numbers in Column 1");
            s[6] = '6';
            Debug.Assert(s.ValidSector() == false, "ValidSector should return false");
            s[0] = '9';
            Debug.Assert(s.ValidSector(), "ValidSector should return true");

            // Current state:
            // 9 . .
            // 3 4 5
            // 6 . .

            Debug.Assert(s.UnusedValues().Count == 4, "UnusedValues doesn't work with 4 missing values");

            s[1] = '1';
            s[2] = '2';
            s[7] = '7';
            Debug.Assert(s.UnusedValues().Count == 1, "UnusedValues doesn't work with just 1 missing value");

            s[2] = '7';
            Debug.Assert(s.UnusedValues().Count == 2, "UnusedValues should ignore invalid sectors");

            s[2] = '2';
            s[8] = '8';

            Debug.Assert(s.UnusedValues().Count == 0, "UnusedValues doesn't work for no values left");
            Debug.Assert(s.UsedValues().Count == 9, "UsedValues should return 9 when they are all used");

            // Current state:
            // 9 1 2
            // 3 4 5
            // 6 7 8
        }