Abstract Unit Testing Simulator
Your co-worker has implemented a math parser, but doesn't think he needs to test it. You, of course, know that code must always be unit tested! Otherwise, when someone goes to "improve" it, they might not notice when they break something.
The parser can perform +,-,/, and *, and supports parentheses. It's easy enough to feed garbage input to the system, and all bets are off if you do. You're only interested in ensuring that valid inputs get back valid results. However, it should handle something like 1.5+3/2*(9-2*8/(-2)+9)-6/24
without a problem.
Write a series of expressions -- one per line -- of the form [expression] = [value]
, such as 1.5+3/2*(9-2*8/(-2)+9)-6/24 = 40.25
to test against the parser. Initially, the parser should work exactly as expected. Hitting the "Improve" button will cause something to break, though!
Try to write a series of equations that will allow you to notice when something has broken, and identify exactly what part of the parser has broken. Try to be as precise as possible, so your co-workers can spend less time trying to figure out what's wrong.
When you're comfortable with your ability to determine what's wrong, you can download the source of this application and try to write actual unit tests. We've already gone ahead and taken care of all the messy stuff, you just need to add your tests to /tests/test.js. Then if you open up /tests/index.html in your browser, they should run!
These unit tests are written in QUnit, which is javascript specific, but most unit testing frameworks are basically the same:
- Provide a statement
- Make an assertion of what the result should be