levo

Validation, Verification and Testing

Implementing validation in an algorithm

  • 3 things to know
  • Component 1
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

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