Posts

Showing posts with the label explicit code

Making Data Relationships Obvious

When you are writing tests you end up using literals or hand-constructed data objects. However, using literals can obscure the meaning a little. Not horribly; most people can puzzle them out quickly enough, but you can make it easier on the reader. In most of these tests, the values are pretty much arbitrary, but the relationship between the values is essential. For instance, when checking that no bonus is given when sales is less than quota, I could state that sales is 10,000.00 and that the quota is 9,900.00.  Pretty much anyone could tell that the quota is less than sales here, right? But what if we made it really explicit?      double quota = 10000;      double sales = quota - 100; This is how I like to roll. For instance, in python:      event_date = datetime(2015,9,10)      later = event_date + timedelta(days=10)      earlier = event_date - timedelta(days=2) And how ...