2.4.3 Testing Strategies
2.4.3 Testing Strategies
3. An algorithm has been produced which inputs two numerical values and outputs the larger one.
Select three pairs of numbers that could be used as test data. Explain what each pair of numbers is intended to test.
[6]
May/June 2004
The individual modules in the program have been fully tested and there are no errors in any of them.
Explain why the program may fail to run or may produce incorrect results, despite the testing that has been done. [2]
May/June 2007
6. D=1
INPUT X, E
B=E
C=E
FOR I = 1 TO (X-1)
INPUT A
IF A>B THEN B = A
END IF
END IF
D = D + 1
E = E + A
NEXT
F = E/D
OUTPUT B, C, F
END
(b) Give three other different sets of test data, explaining what condition each is meant to test. [3]
Page 1 of 19
Computer Science 9608
Topical Past Papers
1 Ahmed, a designer, stores the following details of each job that he does in a file.
State four items of data you would use to test the JobID validation.
[8]
3 Kris has written a program that will work out the wages for her staff. The main steps for each employee are: to
work out the hours worked, work out the total earnings, work out tax and finally print out how much will be taken
home.
For each employee the hours worked module collects data for five days. If they do not work on a particular day a
zero is entered. Each person can work up to 9 hours a day for up to 5 days a week. The hours are added up; no-one
may work more than 40 hours.
Write five sets of test data which test the module for different inputs/outcomes.
For each set of test data, give a reason for your choice.
Page 2 of 19
[10]
2 Nathan is designing a software solution for stock control in a mobile phone shop. He has a colleague, called Andre,
who will help him write the program. Nathan decides to modularise the solution.
Page 3 of 19
Oct/NOV 2011 P22
(ii) Nathan has written the PhoneSales module, which now needs testing.
Give six different items of test data other than invalid data which thoroughly test the two rules given above. Give a
reason for each choice.
[6]
Page 4 of 19
Oct/NOV 2011 P23
1 Nathan is designing a software solution for stock control in a computer shop. He has a colleague, called Andre, who
will help him write the program. Nathan decides to modularise the solution.
Give six different items of test data, other than invalid data, which thoroughly test the two rules given
above. Give a reason for each choice.
[6]
Page 5 of 19
May/June 2013. P21/22
(c) (i) Meena uses three items of data to test this logic. In the table below enter ‘normal’ or ‘borderline’ in the empty
cells.
(ii) State the reason why this invalid HandInDate is not a good test of the validation rules. [1]
(iii) State three hand-in dates that provide a better test to show that invalid data does not get entered. [3]
1 Jemma is designing a program that will work out the end of year bonuses for her employees. The main steps are:
(d) Jemma is designing a range validation check for the input of an employee’s pay. The pay range depends on the
employee’s job type, which may be P(part-time), F(full-time) or C(commission only).
Complete the table showing five more rows of test data. Give a different reason for each, describing what is being
tested.
Page 6 of 19
[5]
Oct/Nov 2014.P21/P23
1 Rema surveys the students in her class to find out which is the most popular sport.
Rema plans to collect sport data from students in the whole school. She designs a program to:
Page 7 of 19
Cricket ← 0
Football ← 0
Tennis ← 0
Swimming ← 0
REPEAT
INPUT Choice
CASE Choice OF
1: Cricket ← Cricket + 1
2: Football ← Football + 1
3: Tennis ← Tennis + 1
4: Swimming ← Swimming + 1
ENDCASE
UNTIL Choice = 0
Her friend Aisha suggests that the pseudocode could be improved by:
• using a one-dimensional array, Tally, instead of four variables to store the counts
• modularising the design. The main program should just consist of three procedure calls:
InitialiseArrayCounts
InputStudentChoices
OutputTallyChart
(d) Rema wants to test each module before she tests the whole program.
The first module she is going to test is the OutputTally procedure using different parameter values.
Page 8 of 19
[9]
Oct/Nov 2014.P22
3 A game is played by two players. Player A uses white tokens ( ). Player B uses black tokens ( ). The players
take turns dropping tokens into a vertical grid. The tokens fall straight down and occupy the next available space in
the chosen column. The aim of the game is to connect four of one’s own colour tokens. This must be done in a
vertical, horizontal or diagonal line.
Here is one example after Player A has had 2 turns and Player B has had 1 turn:
Nathan wants to write a program to allow two users to play the game on the computer.
The program will display a simplified version of the above grid which is redrawn after every turn.
(c) To drop a token into the grid, the player enters the chosen column number.
The function ColumnNumberValid has a parameter (x) which is the chosen column number. The function
returns:
• TRUE if x is between 1 and 7 inclusive and there is still space in the column
• FALSE otherwise
Page 9 of 19
(ii) Nathan wants to test the validation of the parameter, x, by this function.
[9]
May/June 2015.P21/P22
The players take turns in placing their marker in an empty cell of the grid; player O always starts.
The game ends when one player completes a row, column or diagonal or the grid is full.
• the row and column numbers are within the range 1 to 3 inclusive
• the cell is empty
Page 10 of 19
Ali chooses a sequence of six pairs of integer values to simulate player input. The test starts with an empty grid.
(i) Show the contents of the grid after the input of each pair of integer values. Circle whether the input is
valid or invalid. If the input is invalid state the reason.
[6]
(h) When Ali has tested all individual modules he plans to do further testing.
Page 11 of 19
May/June 2015.P23
(b) Ahmed wants to carry out white box testing of the function.
Give four integers which thoroughly test the function. For each one, give the expected return value and justify your
choice.
Page 12 of 19
[4]
(c) When Ahmed has tested the function, he plans to use it in a program.
Give two types of testing that Ahmed could do with the completed program. [2]
Oct/Nov 2015.P21/P23
2 Alia received a number coded as a sequence of letters. She wants to write a program to change this sequence of
letters back to the original number. She knows that each digit of the original number was replaced by exactly one
letter. The letters used are shown in the flowchart below.
She has drawn the flowchart as part of the design for her solution.
The function DenaryDigit(Letter) returns an integer.
Page 13 of 19
(a) (ii) Alia needs to test this function before using it in her program.
Complete the table of test data.
[3]
Page 14 of 19
Oct/Nov 2015.P22
2 At the end of movies, when credits are listed, the year of production is often shown in Roman
numerals.
Roman numbers are formed by combining letters together and adding their value. The letters used
and their values are:
M: 1000
D: 500
C: 100
L: 50
X: 10
V: 5
I: 1
For example, MMXV is 1000 + 1000 + 10 + 5 = 2015.
Ali wants to write a program to convert a year written in Roman numerals to denary.
He has drawn the flowchart as part of the design for his solution.
(a) (ii) Ali needs to test this function before using it in his program.
Complete the table of test data.
Page 15 of 19
[3]
(d) The order of letters in Roman numbers is significant. Letters are placed from left to right, in
order of value, starting with the largest.
However, a sequence of four identical letters (such as IIII) is shortened as follows.
If a letter to the left is of lower value than the letter to its right, the left letter’s value becomes
negative.
Examples are shown in the following table:
Ali has to amend his pseudocode to include the conversion of these shortened Roman
numbers.
Ali has chosen some test data.
Complete the table.
[4]
Page 16 of 19
Computer Science (9608)
May/June 2015.P21/P22
1 A marathon runner records their time for a race in hours, minutes and seconds.
[6]
Oct/Nov 2015.P21/P23
Page 17 of 19
01 INPUT InA
02 INPUT InB
03 IF (InA = FALSE AND InB = FALSE) OR (InA = FALSE AND InB = TRUE)
OR (InA = TRUE AND InB = FALSE)
04 THEN
05 OutZ ← TRUE
06 ELSE
07 OutZ ← FALSE
08 ENDIF
09 OUTPUT OutZ
(a) The programmer chooses the following four test cases.
Show the output (OutZ) expected for each test case.
[4]
Oct/Nov 2015.P22
01 INPUT P
02 INPUT Q
Page 18 of 19
03 IF (P = 1 AND Q = 0) OR (P = 0 AND Q = 1) OR (P = 0 AND Q = 0)
04 THEN
05 X ← 0
06 ELSE
07 X ← 1
08 ENDIF
09 OUTPUT X
(a) The programmer chooses the following four test cases.
Show the output (X) for each test case.
[4]
Page 19 of 19