OCR J277 GCSE Computer Science · 2.3 Producing Robust Programs

Stretch tasks Producing Robust Programs

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick-box tables in the exam.

  • 11 cards to sort into 3 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

11 cards, about 4 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Producing Robust Programs

Producing Robust Programs: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. Which validation check makes sure an age is between 0 and 120?

    • Length check
    • Format check
    • Range check
    • Presence check
  2. Which validation check makes sure a surname is not left blank?

    • Range check
    • Type check
    • Look up check
    • Presence check
  3. Validation checks that data has been entered correctly.

    • True
    • False
  4. A program crashes when it divides by zero. Which type of error is this?

    • Syntax error
    • Logic error
    • Validation error
    • Runtime error
  5. A missing colon stops a Python program from running at all. Which type of error is this?

    • Boundary error
    • Syntax error
    • Logic error
    • Runtime error
  6. A program uses + where it should use *, so the total is wrong. Which type of error is this?

    • Logic error
    • Syntax error
    • Runtime error
    • Format error
  7. Ages 11 to 18 are allowed. Which TWO values are boundary test data?

    Tick 2.

    • 14
    • 25
    • "fourteen"
    • 11
    • 18
  8. What name is given to testing carried out during development, as each part is written?

  9. What does authentication do?

    • Checks data is sensible
    • Finds syntax errors
    • Compresses passwords
    • Confirms a user is who they claim to be
  10. Which TWO improve maintainability?

    Tick 2.

    • Comments explaining why
    • Single-letter variable names
    • Removing all indentation
    • Copying the same code into many places
    • Meaningful variable names
  11. Why should passwords be stored hashed?

    • It stops users forgetting them
    • A stolen database does not reveal them
    • Hashing makes them shorter to type
    • Hashed passwords never expire
  12. A test plan should state the expected result of every test.

    • True
    • False

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between validation and verification. [2 marks]

  2. A program accepts ages from eleven to eighteen. Give one normal, one boundary and one erroneous test value. [3 marks]

  3. Give two ways to make a program more maintainable. [2 marks]

  4. Explain why boundary data is the most valuable test data. [2 marks]

Quiz Challenge, round 3: Big Think

  1. A sign-up form asks for a username and an age from 13 to 100. Describe how validation could be used to make the program robust. [6 marks]

  2. Compare iterative testing with final testing, and explain why a program needs both. [4 marks]

This or That: tick the right answer

  1. Which of these is a format check?

    • A surname must not be blank
    • An email must contain an at sign
  2. Asking for a new password twice is...

    • Validation
    • Verification
  3. Which error is harder to spot?

    • A syntax error
    • A logic error
  4. A check is written as > 11 instead of >= 11. Which test value catches it?

    • 14
    • 11
  5. Testing an age box with "fourteen" uses which type of data?

    • Boundary
    • Erroneous
  6. What does two factor authentication add?

    • A second check, such as a code sent to a phone
    • A second password box on the same page
  7. Opening a file that does not exist crashes a program. What kind of error is that?

    • A syntax error
    • A runtime error
  8. Final testing checks the program against...

    • The programmer's memory
    • The original requirements

Memory Match: match each term to its meaning

TermMeaning
A Range check1 Runs, but gives the wrong result
B Presence check2 Values at the very edge of the range
C Length check3 Breaks the language's rules, so it won't run
D Syntax error4 Something has been entered
E Logic error5 Between a lower and an upper limit
F Boundary data6 The right number of characters

Sort It: tick one box in each row

Syntax error, logic error or runtime error?

StatementSyntax errorLogic errorRuntime error
Dividing by zero
Reading item 10 of a list with 5 items
Using > where >= was needed
Printing the average before it is calculated
Using + where * was intended
A bracket that is never closed
A missing colon after an if statement
A loop that adds 1 to the wrong variable
Converting the text abc to a whole number
Opening a file that does not exist
A misspelled keyword, such as whlie
Answers

Round 1: Quiz Blitz

  1. Range check A range check tests that a value falls between an upper and a lower limit.
  2. Presence check A presence check makes sure something has been entered.
  3. False Validation checks data is sensible. Verification checks it was entered correctly.
  4. Runtime error The code is valid, but it crashes while running.
  5. Syntax error It breaks the rules of the language, so the program cannot run.
  6. Logic error It runs perfectly and quietly gives the wrong answer: a logic error.
  7. 11; 18 Boundary data sits at the very edge of the range. 14 is normal, 25 is invalid, and text is erroneous.
  8. iterative testing Iterative testing finds problems early, when they are cheap to fix.
  9. Confirms a user is who they claim to be Passwords, two factor authentication and biometrics are all ways to authenticate.
  10. Meaningful variable names; Comments explaining why Indentation, subroutines and constants help too.
  11. A stolen database does not reveal them A hash cannot simply be read back as the password.
  12. True Without an expected result, there is nothing to compare the actual result with.

Round 2: Quick Fire

    • Validation checks that data is sensible and in the right format
    • Verification checks that data was entered correctly, for example by typing it twice
    Model answer

    Validation checks that data is sensible and in the right format before it is used. Verification checks that it was entered correctly, for example by asking for a password twice.

    • Normal: a typical age inside the range
    • Boundary: a value at the edge of the range
    • Erroneous: data of the wrong type
    Model answer

    Normal: 14. Boundary: 11. Erroneous: "fourteen", which is text rather than a number.

    • Meaningful identifiers
    • Comments
    • Indentation
    • Subroutines
    • Constants
    • White space
    Model answer

    Use meaningful variable names, such as totalPrice instead of tp, and add comments that explain why the code does something.

    • It tests the very edge of the allowed range
    • That is where off by one mistakes, such as > instead of >=, are caught
    Model answer

    Boundary data tests the very edge of the allowed range, which is exactly where off by one mistakes hide: a check written as > 11 instead of >= 11 is only caught by testing 11.

Round 3: Big Think

    • A presence check on the username
    • A length check on the username
    • A type check that the age is a whole number
    • A range check on the age
    • A loop asks again until the input is valid, instead of crashing
    • An error message tells the user what to enter
    • This is defensive design: it anticipates misuse
    Model answer

    A presence check makes sure the username is not left blank, and a length check could make sure it is at least 3 characters long. A type check makes sure the age is a whole number, so typing letters cannot crash the program, and a range check makes sure it is between 13 and 100. If any check fails, the program shows an error message that tells the user what to enter, and a while loop asks again until the input is valid. This is defensive design: it anticipates misuse instead of crashing.

    • Iterative testing happens during development, as each part is written
    • So problems are found early, when they are cheap to fix
    • Final testing happens when the program is complete
    • It checks the program against the original requirements
    • Parts that work alone can still fail when combined
    Model answer

    Iterative testing happens during development: each part is tested as it is written and corrected before moving on, so problems are found early, when they are cheap to fix. Final testing happens when the program is complete: the whole program is tested against the original requirements. Each part can work on its own while the parts fail when combined, so testing the whole program together is still needed.

This or That

  1. An email must contain an at sign A format check tests for a pattern. Not blank is a presence check.
  2. Verification Typing it twice checks it was entered correctly: verification.
  3. A logic error The translator finds syntax errors for you. A logic error runs quietly with the wrong answer.
  4. 11 Only a test on the boundary itself shows the difference.
  5. Erroneous Erroneous data is the wrong type entirely, and should be rejected.
  6. A second check, such as a code sent to a phone A stolen password alone is no longer enough to get in.
  7. A runtime error The code is valid, so it starts, then crashes while running.
  8. The original requirements It confirms the program does everything it was supposed to.

Memory Match

  • A 5 Range check: Between a lower and an upper limit
  • B 4 Presence check: Something has been entered
  • C 6 Length check: The right number of characters
  • D 3 Syntax error: Breaks the language's rules, so it won't run
  • E 1 Logic error: Runs, but gives the wrong result
  • F 2 Boundary data: Values at the very edge of the range

Sort It

  1. Runtime error Dividing by zero The program crashes while running.
  2. Runtime error Reading item 10 of a list with 5 items The index is out of range, so the program crashes.
  3. Logic error Using > where >= was needed The program runs, but gets the boundary wrong.
  4. Logic error Printing the average before it is calculated The steps are in the wrong order, so the output is wrong.
  5. Logic error Using + where * was intended It runs, but the answer is wrong.
  6. Syntax error A bracket that is never closed Unclosed brackets break the language's rules.
  7. Syntax error A missing colon after an if statement It breaks the rules of Python, so it will not run.
  8. Logic error A loop that adds 1 to the wrong variable No crash, just a wrong result.
  9. Runtime error Converting the text abc to a whole number int() fails on letters while the program runs.
  10. Runtime error Opening a file that does not exist The code is fine, but it fails at run time.
  11. Syntax error A misspelled keyword, such as whlie The translator cannot understand the misspelled keyword.