Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Worksheet 5 Testing

Unit 7 Algorithm design and programming

Worksheet 5 Testing
Task 1
The pseudocode program shown below is intended to model the calculation of the toll charge
for crossing a bridge on a motorway. Between 6am (0600hrs) and 10pm (2200 hrs) inclusive,
the charges are as follows:

Motorcycle £1.00 (Vehicle type 1)


Car £2.00 (Vehicle type 2)
Goods vehicle £2.50 (Vehicle type 3)
HGV and coaches £5.00 (Vehicle type 4)

After 10pm, up to but not including 6am, there is no charge.


Amanda writes the following pseudocode:
IF time <=0600 OR time >=2200 THEN
Charge = 0
ELSE
CASE Vehicle OF
1: Charge = 1.00
2: Charge = 2.00
3: Charge = 2.50
4: Charge = 5.00
ELSE
Charge = 0.00
ENDCASE
ENDIF

Complete the following test plan.

Test Data Expected


Data Actual
numbe (Vehicl Reason for test result for
(Time) result
r e type) Charge
1 1 1245 Valid time 1.00 1.00
2 2 0600
3
4
5

Are your tests sufficient to thoroughly test the program? What assumptions have been made?

_________________________________________________________________________

Is the logic of the program correct? If not, what should be changed?

_________________________________________________________________________

1
Worksheet 5 Testing
Unit 7 Algorithm design and programming

Task 2
The following program code is part of a game in which Mighty Max is engaged with the enemy,
dealing deathly blows in all directions to overcome the evil gremlins but taking considerable
punishment himself until he is fatally wounded.

wounds 🡨 0
gremlins 🡨 4
strength 🡨 30
WHILE strength > 0
IF gremlins>=1 THEN
wounds 🡨 wounds + gremlins
ENDIF
IF strength > 2 THEN
gremlins 🡨 gremlins -1
output “Mighty Max has dealt a deathly blow to a gremlin, but his strength is fading”
ENDIF
strength 🡨 strength - wounds
output "Wounds = ",wounds, "Gremlins = ",gremlins, " Strength = ", strength
ENDWHILE
output “Alas, our hero has been overcome… Game Over”

(a) Complete the next 4 rows in the following trace table.

Wounds Gremlins Strength Strength<>0

0 4 30 True

2
Worksheet 5 Testing
Unit 7 Algorithm design and programming

Task 3
When the creator of the game of chess showed his invention to the ruler of the country, the ruler
was so pleased that he gave the inventor the right to name his prize for the invention. The man,
who was very clever, asked the king this: that for the first square of the chess board, he would
receive one grain of wheat (in some tellings, rice), two for the second one, four on the third one,
and so forth, doubling the amount each time. (You can google the full story, “grains of wheat on
chessboard”)

A programmer decides to find out how many grains of wheat the inventor will end up with. He is
worried about causing an overflow error if the number is very large, so he tests the program with
just 6 squares of the chessboard.

A programmer decides to find out how many grains of wheat the inventor will end up with. He
tests the program with just 6 squares of the chessboard.

The program is shown below. Complete the trace table to show the total number of grains of
wheat received for the first 6 squares of the chessboard.

OUTPUT ("How many grains of wheat will be on each square?")


powerOf2 = 1
total = 1
FOR n = 2 To 6
powerOf2 = powerOf2 * 2
total = total + powerOf2
OUTPUT ("You have a total of ",total, “grains on squares 1 to”,n)
NEXT n

PowerOf2 Total n

1 1 2

3
Worksheet 5 Testing
Unit 7 Algorithm design and programming

4
Worksheet 5 Testing
Unit 7 Algorithm design and programming

Task 4
(a) The Post Office charges different rates for small, medium and large parcels.

Write a pseudocode algorithm to determine whether a parcel is small, medium or large. Set
a variable called size equal to ‘s’, ‘m’ or ‘l’ according to its size, and display a message to
tell the user whether the parcel is small, medium or large.

A small parcel must not exceed: Length 45cm, Width 35cm, Depth 16cm, Weight 2kg.

A medium parcel must not exceed: Length 61cm, Width 46cm, Depth 46cm, Weight 20kg.

A parcel larger than this cannot be posted.

(b) Complete the table below to show 6 sets of test data you could use to thoroughly test your
algorithm, and the expected result each time. Do not include invalid input data, since this
section of pseudocode does not include a validation routine.

Expected
Test
Length Width Depth Weight Reason for test output
number
(size)

Test “normal” data for


1 20 20 5 1.2 s
small parcel

2 45 35 16 2

3 45 35 16 3

4 50 20 20 1

5 61 46 46 20

6 62 10 10 2

Does your test plan comprehensively test your algorithm?

5
Worksheet 5 Testing
Unit 7 Algorithm design and programming

Task 5
In Worksheet 1 Task 3 you were given the following algorithm for a dice game. How could you
thoroughly test a program that simulates this game?
Complete the test plan below with test data and expected results.

Start

die1, die2 and Yes Score = die1 + die2 +


die3 equal? die3

No

Are two of the No


Score = 0
dice equal?

Yes

score = sum on two


equal dice

score = score - sum on


third die

End

Expected
Test Die1 Die2 Die3 Purpose of test
result
1 5 5 5 All dice equal 15

You might also like