| [ next ] [ prev ] [ contents ] [ up to Scoring Tests ] | XP-Cinti TDD Workshop |
It is important to always keep your code at its best. After review the score_at method, we decided the test was complicated enough to break into a separate function. So we applied the "Extract Method" refactoring, producing ...
...
def score_at(x, y, player)
surrounded?(x, y, player) ? 1 : 0
end
def surrounded?(x, y, player)
self[x-1, y] == player &&
self[x+1, y] == player &&
self[x, y-1] == player &&
self[x, y+1] == player
end
...
|
We run the tests to make sure the refactoring was successful, and all
the tests pass.
| [ next ] [ prev ] [ contents ] [ up to Scoring Tests ] | Copyright 2003 by Jim Weirich.![]() |