Testing CS Thinking Example 1

Follow the full solution, then compare it with the other examples linked below.

Example 1

easy
A function isEven(n) should return TRUE if n is even and FALSE otherwise. Suggest three test cases, including a normal, boundary, and erroneous value.

Solution

  1. 1
    Step 1: Normal test: isEven(4) should return TRUE. This tests typical valid input.
  2. 2
    Step 2: Boundary test: isEven(0) should return TRUE. Zero is an edge case that is technically even.
  3. 3
    Step 3: Erroneous test: isEven('hello') should handle the invalid input gracefully (return an error or FALSE). This tests that the function does not crash on bad input.

Answer

Normal: isEven(4) โ†’ TRUE. Boundary: isEven(0) โ†’ TRUE. Erroneous: isEven('hello') โ†’ error/FALSE.
Good testing uses normal data (typical valid input), boundary data (edge cases at limits), and erroneous data (invalid input). This ensures the program works correctly in all situations.

About Testing

Systematically running a program with known inputs to verify that its outputs are correct. Testing involves designing test cases that cover normal inputs, boundary values, and error conditions, then comparing actual results against expected results.

Learn more about Testing โ†’

More Testing Examples