Program Testing
Program Testing
3. (a) Describe each of the following types of program error, giving an example in each case.
(b) Describe two methods used to assist in finding program errors. [4]
May/June 2004
3 (b) Explain what is meant by the following types of programming error. Give an example in each case.
(i) Syntax.
(ii) Logic.
(iii) Arithmetic. [6]
May/June 2008
2. (c) When a computer runs a program, the program may fail to run successfully because there are errors in the
code.
Describe two types of error that may be present, giving an example of each. [6]
Page 1 of 9
May/June 2011. P23
1 Jodelle needs to write program code that will check the password to her personal computer.
It checks each attempt to enter the password and closes the screen after three wrong attempts.
Jodelle first produces her solution using pseudocode. She wants the password to be 'poppy', the name of her cat.
Attempt ← 1
REPEAT
INPUT Password
Attempt ← Attempt +1
IF Password = “poppy”
THEN
ELSE
ENDIF
(i) One way to correct this is to change the first line. Rewrite this line to make the pseudocode correct. [1]
(ii) State the type of error that Jodelle made. [1]
1 Ahmed is writing a program to record the data of members of the school football squad.
(g) The squad has 30 players. Ahmed stores the records in an array called Squad. To calculate how many players are
defenders he designs this pseudocode:
Page 2 of 9
Dtotal ← 0
ArrayPosition ← 1
REPEAT
IF Squad[ArrayPosition].Position = 'd'
THEN
Dtotal ← Dtotal + 1
ENDIF
ArrayPosition ← ArrayPosition + 1
UNTIL ArrayPosition = 30
This pseudocode will only consider the first 29 records in the array.
2 Philipe is trying different ways of designing the process of entering data into an array.
Element ← 1
INPUT Number[Element]
Element ← Element + 1
ENDWHILE
(b) (i) There appears to be an error in the above pseudocode. State the type of error. [1]
(ii) The error can be corrected by changing one line. Write the corrected line of pseudocode. [1]
Page 3 of 9
May/June 2012. P23
3 Liliane wants to write a program to play chess. She will represent the board of 8 x 8 squares, using the 2-
dimensional array Board[8,8].
Each element of the array will need initialising to zero. Later, if a chess piece is on a square, it will take a value of 1.
She starts by writing pseudocode for the initialisation of a 4 x 4 board. This is easier to trace.
01 RowNo ← 1
03 ColumnNo ← 1
05 Board[RowNo,ColumnNo] ← 0
06 ColumnNo ← ColumnNo + 1
07 ENDWHILE
08 RowNo ← RowNo + 1
09 ENDWHILE
(i) State when and how syntax errors are detected. [2]
4 (c) Meena has compiled the program and she thinks it is working.
Page 4 of 9
Oct/Nov 2013.P21
3 An array, MyResource, size 5000, data type INTEGER, is used to store the resource IDs.
An array, KeptIn, size 5000, data type STRING, is used to store where a resource is kept.
Juan writes the pseudocode that searches MyResource for a given resource ID and outputs where the resource is
kept.
flag ← 0
INPUT P
FOR X ← 1 TO 5000
IF myresource[X] = P
THEN
OUTPUT keptin[X]
flag ← 1
ENDIF
NEXT
IF flag = 0
THEN
ENDIF
Page 5 of 9
(e) (i) If Juan were to perform a dry run on the pseudocode using a trace table, state one type of error he might find.
Give an example.
State another type of error he might find later. Give an example. [4]
Oct/Nov 2013.P22
3 Aisha wants to write a program that checks the password to her personal computer. The program should check
each attempt to enter the password correctly and should terminate after three wrong attempts.
Aisha writes her first try at designing the code in pseudocode. She wants the password to be "Aisha", her name.
1 Attempt ← 0
2 REPEAT
3 INPUT Password
4 Attempt ← Attempt + 1
6 IF Password = "Aisha"
7 THEN
9 ELSE
11 ENDIF
(c) This piece of code does not do what Aisha intended. There is an error.
Page 6 of 9
Oct/Nov 2013.P23
3 An array, Catalog, size 8 000, data type INTEGER, is used to store the equipment IDs.
An array, KeptIn, size 8 000, data type STRING, is used to store where a piece of equipment is kept.
A piece of equipment with equipment ID Catalog[X] is kept at KeptIn[X] where X is an integer variable.
Ashvin writes the pseudocode that searches Catalog for a given equipment ID. The output is to be where the piece of
equipment is kept.
flag ← 0
INPUT P
FOR X ← 1 TO 8 000
IF catalog[X] = P
THEN
OUTPUT keptin[X]
flag ← 1
ENDIF
NEXT
IF flag = 0
THEN
ENDIF
Page 7 of 9
(e) Ashvin will perform dry runs on the pseudocode using a trace table and a variety of test data. He hopes to find
any logic errors and avoid run-time errors occurring later.
(i) State what is meant by a logic error and give an example. [2]
(ii) State what is meant by a run-time error and give an example. [2]
May/June 2015.P21/P22
2 The pseudocode below is intended to calculate the sum of a sequence of integers input.
DECLARE x : INTEGER
x ← 0
Result ← 0
WHILE x <> -1
INPUT x
Result ← Result + x
ENDWHILE
OUTPUT Result
Oct/Nov 2015.P21/P23
Oct/Nov 2015.P22
2 (f) Ali has written the final program code. There are syntax and logic errors in his program.
(i) Describe when and how syntax errors are detected. [2]
(ii) Describe when and how logic errors are detected. [2]
Page 9 of 9