Professor: That’s nice. Wha t else did you do?
Maria: We couldn’t think of any systematic approach that would perform an ex-
haustive test. We simply tried to insert so me wrong numbers that violated only one
of the three conditions. If a number had violated more than one condition, then we
would only have been testing a condition that is violated first inside the setNumber()
method of Sudoku. We did the same test against the initial clues as well as against a
manually entered nu mber. At the end we also tried to enter the same numbe r in the
same cell twice.
This is our cod e:
var initial = [
[null, 5, 7, null, 4, null, null, 2, null],
[null, 3, 8, null, null, 2, 7, null, null],
[null, 1, null, 7, 3, null, null, null, null],
[null, 7, null, 2, 8, null, null, null, 3 ],
[3, null, 4, null, null, null, 1, null, 6 ],
[1, null, null, null, 6, 4, null, 7, null],
[null, null, null, null, 2, 7, null, 1, null],
[null, null, 1, 9, null, null, 2, 3, null],
[null, 4, null, null, 1, null, 5, 9, null]
];
var test = [];
var S = new Sudoku();
S.setClues(initial);
test.push(S.setNumber(2, 0, 0));
test.push(S.setNumber(8, 0, 0));
test.push(S.setNumber(9, 0, 3));
test.push(S.setNumber(6, 0, 0));
test.push(S.setNumber(6, 0, 5));
test.push(S.setNumber(6, 3, 0));
test.push(S.setNumber(6, 2, 2));
test.push(S.setNumber(6, 0, 0));
console.log(test);
S.print();
Mike: All except two of the calls to th e setNumber() method retur n false, which
was expected. At the end, the whole puzzle is written to the browser window and you
can see that numbe r six was inde ed successfully inserted to the upper left cell of the
puzzle.
228 Meeting 12. Using JavaScript to Control the Browser