Test Case Generation Self-Assessment

 

[This self-assessment test was excerpted from The Art of Software Testing 1st Ed., by Glenford Myers, ©1979 John Wiley & Sons (2nd Ed pub. 2004)]

Program Description:

The program reads three integer values from the console.  The three values represent the lengths of the sides of a triangle.  The program prints a message that states if the triangle is equilateral (all sides the same length), isosceles (two sides the same length), or scalene (all sides have different lengths).

Your Task

Write down a set of test cases (i.e., specific sets of data) that you feel would thoroughly test such a program.

This program turns out harder than it looks, and over the years many versions have been written (no doubt by students who were given this program as an assignment!) and tested.  A list of common errors, nearly all of which have occurred in one version of the program or another, have been compiled.  Before looking at the list below, try to come up with your own list.

Don't peek!

Show/Hide Answer (+/-)

Check your test cases against this list.  Did you include:

  1. A test case for a valid scalene triangle?  (Note that test cases such as "1,2,3" and "2,5,10" do not warrant a "yes" answer here, as there is no possible triangle with such sides.)
  2. Three (or more) test cases for a valid scalene triangle, with legal but unusual values (boundary value testing)?  (E.g., "1, 4, 5", "65536, 65537, 1", "100000000, 1, 1000000001", etc.)
  3. A test case for a valid equilateral triangle? (e.g., "3, 3, 3")
  4. Three (or more) test cases for a valid equilateral triangle, with legal but unusual values (boundary value testing)?  (E.g., "1, 1, 1", "65536, 65536, 65536", "100000000, 100000000, 1000000000", etc.)
  5. Three test cases for a valid isosceles triangle, with the odd side in each possible position?  (E.g., "3, 3, 2", 3, 2, 3", and "2, 3, 3".  Note that a test case such as "2,2,4" doesn't count, as there is no possible triangle with such sides.)
  6. Three (or more) test cases for a valid isosceles triangle, with legal but unusual values (boundary value testing; see above for examples)?
  7. Three test cases where one side has a value of "0", in each position?
  8. Three test cases where two sides has a value of "0", in each position?
  9. One test case where all three sides have the value "0"?
  10. Three test cases where one side has a negative value, in each position (e.g., "-2, 5, 6")?
  11. Three test cases where two sides have negative values in each position (e.g., "-2, -3, 4")?
  12. One test case where three sides have a negative values (e.g., "-2, -3, -4")?
  13. Three or more test cases where one or more inputs have a leading plus sign, in each position (e.g., "+2, 5, 6")?
  14. Three test cases for invalid scalene triangles, such that the lengths of two sides sum to the third?  (e.g., "1,2,3", "1,3,2", and "3,2,1")
  15. Three test cases for invalid scalene triangles, such that the sum of the lengths of two sides is less than the third?  (e.g., "1,2,4", "12,30,15", and "10,3,4")
  16. Three test cases for invalid isosceles triangles, such that the sum of the lengths of the two same-length sides is equal to the length of the third side?  (e.g., "2,2,4", "2,4,2", "4,2,2")
  17. Three test cases for invalid isosceles triangles, such that the sum of the lengths of the two same-length sides is less than the length of the third side?  (e.g., "2,2,5", "2,5,2", "5,2,2")
  18. Three test cases with one or more non-integer numeric values, with the bad value(s) in all possible positions?
  19. Three test cases with one non-numeric (e.g., text) values, with the bad value in all possible positions?
  20. Three test cases with two non-numeric (e.g., text) values, with the good value in all possible positions?
  21. Three (or more) test cases with one, two, or all three of the numbers having one or more leading zeros?

  22. Four or more test cases with the wrong number of values?  (e.g., zero, one, two, or four (or more) values, rather than exactly three)
  23. Did you remember to specify the expected output (or Exception/Error) for each test case, in addition to the inputs?

Your score:  

Results

A study showed that highly experienced professional programmers, on the average, only score about 56%!

This shows that testing even a trivial program is not an easy task.  Now imagine you need to write test cases for a 100,000 line program, say an air-traffic-control system, or a payroll program.

Note this doesn't say that testing is pointless.  Rather it is a very valuable tool!  This just shows the difficulty of thoroughly testing any complex program.  100% coverage isn't a realistic goal of testing.