Program testing does not end when errors are found. The real value of testing comes from correcting those errors and ensuring the program works correctly afterward. This stage is part of program maintenance and debugging.
An error is a flaw in a program that causes it to produce incorrect results, crash, or behave unexpectedly.
Errors are often called bugs, and the process of fixing them is called debugging.
These occur when the program breaks the rules of the programming language.
Examples:
IF x > 5
PRINT x
Correction:
IF x > 5 THEN
PRINT x
ENDIF
These are usually detected automatically by the compiler or interpreter.
These occur when the program runs but produces incorrect results.
Example:
area = length + width
Correction:
area = length * width
The program runs, but the formula was wrong.
These occur during program execution and cause the program to crash.
Example:
average = total / count
If:
\[
count = 0
\]
Correction:
IF count > 0 THEN
average = total / count
ENDIF
This prevents division by zero.
Correcting errors follows a logical process.
Use:
Find the exact line causing the problem.
This can be done using:
Modify the faulty code.
Example:
total = total - price
Corrected version:
total = total + price
This ensures:
This is called:
Regression testing
A trace table helps track how variables change during execution.
Example program:
sum = 0
FOR i = 1 TO 3
sum = sum + i
NEXT i
PRINT sum
Trace table:
| i | sum |
|---|---|
| 1 | 1 |
| 2 | 3 |
| 3 | 6 |
If output was wrong, the trace table helps find where the mistake happened.
After fixing errors, the program must be tested again using:
This ensures the correction works in all situations.
Failure to correct errors can lead to:
Example:
An incorrect calculation:
\[
\text{Total} = \text{Price} - \text{Tax}
\]
Instead of:
\[
\text{Total} = \text{Price} + \text{Tax}
\]
This could cause financial loss.
Correcting errors is part of:
Corrective maintenance
Other maintenance types include:
1. Define debugging.
2. Describe how a trace table helps correct errors.
3. Explain why programs must be retested after correction.
4. Identify and correct the error:
average = total / count
where count may be zero.
5. State two types of maintenance.