A Harder Test
Now its time to see if we can really detect a scoring position. The
test is simple to write (although we had to draw the board on a piece
of paper to make sure we got our indices correct).
# file: testnet.rb
...
def test_score_simple_board
@net[2,1] = :BLACK
@net[1,2] = :BLACK
@net[2,3] = :BLACK
@net[3,2] = :BLACK
assert_equal 1, @net.score(:BLACK)
end
...
|
After writing this test, we decided that there was a smaller step we
could take. Instead of trying to write score from scratch, we will
first write a helper function (score_at) that will score a
stationary location on the board. The test for score_at initially
looks like this.
# file: testnet.rb
...
def test_score_at
@net[2,1] = :BLACK
@net[1,2] = :BLACK
@net[2,3] = :BLACK
@net[3,2] = :BLACK
assert_equal 1, score_at(2,2,:BLACK)
end
...
|
Running this test produced two problems, one for score and one for score_at.
| | | ...
Error occurred in test_score_at(TestNet): NameError: undefined method `score_at' for #<TestNet:0x402173ac>
...
Error occurred in test_score_simple_board(TestNet): NameError: undefined method `score' for #<TestNet:0x40217474>
...
|
My intention is to work on score_at for the moment and will return
to score later. We write down score on our todo list and rename
the test for score so that the testing framework won't pick it up.
This way it won't distract us while we work on score_at.
# file: testnet.rb
...
def xtest_score_simple_board
...
end
...
|