Algorithm Testing
24.1 Tracing and Testing Algorithms
Three types of errors: Syntax errors, run-time error, logic error
If the program can run, it do not have syntax errors.
Dry run:
run on paper (using a trace table)
similar with using raptor to run step by step
1. Prepare a set of test data (Data input)
2. Draw a trace table (It should contains all the variables in the program)
3. Simulate to run the program step by step.
4. write down the change of variable.
5. write down the values of all output
Test data
Valid Data
cover boundary case
Cover the whole range
Cover all path of the program
Invalid Data
It is no way to completely test a program.
Comparing different solutions to the same problem
- memory space
- running time
For example: the running time between sequential search and binary search
Sequential Search: O(N)
Binary search: O(log(N))