Desk Checking Desk Checking Desk checking is a

  • Slides: 13
Download presentation
Desk Checking

Desk Checking

Desk Checking • • Desk checking is a manual (non computerised) technique for checking

Desk Checking • • Desk checking is a manual (non computerised) technique for checking the logic of an algorithm. The person performing the desk check effectively acts as the computer, using pen and paper to record results. The desk checker carefully follows the algorithm being careful to rigidly adhere to the logic specified. The desk check can expose problems with the algorithm. Desk checks are useful to check an algorithm (before coding) thereby confirming that the algorithm works as expected and saves time possibly writing a program that doesn't do what was intended. Another benefit of a desk check is that it confirms to the programmer/designer that the algorithm performs as intended. A desk check is normally done as a table with columns for: 1. 2. 3. 4. Pseudo code line number column (Pseudo code doesn't normally have lines numbers, but these are necessary in a desk check to specify the line(s) being executed) One column per variable used. The columns should be in alphabetical order on variable name with the variable name at the top of the column. As the algorithm is executed, the new values of the variables are put in the appropriate column. Show working for calculations. A condition column. The result of the condition will be true (T) or false (F). As the algorithm is executed, conditions are evaluated and the details are recorded in the column. Show working when evaluating the conditions. This is used whenever a condition is evaluated - IF WHILE or FOR statements all have explicit or implicit conditions. An Input/Output column is used to show what is input by the user and displayed by the program. Show inputs with: the variable name, a "? " and the value input e. g. price ? 200. Show outputs with the variable name, an =, and the value displayed (or just the value displayed) e. g. discount. Price= 180.

Desk Checks vs Test Plans • A Desk Check concentrates on the value of

Desk Checks vs Test Plans • A Desk Check concentrates on the value of variables and the logic i. e. what is the value of variable x after statement n; what is the next statement to be executed? • A Test Plan focuses on the values of inputs and outputs required to test a program without concern for the internal workings i. e. are the results (outputs) correct for the inputs? .

Sequence Desk Check Example 1 • Problem Description: Calculate the discounted price of an

Sequence Desk Check Example 1 • Problem Description: Calculate the discounted price of an item purchased. (Note: a problem description is not normally specified in a desk check, it is only included to assist in understanding the problem. ) • The following example shows desk checking involving sequence, executing instructions one after the other. • Sequence involves executing all instructions once, from top to bottom, one after the other. • Algorithm (with line numbers added for the Desk Check) 1 2 3 4 5 calc. Discount. Price() Input price, discount. Percent discount = price * discount. Percent / 100 discount. Price = price - discount Display discount. Price 6 STOP

Sequence Desk Check Test Data Inputs: price = $200, discount. Percent = 10%. Correct

Sequence Desk Check Test Data Inputs: price = $200, discount. Percent = 10%. Correct results: discount = $20, discount. Price = $180. Line discount Number Discount Percent Discount Price price Input/Output 200 price ? 200; discount. Percent ? 10 1 2 3 4 5 6 10 200 * 10 / 100 = 20 200 - 20 = 180 discount. Price = 180

Selection Desk Check Example 2 • Problem Description: Calculate the discounted price of an

Selection Desk Check Example 2 • Problem Description: Calculate the discounted price of an item purchased. Customers receive a discount of 15% on an item if the purchase price of the item is over $100. • The following example shows desk checking involving selection using an IF. • For an IF without an ELSE, if the condition evaluates to True then execution continues to the next line and the lines between the IF and ENDIF are executed (inclusive), otherwise (the condition is False) execution jumps from the IF to the ENDIF. • Algorithm (with line numbers added for the Desk Check) 1 calc. Price() 2 Input price 3 IF price > 100 THEN 4 discount = price * 15 / 100 5 price = price - discount 6 ENDIF 7 Display price 8 STOP

Selection Desk Check • Inputs: price = $200 Correct results: price = $170. Line

Selection Desk Check • Inputs: price = $200 Correct results: price = $170. Line Number discount price Conditions Input/Output 1 2 200 3 4 5 price ? 200 > 100 ? is T 200 * 15 / 100 = 30 200 - 30 = 170 6 7 8 price = 170

Selection Desk Check cont. Inputs: price = $50 Correct results: price = $50. Line

Selection Desk Check cont. Inputs: price = $50 Correct results: price = $50. Line Num ber disco pri Conditio u c ns nt e Input/O utput 1 2 3 price ? 50 50 50 > 100 ? is F 6 7 price = 50

Iteration Desk Check • Problem Description: Display a table of values of x and

Iteration Desk Check • Problem Description: Display a table of values of x and x squared. X is to start at 1 and increase by 1 up to 3. • The following example shows desk checking involving iteration (repetition) using a FOR loop. • The counter variable is initialized once at the top of the loop, the first time through the loop. The implied condition is evaluated at the top of the loop, with execution going to the next line if the condition is True and going to the line after the ENDFOR if the condition is False. In this case the implied condition is x <= 3 ? . On the ENDFOR line the counter variable is incremented by 1, then program execution loops from the ENDFOR line, back to the FOR line. Algorithm (with line numbers added for the Desk Check) 1 calc. Squares() 2 Display "X", "X Squared" 3 FOR x = 1 TO 3 DO 4 x. Squared = x * x 5 Display x, x. Squared 6 ENDFOR 7 Display "------" 8 STOP

Input: None Correct results: x = 1, x. Squared = 1; x = 2,

Input: None Correct results: x = 1, x. Squared = 1; x = 2, x. Squared = 4; x = 3, x. Squared = 9. Line Number x x. Squared Conditions Input/ Output 1 2 3 X, X Squared 1 4 1 <= 3 ? is T 1*1=1 5 6 x = 1, x. Squared = 1 1+1=2 3 2 <= 3 ? is T 4 2*2=4 5 6 x = 2, x. Squared = 4 2+1=3 3 3 <= 3 ? is T 4 3*3=9 5 6 3 7 8 x = 3, x. Squared = 9 3+1=4 4 <= 3? is F ------

Example from Case Study 1. Dim Cash. Paid, Change, Grand. Total As Currency 2.

Example from Case Study 1. Dim Cash. Paid, Change, Grand. Total As Currency 2. Grand. Total = txtnettotal. Text 3. Cash. Paid = txtcashtendered. Text 4. If Grand. Total > Cash. Paid Then 5. txtcashtendered. Text = "" 6. Else 7. Change = Cash. Paid - Grand. Total 8. End If

Grand. Total = 120 Cash. Paid = 200 Change should = 80 Line Number

Grand. Total = 120 Cash. Paid = 200 Change should = 80 Line Number Grand. Total Cash. Paid Change 2 120 3 8 Input/Output 200 120 > 200 ? is F 4 7 Conditions Change = 200 - 120 Change = 80

Try this one… Dim Count As Integer Adodc 1. Recordset. Move. First Do While

Try this one… Dim Count As Integer Adodc 1. Recordset. Move. First Do While Not Adodc 1. Recordset. EOF Count = Count + 1 Adodc 1. Recordset. Move. Next Loop txt. No_Records. Text = Count Adodc 1. Recordset. Move. First End Sub *5 records in database