desk checking note

Upload: eida-shida

Post on 02-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Desk Checking note

    1/13

    Desk Checking

  • 8/11/2019 Desk Checking note

    2/13

    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 torecord results. The desk checker carefullyfollows the algorithm being careful to rigidly adhere tothe 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 algorithmworks 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 algorithmperforms as intended.

    A desk check is normally done as a table with columns for:

    1. Pseudo code line numbercolumn (Pseudo code doesn't normally have lines numbers, but theseare necessary in a desk check to specify the line(s) being executed)2. One column per variableused. 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 ofthe variables are put in the appropriate column. Show working for calculations.

    3. A conditioncolumn. The result of the condition will be true (T) or false (F). As the algorithm isexecuted, conditions are evaluated and the details are recorded in the column. Show working whenevaluating the conditions. This is used whenever a condition is evaluated - IF WHILE or FORstatements all have explicit or implicit conditions.

    4. An Input/Outputcolumn 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 withthe variable name, an =, and the value displayed (or just the value displayed) e.g. discountPrice=180 .

  • 8/11/2019 Desk Checking note

    3/13

    Desk Checks vs Test Plans

    A Desk Checkconcentrates on thevalue of variables and the logic i.e.what is the value of variablex afterstatement n; what is the next

    statement to be executed? A Test Planfocuses on the values of

    inputs and outputs required to test a

    program without concern for theinternal workings i.e. are the results(outputs) correct for the inputs?.

  • 8/11/2019 Desk Checking note

    4/13

    Sequence Desk CheckExample 1 Problem Description: Calculate the discounted price of an

    item purchased.(Note: a problem description is notnormally specified in a desk check, it is only included toassist in understanding the problem.)

    The following example shows desk checking involvingsequence, 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 calcDiscountPrice()2 Input price, discountPercent3 discount = price * discountPercent / 1004 discountPrice = price - discount5 Display discountPrice 6 STOP

  • 8/11/2019 Desk Checking note

    5/13

    Sequence Desk CheckTest Data

    Inputs: price = $200, discountPercent = 10%.Correct results: discount = $20, discountPrice = $180.

    Line

    Numberdiscount

    Discount

    PercentDiscount

    Priceprice Input/Output

    1

    2 10 200price ? 200;

    discountPercent ? 10

    3200 * 10 / 100 =

    20

    4 200 - 20 =180

    5 discountPrice = 180

    6

  • 8/11/2019 Desk Checking note

    6/13

    Selection Desk CheckExample 2 Problem Description: Calculate the discounted price of an item

    purchased. Customers receive a discount of 15% on an item if thepurchase price of the item is over $100.

    The following example shows desk checking involving selectionusing anIF.

    For an IF without an ELSE, if the condition evaluates to True thenexecution continues to the next line and the lines between the IFand ENDIF are executed (inclusive), otherwise (the condition isFalse) execution jumps from the IF to the ENDIF.

    Algorithm (with line numbers added for the Desk Check)1 calcPrice()2 Input price

    3 IF price > 100 THEN4 discount = price * 15 / 1005 price = price - discount

    6 ENDIF7 Display price 8STOP

  • 8/11/2019 Desk Checking note

    7/13

    Selection Desk Check Inputs: price = $200

    Correct results: price = $170.

    Line Number discount price Conditions Input/Output

    1

    2 200 price ? 200

    3 200 > 100 ? is T

    4 200 * 15 / 100 = 30

    5 200 - 30 = 170

    6

    7 price = 170

    8

  • 8/11/2019 Desk Checking note

    8/13

    Selection Desk Check cont.

    Line Number discount price Conditions Input/Output1

    2 50 price ? 50

    3 50 > 100 ? is F

    6

    7 price = 50

    8

    Inputs: price = $50Correct results: price = $50.

  • 8/11/2019 Desk Checking note

    9/13

    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 FORloop. 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 impliedcondition is x

  • 8/11/2019 Desk Checking note

    10/13

    Input: NoneCorrect results: x = 1, xSquared = 1; x = 2, xSquared = 4; x

    = 3, xSquared = 9.Line Number x xSquared Conditions Input/ Output

    1

    2 X, X Squared

    3 1 1

  • 8/11/2019 Desk Checking note

    11/13

    Example from Case Study1. Dim CashPaid, Change, GrandTotal As Currency

    2. GrandTotal = txtnettotal.Text

    3. CashPaid = txtcashtendered.Text

    4. If GrandTotal > CashPaid Then

    5. txtcashtendered.Text = ""

    6. Else

    7. Change = CashPaid - GrandTotal

    8. End If

  • 8/11/2019 Desk Checking note

    12/13

    Line Number GrandTotalCashPai

    dChange Conditions Input/Output

    2 120

    3200

    4120 > 200 ?

    is F

    7Change =

    200 - 120Change = 80

    8

    GrandTotal = 120CashPaid = 200

    Change should = 80

  • 8/11/2019 Desk Checking note

    13/13

    Try this oneDim Count As Integer

    Adodc1.Recordset.MoveFirst

    Do While Not Adodc1.Recordset.EOF

    Count = Count + 1

    Adodc1.Recordset.MoveNextLoop

    txtNo_Records.Text = Count

    Adodc1.Recordset.MoveFirst

    End Sub

    *5 records in database