Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
OCR GCSE Computer Science (Paper 2) Smart practice A mixed round aimed at your weak spots
Unit 1
Algorithms
Unit 2
Programming fundamentals
Unit 3
Producing robust programs
Unit 4
Boolean logic
Unit 5
Programming languages and IDEs
Unit 6
Practical programming (Section B)
Avg
score:
–
Topics
done:
0/31

Testing: purpose, types of testing, syntax and logic errors

Practise 29 exam-style questions on Testing: purpose, types of testing, syntax and logic errors for OCR GCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with the Study Helper on hand if you get stuck.

  • 29 questions
  • 1–6 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

2 marks

Give two reasons why a program should be tested before it is released.

Model answer

1. To find any errors so that they can be fixed before the program is used.
2. To check that the program handles invalid or unexpected inputs without crashing.

Explanation

Testing has two jobs: finding errors so they can be fixed, and checking that the program meets its requirements, including dealing sensibly with bad input. A program released without testing may crash or give wrong results for its users. Testing cannot prove a program has no errors, but a good test plan finds most of them.

Mark scheme
  1. 1 mark

    To find errors / bugs so they can be fixed (before users find them)

    max 2

  2. 1 mark

    To check that the program meets its requirements / does what it is supposed to do

  3. 1 mark

    To check that it gives the correct outputs (for a range of inputs)

    Do not award together with the requirements point if the student only repeats the same idea in different words.

  4. 1 mark

    To check that it handles invalid / unexpected inputs without crashing // to make sure it is robust

Question 2

2 marks

Explain why a translator can detect syntax errors but cannot detect logic errors.

Model answer

The translator checks that every statement follows the rules of the language, so it finds code that breaks them. A logic error is still valid code, and the translator has no way of knowing what the programmer intended the program to do, so it translates it without any error.

Explanation

To a translator, total = total - price is just as correct as total = total + price: both are valid statements. Only the programmer knows which one the problem needs. That is why logic errors have to be found by testing and tracing, not by the translator.

Mark scheme
  1. 1 mark

    Syntax errors break the rules of the language, which the translator checks as it translates the code

  2. 1 mark

    Code with a logic error follows the rules / is valid code, and the translator does not know what the program is meant to do

Question 3

3 marks

This program should output the total number of steps walked in a week.

01for day = 1 to 7
02    total = 0
03    steps = int(input("Enter steps for day " + str(day)))
04    total = total + steps
05next day
06print("Weekly total: " + str(total))

When it is tested by entering 1000 for every day, it outputs Weekly total: 1000 instead of Weekly total: 7000.

Explain the cause of the logic error and state how to correct it.

Model answer

Line 02, total = 0, is inside the for loop, so the total is set back to 0 at the start of every day. Only the last day's steps are added, so the output is 1000. Moving total = 0 to before line 01 means it is set to 0 once and all seven days are added.

Explanation

A running total must be initialised once, before the loop, and then added to inside the loop. Initialising it inside the loop wipes out the previous days each time. Tracing the program for two or three days shows the total going 1000, 1000, 1000 instead of 1000, 2000, 3000.

Mark scheme
  1. 1 mark

    total = 0 (line 02) is inside the loop

  2. 1 mark

    So total is reset to 0 on every pass / every day, so only the last day's steps are kept

  3. 1 mark

    Move total = 0 to before the loop (before line 01)

Question 4

4 marks

This program should output the mean of three test marks. It contains one syntax error and one logic error.

01// calculates the mean of 3 test marks
02total = 0
03for i = 1 to 3
04    mark = int(input("Enter mark"))
05    total = total + mark
06nxt i
07average = total / 2
08print("Average: " + str(average))

Identify the line number of each error and write the corrected line for each.

Model answer

Syntax error: line 06 - the keyword is misspelt.

next i

Logic error: line 07 - three marks are entered, so the total must be divided by 3.

average = total / 3

Explanation

nxt is not a keyword, so the loop is never closed and the program cannot be translated: a syntax error. Dividing by 2 is valid code, so the program would run, but for marks of 60, 70 and 80 it would output 105 instead of 70: a logic error. The syntax error has to be fixed before the logic error can even be seen.

Mark scheme
  1. 1 mark

    Syntax error on line 06

  2. 1 mark

    Corrected: next i

  3. 1 mark

    Logic error on line 07

  4. 1 mark

    Corrected: average = total / 3

    Do not accept total DIV 3.

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.