| [ next ] [ prev ] [ contents ] [ skip to Another Refactoring ] [ up to Some Loose Ends ] | XP-Cinti TDD Workshop |
At this point Mark and I reviewed our code and noticed that the customer wanted an tied? method instead of an untied? method. We had named the query function incorrectly and implemented the reverse logic.
No problem. We add a new assertion to our first test so that it now also called tied? in addition to untied?.
# file: testnet.rb
...
def test_untied
assert_equal true, @net.untied?(1,1)
assert_equal false, @net.tied?(1,1) # NEW
end
...
|
We ran our tests and they failed (I will spare you the output at this point). We then implemented tied? in terms of untied?.
# file: net.rb
...
def tied?(x,y)
! untied?(x,y)
end
def untied?(x,y)
! @tied[x-1][y-1]
end
|
This passed all the tests. So then we reversed the implementation of tied? and untied? so that untied? used tied?.
# file: net.rb
...
def tied?(x,y)
@tied[x-1][y-1]
end
def untied?(x,y)
! tied?(x,y)
end
|
The tests still pass. Now we rewrote all the untied? tests in our test to use tied? instead, and changed the sense of the tests as appropriate. This was a little tedious, but not really difficult.
Running the tests showed that everything was still running.
The last step in this refactoring was to remove the untied? method from the Net class and check to see the tests still passed (they did).
The code for the unit tests and Net class at this point in the
process can be found here.
| [ next ] [ prev ] [ contents ] [ skip to Another Refactoring ] [ up to Some Loose Ends ] | Copyright 2003 by Jim Weirich.![]() |