| [ next ] [ prev ] [ contents ] | XP-Cinti TDD Workshop |
NOTE: I going to deviate a bit from actuall events at this point. What really happened is that Mark and I made wholesale changes to our tests to support the new syntax. Then we implemented the new syntax for the net object. I think I can do the change more incrementally and will present the series of changes here.
The first test adds support for the basic indexing operation.
# file: testnet.rb
...
def test_tied
assert_equal true, ! @net.tied?(1,1)
assert_equal :EMPTY, @net[1,1] # NEW
end
...
|
The implementation was straight forward
# file: net.rb
...
def [](x,y)
@tied[x-1][y-1]
end
...
|
But the tests gave this error ...
... Failure occurred in test_tied(TestNet) [testnet.rb:12]: Expected <EMPTY> but was <false> ... |
This can be fixed by initializing the array to :EMPTY instead of false. But this will cause the tied? method to break (it is expected to return a true/false value). So we fix that as well.
# file: net.rb
...
def initialize
@tied = (1..MAXSIZE).collect {
(1..MAXSIZE).collect {:EMPTY}
}
end
...
|
I though that would work, but the tests report ...
$ ruby testnet.rb Loaded suite testnet Started... .. Failure occurred in test_max_matrix_size(TestNet) [testnet.rb:46]: Expected <false> but was <true> .... Failure occurred in test_untie(TestNet) [testnet.rb:31]: Expected <false> but was <true> Finished in 0.063337 seconds. 5 runs, 11 assertions, 2 failures, 0 errors |
Checking the tests, we discover that the untie method stores a false value. We will need to change this.
# file: net.rb
...
def untie(x,y)
@tied[x-1][y-1] = :EMPTY
end
...
|
And the tests are OK once again. On to the next step.
| [ next ] [ prev ] [ contents ] | Copyright 2003 by Jim Weirich.![]() |