OCR GCSE Computer Science June 2024 Paper 2, Question 9(c): a range check and its test data

OCR J277/02 June 2024, Question 9(c): write an algorithm that outputs VALID or NOT VALID for a height between 40.0 and 180.0 inclusive, then give normal, boundary and erroneous test data. Model answers, the marks explained, and the check to run.

Past paper questionOCR J277/02June 2024 Paper 27 marksWrite a program

Question 9(c) of the OCR GCSE Computer Science Paper 2 sat on 21 May 2024 (J277/02) has two parts that go together. Write a range check (4 marks), then choose test data for it (3 marks). It is in Section B, so the algorithm must be in OCR Exam Reference Language or a high-level language.

We do not copy the exam paper here. Open it beside this page: OCR June 2024 J277/02 question paper (PDF). When you have finished, check the mark scheme too.

The question in short

A high jump height is entered in centimetres. It must be between 40.0 and 180.0 inclusive. The algorithm takes the height as input and outputs "VALID" or "NOT VALID".

Part (i): a model answer

In OCR Exam Reference Language:

height = input("Enter height jumped")
if height >= 40.0 and height <= 180.0 then
    print("VALID")
else
    print("NOT VALID")
endif

In Python:

height = float(input("Enter height jumped: "))
if height >= 40.0 and height <= 180.0:
    print("VALID")
else:
    print("NOT VALID")

You can test for the bad values instead: if height < 40.0 or height > 180.0 and swap the two outputs. Notice that the joining word changes. Good values need and. Bad values need or.

Where the four marks are

  • inputting a value and storing it;
  • checking the minimum (>= 40.0);
  • checking the maximum (<= 180.0);
  • outputting VALID and NOT VALID the right way round.

The mark scheme ignores whether you cast the input to a number.

Part (ii): the test data

Type of test Test data Expected output
Normal 100 VALID
Boundary 40.0 or 180.0 VALID
Erroneous 200, or 10, or "abc" NOT VALID

The expected outputs are printed on the paper, so the boundary value has to be one that is valid: exactly 40.0 or exactly 180.0. Any value clearly inside the range is normal. Anything outside it, or not a number at all, is erroneous.

Where the marks are lost

  • height >= 40 and <= 180. Both sides of and must be complete comparisons. The mark scheme refuses this by name.
  • => for >=. The symbol is greater than, then equals. The other way round is not an operator.
  • > and <. "Inclusive" means 40.0 and 180.0 are valid. Without the equals signs your own boundary test would fail.
  • A variable called input. That is the name of the function.
  • Describing the data. "A number between 40 and 180" is not test data. Write an actual value, such as 100.
  • 39.9 as the boundary. It is next to the boundary, but here the expected output is VALID, so the value must be inside.

Run it

The check as a function, run on your test table. Put your own three values in TESTS and see whether the outputs are what you expected. The robot jumps (drives) 1 cm for every 10 cm of the last valid height.

100 and 40.0 and 180.0 are VALID. 39.9, 180.1 and 200 are NOT VALID. Change the operators to > and < and watch the boundary tests fail.
The program
from bugbot import *
connect()

TESTS = [100, 40.0, 180.0, 39.9, 180.1, 200]

def check(height):
    if height >= 40.0 and height <= 180.0:
        return "VALID"
    else:
        return "NOT VALID"

best = 0
for height in TESTS:
    result = check(height)
    print(height, result)
    if result == "VALID":
        best = height
forward(60, distance=best / 10)
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to OCR J277 June 2024 Paper 2 Question 9(c)(i)?

Input the height. If height >= 40.0 and height <= 180.0 then print VALID, otherwise print NOT VALID.

What is boundary test data?

Data at the very edge of what is allowed, such as 40.0 and 180.0 for a range of 40.0 to 180.0 inclusive. It checks that the comparison operators are right.

What is erroneous test data?

Data that the program should reject: a value outside the allowed range, or data of the wrong type such as text where a number is expected.

More from this paper

Every OCR J277 question we have worked

Learn it step by step

  1. F6.1 Defensive design and validation Robust programs
  2. F6.3 Testing and test data Robust programs
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.