I blame the testing

It’s amazing what a day or two away can do. I came back to the tests with a fresh mind this morning and dealt with the issues that had caused me problems at the tail end of last week before I got my morning coffee.

Ok, so I don’t take coffee until 11.30. I still think I did pretty good…

I’d written the bulk of the tests on thursday evening. Unfortunately I’d made one of those mistakes that you just can’t see until you walk away and come back with a clean brain. The bug involved a cross currency FX forward rate. As usual it was an ’edge case’, ie one of the areas that was the most complex in the old version of the code. It was a cross currency from EUR->USD->CHF where there was a CHF holiday on the day that would otherwise be the USD->CHF spot day…

In summary, it was the same problem that we’ve had problems with for the last month or so, but the names and dates had changed. This time we nailed it; I think…

Throughout the FX testing and refactoring phase we’ve been trying to reduce the number of lines of code and make what’s left more simple and also make what’s left follows the way the examples in the text books work. In general we’re looking to end up with code that someone can understand without a great deal of thinking. The only comments we have are pointers to the books where we got the calcs from. The rest is named nicely and reads well; if we get a moment in the schedule we may even get some overview docs written (don’t hold anything).

So, I’d written a test on Thursday evening and it didn’t work and I stayed late looking at it and poking it and not really understanding why it didn’t work but needing to continue prodding it.

Today I looked at it and saw the problem; we were testing a particular situation, a bug that happens when there’s a CHF holiday on what would be the USDCHF spot day, we’d used our mock objects to set the world to X/Y/2003 and I’d poked a holiday into the system as Z/A/2004… 2004? Ooops.

Once that was fixed I got the results I expected. The test passed as it duplicated the exact conditions for the bug. I fixed the expected results and it failed. We could then run it again and again and again and step into the code to see what was wrong. Not surprisingly it was a bit of code that ’looked unbalanced’… The code looked wrong, we changed it to something that looked right. The tests all worked. We eyeballed lots of other test cases and all was good… Woo hoo!

Lesson learned? When it’s late in the day and you get a hard thing to do, go home. You’ll do it faster and better tomorrow.