Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 Desk Checking/Dry Running.

Similar presentations


Presentation on theme: "Chapter 5 Desk Checking/Dry Running."— Presentation transcript:

1 Chapter 5 Desk Checking/Dry Running

2 Desk Checking/Dry running
Basically it is the manual simulation/process of walking through a program’s logic on paper before actually writing the program (coding). Used to test for the correctness of the solution algorithm Vital to check for errors during development of the solution algorithm (before coding) so that these errors are not implemented Done during planning/design stage In a large system, if there is logical error, it is very difficult to trace back the program as it involves 1000s lines of codes. Eliminate most errors but cannot prove algorithm is 100% correct Analyze codes = time consuming = costly

3 Desk Checking/Dry running
It involves Use pen and paper Tabulate All variables (one column for each) Conditions – result is T for True or F for False Output walk through the logic of the algorithm with specific test data. and keep track of the values of all variables through out the process.

4 Desk Checking/Dry running
May involves 6 steps for desk checking the solution: Choose 2 or 3 sets of simple input data (may include one invalid data to test the condition, if any) . Define/calculate the expected result for each test case. Make a table of relevant variable names within the algorithm e.g. Read number, total, while counter < 10 etc.

5 Desk Checking/Dry running
Walk the first test data through the algorithm, keeping a step-by-step record of the content of each variable as the data passes through the logic. Repeat the walk-through process using the next test data until the algorithm has reached its logical end. Check that the expected result matches the actual result in the walk-through. For some cases you may omit steps 1 & 2 (if you do desk check after you do analysis using stepwise)

6 Example 1– Problem spec Analyze the problem to accept customer name, purchase amount, amount paid and payment type (Cash or Card). Calculate and display the change.

7 Example 1– solution algorithm
Read customerName, purchaseAmt, amtPaid, paymentType Calculate change change = amtPaid - purchaseAmt Display change

8 Example 1– Desk Checking
Step 1 - Choose 2 or 3 valid simple input data Variables Data1 Data2 CustomerName purchaseAmt amtPaid paymentType Aziz 100.00 Card Ahmad 55.00 Cash

9 Example 1– Desk Checking
Step 2 - Define/calculate the expected result for each test case. Variables Data1 Data2 change 0.00 45.00

10 Example 1- Desk Checking
Step 3 - Make a table of relevant variable names statement Customer Name purchaseAmt amtPaid Payment Type change Output Data 1 Read Display Data 2

11 Example 1- Desk Checking
Step 4 & 5 - walk-through process + record the content of each variable statement Customer Name purchaseAmt amtPaid Payment Type change Output Data 1 Read Display Aziz 100.00 Card 0.00 Data 2 Ahmad 55.00 Cash 45.00

12 Example2 – Problem Spec A program is required to read from the screen the length and width of a rectangular house block and the length and width of the rectangular house that has been built on the block. The algorithm should then compute and display the mowing time required to cut the grass around the house, at a rate of 2 square metres per minute. Chp 3 – Simple Program Design

13 Example3 – Problem Spec Find the average of 4 integers which lie between 0 and 100 (exclusive) using iterative control structure

14 Example3 – solution algorithm
1. Set num_count = 0, total = 0 2. While num_count < Read number 2.2 If number > 0 AND number < total = total + number Add 1 to num_count 3. Calculate average avg_num = total / num_count 4. Display avg_num

15 Example 1– Desk Checking
Step 1 - Choose input data Data 1 Data 2 number 20,30,40,60 1, 40, -5, 29, 100, 99

16 Example 1– Desk Checking
Step 2 - Define/calculate the expected result for each test case. Variables Data 1 Data 2 avg_num 37.50 42.25

17 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output Data1 1. Set 2. while T 2.1. Read 20 2.2. IF total 2.2.2 Add 1 30

18 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output total 50 2.2.2 Add 2 2. while T 2.1. Read 40 2.2. IF 90 3

19 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output 2.1. Read 60 2.2. IF T total 150 2.2.2 Add 4 2. while F 3. avg_num 37.50 4. Display

20 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output Data2 1. Set 2. while T 2.1. Read 1 2.2. IF total 2.2.2 Add 40

21 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output total 41 2.2.2 Add 2 2. while T 2.1. Read -5 2.2. IF F 29

22 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output total 70 2.2.2 Add 3 2. while T 2.1. Read 100 2.2. IF F 99 189

23 Example 3- Desk Checking
Step 3 – List out variables, conditions, output statement num_count total While OK? number IF OK? avg_num output 2.2.2 Add 4 2. while F 3. avg_num 42.25 4. Display

24 Class Exercise 1 Calculate the discounted price of an item purchased. Design the algorithm and do the desk check

25 Class Exercise 2 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. Design the algorithm and do the desk check


Download ppt "Chapter 5 Desk Checking/Dry Running."

Similar presentations


Ads by Google