| [ next ] [ prev ] [ contents ] | XP-Cinti TDD Workshop |
Now we will implement the ability to set an intersection to a particular value. First we need a test...
# file: testnet.rb
...
def test_place_token
@net[1,1] = :BLACK
assert_equal :BLACK, @net[1,1]
@net[1,1] = :WHITE
assert_equal :WHITE, @net[1,1]
@net[1,1] = :EMPTY
assert_equal :EMPTY, @net[1,1]
end
...
|
Running the test results in ...
... Error occurred in test_place_token(TestNet): NameError: undefined method `[]=' for #<Net:0x40210340> ... |
Implementing the "[]=" method is straightforward.
# file: net.rb
...
def []=(x, y, value)
@tied[x-1][y-1] = value
end
...
|
And the tests run.
| [ next ] [ prev ] [ contents ] | Copyright 2003 by Jim Weirich.![]() |