Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Desk Checking πŸ“

Learning Goals

By the end of this section you will:

  • understand the importance of deskchecking

  • know how to deskcheck branching code

  • know how to deskcheck iterative code

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 reduces the likelihood of creating programs with logic errors. 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:

Branching ExampleΒΆ

Consider the following pseudocode:

1 BEGIN calcPrice()
2    INPUT price
3    IF price > 100 THEN
4        discount = price * 15 / 100
5        price = price - discount
6    ENDIF
7    DISPLAY price
8 END

Since it has branching logic, you will need to run a test for each of the branches (in this case two).

Inputs: price = $200
Correct results: price = $170

Line #discountpriceConditionsInput/Output
1
2200price ? 200
3200price > 100 ? T
4200 * 15 / 100 = 30200
530200 - 30 = 170
630170
730170price = 170
830170

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

Line #discountpriceConditionsInput/Output
1
250price ? 50
350price > 100 ? F
650
750price = 50
850

Iteration ExampleΒΆ

Consider the following pseudocode:

1 BEGIN calcSquares()
2    DISPLAY "X", "X Squared"
3    FOR x = 1 TO 3
4        xSquared = x * x
5        DISPLAY x, xSquared
6    NEXT x
7    ENDFOR
8    DISPLAY "-----------"
9 END
Line #xxSquaredConditionsInput/Output
1
2X, X Squared
311 <= 3 ? T
411 * 1 = 1
51x = 1, xSquared = 1
61 + 1 = 2
322 <= 3 ? T
422 * 2 = 4
52x = 2, xSquared = 4
62 + 1 = 3
333 <= 3 ? T
433 * 3 = 9
53x = 3, xSquared = 9
63 + 1 = 4
43 <= 3 ? F
8DISPLAY "-----------"
9

Choosing Test Values for Desk Checks (Pseudocode)ΒΆ

Desk checking pseudocode is about proving that the algorithmic logic works in all meaningful scenarios. To do this, you need to choose test values that will allow you to check the logic of the algorithm. The following are some guidelines for choosing test values:

Focus on testing:

1. Test Each Branch of a SelectionΒΆ

For every IF / ELSE / ELSE IF:

Example IF mark >= 50 THEN

Test with:

Purpose

2. Test Boundary Conditions in ComparisonsΒΆ

If a condition uses:

Test values:

Purpose

3. Test Loop Entry and Exit ConditionsΒΆ

For WHILE or FOR loops:

Test values that cause:

Example WHILE counter < 5

Test with counter starting at:

Purpose

4. Test Variable InitialisationΒΆ

If variables are initialised before use:

Test values that confirm:

Purpose

5. Test Accumulation or TotalsΒΆ

For algorithms that:

Test:

Purpose

6. Test Special Logical CasesΒΆ

For algorithms involving:

Test combinations that make the overall condition:

Purpose