All programs need to be thoroughly tested.
For example, in VB programming, if you only wanted to accept input values between 1 and 20 then you should display an error message if the user enters an invalid value.
A statement using VB syntax to produce this error message would be:-
MsgBox "Value should be between 1 and 20. You entered " & InputValue & "Try Again!"
Testing strategy - A strategy to ensure that a final solution to a problem meets the original requirements of the user.
Test plan - A document that details the scope, approach, resources, and schedule of intended test activities. Used to record the test data used and test outcomes.
Typical/standard data - Data that is valid and should be processed correctly by the program, used to check validation rules and to confirm accuracy by comparing results with previously calculated outcomes, i.e. testing for logical errors.
Extreme/boundary data - Data that is valid but is at the extreme boundary of an acceptable range of values. Used to confirm data ranges have been correctly set. e.g. 1 or 5 for a film rating between 1- 5
Erroneous data - Data that would cause the program to fail if not validated and rejected. e.g. enter String "five" for a film rating with integer 1-5 input.
Sort Algorithms - Duplicate values, accending order, decending order, negative numbers
Searching Algorithms - test with value in array, test with value not in the array
Algorithms - variety of data types (some expected others would be erroneous - see above)
Syntax Errors - Occur when the program code written by the programmer cannot be translated into source code.
Python example: PRINT(Hello World)
identifer should be lowercase i.e. print
Logical Error - This will compile and run but will not produce the expected outcome.
Example: a program intended to multiply two numbers contains the line:
answer = num1 + num2
Run-Time Errors - The program will again compile and run. The error occurs at run time and can be caused by impossible arithmetic calculations, overflows, or running out of memory.
Example: divide by zero, accessing a memory address which does not exist.
Dry Run- Old fashioned paper and pencil.
IDE tools - Watch and Trace, Cross Referencing, Setting Breakpoints. (see Unit 1.12 Software Engineering)
To dry run an algorithm you should list all inputs, processes and outputs in the columns of a trace table. Then you can show each line number on a row (remember some lines will be excuted serveal times if iteration/looping is used).
Algorithm:
1. Declare Num1, Num2, Multiplier, Answer, Counter As Integer
2.
3. Multipler = 2
4. Num1 = 1
5. Num2 = 4
6.
7. Do While Multiplier < 4
8. For Counter = Num1 to Num2
9. Answer = Counter * Multiplier
10. Add_to_the_display: Counter & "Times" & Multiplier & " = " & Answer
11. Next Counter
12 Multiplier = Mulitplier + 1
13. Loop
Trace Table:
Sort Algorithms - Duplicate values, accending order, decending order, negative numbers
Searching Algorithms - test with value in array, test with value not in the array
Algorithms - variety of data types (some expected others would be erroneous - see above)
Exam Question:
This is an algorithm which should have four outputs, a, b, c and d. The algorithm does not work as intended.
(a) State the outputs that this algorithm will give [2]
The outputs that this algorithm will give are 0 and 1
(b) Explain why this algorithm does not work as inteded [4]
This algorithm does not work as intended. The algorithm will not output c or d as they are undefined. This is because the scope of c and d lies within the function myFunction. C and D are local variables to myFunction.
The lifetime of the data stored in each variable end when myFunction ends. Variables c and d are not available to the main program.