levo

Validation, Verification and Testing

Implementing validation in an algorithm

  • 3 things to know
  • Component 1

Overview

Benefit of writing a validation check as a separate function, defensive programming and how a drop-down list reduces the need for validation code.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Write pseudo-code for a loop that keeps asking for an age until it lies between 0 and 120.

Key term

Why is a post-conditioned loop a natural structure for validating input?

Key term

Explain the benefit of writing a validation check as a separate function.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Write pseudo-code for a loop that keeps asking for an age until it lies between 0 and 120.

    Model answer

    The loop is REPEAT INPUT age UNTIL age ≥ 0 AND age ≤ 120. The program cannot continue until an acceptable value has been entered.

  2. 2

    Why is a post-conditioned loop a natural structure for validating input?

    Model answer

    A post-conditioned loop always asks for the value once before testing it. The test then decides whether the question has to be repeated.

  3. 3

    Explain the benefit of writing a validation check as a separate function.

    Model answer

    A function that returns TRUE or FALSE can be called from anywhere in the program. The same rule is then applied identically wherever that field is entered.

  4. 4

    Write pseudo-code that rejects an empty name entry.

    Model answer

    The test is IF name = '' THEN OUTPUT 'Name required' ELSE store the record. An empty string is the value a presence check looks for.

  5. 5

    How can a program stop a validation loop running forever?

    Model answer

    A counter can limit the number of retries allowed before the program gives up. The user is then returned to the menu instead of being trapped.

  6. 6

    What is defensive programming?

    Model answer

    Defensive programming means writing code that expects invalid or hostile input at every entry point. Checks are placed on data before it is used rather than afterwards.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Data Structures: Arrays, Records and Hash Tables
Stacks, Queues, Linked Lists and Trees
Boolean Logic and Simplification
Algorithms, Pseudo-Code and Programming Constructs

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe two are not the same.
BOpen source refers to the availability of the code.
CMuch open source software is free of charge.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Validation, Verification and Testing, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.