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.
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.
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.
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.