Vous êtes sur la page 1sur 4

Desk Checking Algorithms

The basic idea of desk checking is that you step through the algorithm step by step and document each variable and how it changes as it goes through the algorithm.

Lets take an example algorithm:

 1 BEGIN displayGrade() 2 Input mark 3 IF mark >= 50 THEN 4 grade = "Pass" 5 Display "Well done" 6 ELSE 7 grade = "Not pass" 8 ENDIF 9 Display grade 10 END

Step 1: List the variables

Okay, first thing you do is list all the variables in the program. In this case, that is only mark and grade.

There is also, obviously, an output in any program. You input variables and output results in any program.

You also want to test a certain number of sets of data for the program. In an exam, they will normally tell you what data to test.

Step 2: Create the table

Step 3: The desk check

Now, you have to manually step through each line of the algorithm and record what happens (unless nothing happens). Our first set of data is going to be Mark=34

 Set Mark Grade Output 1 34

So, stepping through the algorithm…

Line 1 does nothing. Line 2, inputs mark

Line 3, IF mark >= 50 THEN Ok, so in your test data, is mark >=50? No, then skip lines 4 and 5 to the else statement.

Line 6 and 7.

 6 ELSE 7 grade = "Not pass"

This is a change of variable, so you have to record it on your deskcheck

 Set Mark Grade Output 1 34 Not Pass Line 9 9 Display grade is your output, so place it in the output column Set Mark Grade Output 1 34 Not Pass Not Pass So, if you have multiple sets of data: Set Mark Grade Output 1 34 Not Pass Not Pass 2 50 Pass Well done Pass 3 65 Pass Well Done Pass

So what about more complex algorithms?

Firstly, go through and list all the variables.

Number of Trains

Train

Train ID

Location X

Location Y

X

Y

Now, a table…

 Set Number Train TrainID Location Location X Y Output of X Y Trains
 The question gave you the set of values for number of trains as 0, 1 and 2 so…for 0 Set Number Train TrainID Location Location X Y Output of X Y Trains 1 0 1 Train001 Location Location “Train X Y 001 at X, Y” 2 Train002 Location Location “Train X Y 002 at X, Y” 3 Train003 Location Location “Train X Y 003 at
X, Y”
Never ending loop due to Number of Trains never equalling Train Number
 Train doesn’t equal number of trains (0 doesn’t equal 1, so the loop is entered) ReadTrainID(TrainID)…there’s no sub procedure listed for ReadTrainID(TrainID). You can assume that it’s just inputting the trainID. As we’re not given this value to test, we can either make it up, or just put in trainID. ReadLocation (TrainID,LocationX,LocationY) is giving us the train and, it’s X and Y co-ordinates (location) As you don’t know what the next two subprocedures do, you can ignore them and pass over them. A good desk check should include them, however, you’re not given enough info in this question to do it. Ok, you’re going back to line 7 in the algorithm, because you’ve finished that sub procedure. DisplayTrainID(TrainID, LocationX, LocationY) takes you to line 17. So, the output is “Train ID at X, Y” You then go back to line 8, train = train + 1, so train now equals 2 Go through all that again because Train<>Number of trains yet. As you go through this, you notice that you keep going up in train Numbers, but not Number of Trains, so you see that the loop will never end. Continuing the rest of the desk check:
 Number Train TrainID X Y Output of Trains 0 1 Train LocationX LocationY Train 001 is at Location X, Location Y 001 2 Train LocationX LocationY Train 002 is at Location X, Location Y 002 3 Train LocationX LocationY Train 003 is at Location X, Location Y 003 Endless loop due to value of Train never = Niumber of Trains 1 1 Terminates without looping due to value of train = number of trains initially 2 1 Train LocationX LocationY Train 001 is at Location X, Location Y 001 2 Terminates as Train=Number of trains