DSimon comments on Coding Rationally - Test Driven Development - Less Wrong

25 Post author: DSimon 01 October 2010 03:20PM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (82)

You are viewing a single comment's thread. Show more comments above.

Comment author: DSimon 29 September 2010 04:41:08PM 0 points [-]

I agree that it's not a particularly realistic example. Do you have any alternate suggestions? I'm trying to target people who are not so familiar with programing, and in doing so I valued simplicity over realism. However, assuming some of the readers go on to try some actual TDD, they might try graphics programming first and discover that it's unpleasantly frustrating to test.

Comment author: JGWeissman 29 September 2010 05:43:44PM 1 point [-]

Good example:

You want a program that can invert matrices. You write a test that calls the program, passing it a matrix. The test multiplies the original matrix with the result from the invert program, and verifies that the product is unity.

This is a good case to use TDD because the test is simpler than the program you are testing.

Also, an important part is to test edge/corner cases. In the matrix example, there should be a test that passes the invert program a singular matrix, and validates that it returns an appropiate error.