For the last two weeks I have been working on test driven development (or TDD). It has been a challenging experience working my way through exercise 48 - building a Lexicon.
So far I’ve only written code for the first ‘asser_equal’ in the test provided in the book. Here are the learnings so far:
- Understand the overall problem first, tackle the code later.
- Break the problem down by writing comments in your own words - method known as writing “pseudo code”.
- Hashes aren’t as scary as they seem and I learnt a lot more than what’s in the book by researching into the problem. I took a good look at the ruby docs on hashes found here and here and also arrays.
- You can have blocks inside of blocks, this I didn’t know and just thought I’d try - and it worked!
- Make sure you write a return statement at the end of the block - otherwise the test keeps failing.
Tackling the first two points took me the longest. Once I had that figured out, the coding part became much easier. This is only step one of the problem so far - more to come!
The test was:
test_lexicon.rb
The corresponding code that I wrote was:
lexicon.rb
comments powered by