AQA GCSE Computer Science June 2023 Paper 1, Question 11: test data and a logic error

AQA 8525 June 2023 Paper 1, Question 11: complete a test table for an algorithm that contains a logic error, then correct the error. Each test worked through, the trap explained, and the algorithm as a program you can run.

Past paper questionAQA 8525/1BJune 2023 Paper 15 marksTesting

Question 11 of the AQA GCSE Computer Science Paper 1 sat on 19 May 2023 (8525/1B, the Python paper) gives you an algorithm that you are told is wrong. Part 1 asks what it does with three sets of test data (4 marks). Part 2 asks you to correct the faulty line (1 mark).

The whole question turns on one idea: trace what the code does, not what it is meant to do.

We do not copy the exam paper here. Open it beside this page: AQA June 2023 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.

The question in short

The algorithm is meant to:

  • get a start year and an end year from the user;
  • check that the start year is before the end year;
  • check that the start year is before 2000;
  • work out the difference between the years once a valid start year has been entered.

Inside a loop it sets difference to -1 and reads the two years. Then:

  • if the start year is greater than or equal to the end year, it outputs a message saying the start must be before the end;
  • otherwise, if the start year is less than 2000 it outputs a message saying the start must be before 2000;
  • otherwise it sets validChoice to True.

The loop repeats until validChoice is True. Only then is difference worked out.

Read the middle bullet again. The message is shown when the start year is before 2000. The test is the wrong way round. That is the logic error on line 11, and the question tells you so.

The test table asks for the values of validChoice and difference for each of these:

Test type startYear endYear
Normal 1995 2010
Erroneous 2015 2000
Boundary 2000 2023

Work it through

Normal: 1995 and 2010. Is 1995 greater than or equal to 2010? No, so go to the inner test. Is 1995 less than 2000? Yes. So the faulty code complains, and validChoice stays False. The loop would go round again, so difference is never worked out. It is still -1.

This is perfectly good data, and the algorithm rejects it. That is what the test is there to show.

Erroneous: 2015 and 2000. Is 2015 greater than or equal to 2000? Yes. The first message is shown. validChoice is False and difference is -1. This time the algorithm is right to reject it.

Boundary: 2000 and 2023. Is 2000 greater than or equal to 2023? No. Is 2000 less than 2000? No. So validChoice becomes True, the loop ends, and difference is 2023 - 2000 = 23.

And that is wrong too. 2000 is not before 2000, so it should have been rejected.

The finished table

Test type validChoice difference
Normal False -1
Erroneous False -1
Boundary True 23

One mark for the Normal validChoice, one for the Normal difference, one for both Erroneous values, and one for both Boundary values.

Where the marks are lost

  • Writing what should happen. The tempting answer is True and 15 in the Normal row. The question says the algorithm has an error. Believe it, and trace the code as written.
  • Leaving difference blank. It was set to -1 at the top of the loop, so that is its value when the data is rejected.
  • Working out a difference for rejected data. Line 18 is after the loop. It is never reached while validChoice is False.

Part 2: correct line 11

The message on the next line is for start years that are not before 2000. So the condition must be true for those years:

IF startYear ≥ 2000 THEN

Saying "change the less than sign to greater than or equal to" gets the mark as well. > on its own would still let 2000 through, and the boundary test is what proves it.

Run it

Here is the algorithm as a Python function, run on the three tests. FIXED = False is the version on the paper. Change it to True to see the corrected version, and check that all three tests now give the result they should.

FIXED = False prints the table above: False -1, False -1, True 23. Change FIXED to True and the normal test passes and the boundary test is rejected.
The program
from bugbot import *
connect()

# False is the algorithm on the paper. True is the corrected one
FIXED = False

TESTS = [["Normal", 1995, 2010], ["Erroneous", 2015, 2000], ["Boundary", 2000, 2023]]

def check(start_year, end_year):
    valid_choice = False
    difference = -1
    if start_year >= end_year:
        print("  Start year must be before end year")
    else:
        if FIXED:
            too_late = start_year >= 2000
        else:
            too_late = start_year < 2000       # line 11, the logic error
        if too_late:
            print("  Start year must be before 2000")
        else:
            valid_choice = True
    if valid_choice:
        difference = end_year - start_year
    return valid_choice, difference

for name, start_year, end_year in TESTS:
    print(name, start_year, end_year)
    valid_choice, difference = check(start_year, end_year)
    print("  validChoice", valid_choice, " difference", difference)
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 AQA GCSE Computer Science 2023 Paper 1 Question 11.1?

Normal: validChoice is False and difference is -1. Erroneous: False and -1. Boundary: True and 23. The normal data is rejected because of the logic error on line 11.

What is the answer to Question 11.2?

Change line 11 to IF startYear ≥ 2000 THEN, so that the message is shown for start years that are not before 2000.

What is the difference between normal, erroneous and boundary test data?

Normal data is typical data the program should accept. Erroneous data is data it should reject. Boundary data sits on the edge of what is allowed, such as 2000 when the rule is "before 2000", and it is where a wrong comparison operator shows up.

What is a logic error?

A logic error is a mistake that lets the program run but makes it do the wrong thing, such as a comparison that is the wrong way round. A syntax error stops the program from running at all.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F6.3 Testing and test data Robust programs
  2. F6.4 Debugging logic errors Robust programs
Open the lessons

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