| [ next ] [ prev ] [ contents ] [ up to Scoring Tests ] | XP-Cinti TDD Workshop |
Here is our first try at score_at ...
...
def score_at(x, y, player)
if self[x-1, y] == player &&
self[x+1, y] == player &&
self[x, y-1] == player &&
self[x, y+1] == player
1
else
0
end
end
...
|
And this passes our tests. Just to be sure, we add a few more tests to test_score_at.
# file: testnet.rb
...
def test_score_at
assert_equal 0, @net.score_at(2,2,:BLACK)
@net[2,1] = :BLACK
@net[1,2] = :BLACK
@net[2,3] = :BLACK
@net[3,2] = :BLACK
assert_equal 0, @net.score_at(2,2,:WHITE)
assert_equal 1, @net.score_at(2,2,:BLACK)
assert_equal 0, @net.score_at(1,1,:BLACK)
assert_equal 0, @net.score_at(3,4,:BLACK)
end
end
...
|
And the tests still pass.
| [ next ] [ prev ] [ contents ] [ up to Scoring Tests ] | Copyright 2003 by Jim Weirich.![]() |