ALevelComputing_U2Session13

advertisement
Session Objectives#U2S13
COULD explain and use of a method or tool to identify and fix a programming error.
SHOULD explain 3 different testing strategies
MUST describe 3 different types of programming error
A Level Computing#BristolMet
Starter
How many types of error message can you think of? (30 secs)
A Level Computing#BristolMet
Key Words
A Level Computing#BristolMet
Types of Programming Errors
Syntax Errors – an error that occurs when a statement has been
written in the program that breaks the rules of that programming
language. Common causes are:
• missing/extra punctuation
• Not enough arguments for functions or procedures
• Missing part of multiline statement (such as IF without END
IF, or FOR without NEXT etc)
• Using unrecognised identifiers where all identifiers have been
declared
• Type mismatch – when the computer expects data of a certain
type but the data provided is of a different type
Translator diagnostics will point to the line of code where
there is a syntax error and suggest corrections
Logic Errors - The logic of program refers to the instructions
in the program and the order in which they are executed. NB A
program may still run even if a logic error exists but the
result will be incorrect
A Level Computing#BristolMet
Types of Programming Errors
Logic errors usually do not produce error messages and are only
discovered through testing against expected results.
Common causes:
• Instructions in the wrong order
• Incorrect conditions for IF statements or Loops
Run-time errors
When a program is free of logic and syntax errors it may still
ask the computer to perform an impossible operation that will
cause the program to crash or to stop, these are known as runtime errors. For example, it could be an arithmetic error such
as calculating the square root of a negative number.
Other causes of run-time errors include:
Overflow error – when the program attempts to use a variable to
store a value that is too large for it.
Library error – the program refers to an external library that
does not exist (has not been imported – think of Python and the
time library or random library)
A Level Computing#BristolMet
TASK
Below is an algorithm that reads a file of integers and outputs
the mean. There are errors, where are they and what type of
error are they?
01
02
03
04
05
06
07
08
09
10
11
12
BEGIN
Total = 0
Count = 0
OPEN file for INPUT
WHILE NOT End of file
Read Number from file
Total + Number = Total
Count = count + 1
END WHILE
CLOSE file
OUTPUT Count/Total
END
A Level Computing#BristolMet
TASK
Below is an algorithm that reads a file of integers and outputs
the mean. There are errors, where are they and what type of
error are they?
01
02
03
04
05
06
07
08
09
10
11
12
BEGIN
Total = 0
Count = 0
OPEN file for INPUT
WHILE NOT End of file
Read Number from file
Total + Number = Total - variables assigned on the left (Syntax)
Count = count + 1 – variable with different identifier (Syntax)
END WHILE – Indentation, not all languages (syntax)
CLOSE file
OUTPUT Count/Total –arithmetic error, not mean (Logic)
END
EXTENSION: Use sample test data to find when a
a Run-Time Error would occur
A Level Computing#BristolMet
TASK
Below is an algorithm that reads a file of integers and outputs
the mean. There are errors, where are they and what type of
error are they?
01
02
03
04
05
06
07
08
09
10
11
12
BEGIN
Total = 0
Count = 0
OPEN file for INPUT
WHILE NOT End of file
Read Number from file
Total = Number + Total
Count = Count + 1
END WHILE
CLOSE file
OUTPUT Total/Count
END
A Level Computing#BristolMet
Testing Strategies
Black box Testing – These techniques only concern inputs and
outputs of a program. Ideally every possible variation of input
to output would be tested but this is not possible so test data
is put into logical groups: Valid, Invalid and Borderline (or
Extreme, test data which is the boundary of the argument or
parameters) Try the example on p123.
White box testing – This is more concerned with the logic of the
algorithm and making sure all parts function as intended. Each
possible route is tested using test data and where Ifs or loops
TRUE/FALSE conditions are noted. See the working example p.125
Alpha and Beta Testing – Quite simply the difference is where
and by whom. Alpha takes place in the company by employees
acting as users. This is the first stage of testing whilst the
program is still not finished. Beta Testing is outside of the
company to a selective audience who will test rigorously and
provide development feedback.
A Level Computing#BristolMet
Debugging Tools
We have already mentioned that some languages have tools to help
find programming errors, such as Translator Diagnostics as seen
in Pythons’ IDLE.
Other Debugging Tools include stepping which allows a programmer
to check the logic of a program by executing one instruction at
a time.
TASK: Create a Macro in Excel using the VB Recorder and then use
the “step into” tool check the logic of the VB Script.
Dry Runs - A dry run is similar and could be used in conjunction
with black box testing. Actual test data is used testing each of
line or statement in a program. The logic is followed and
outputs are recorded in a trace table. See the example on p.129
and create your own trace table for the mean algorithm used
previously.
A Level Computing#BristolMet
Dry Runs
TASK: Produce a Dry Run and trace table to error for the
following algorithm
01
02
03
04
05
06
07
08
09
10
11
12
BEGIN
Total = 0
Count = 0
OPEN file for INPUT
WHILE NOT End of file
Read Number from file
Total + Number = Total
Count = count + 1
END WHILE
CLOSE file
OUTPUT Count/Total
END
A Level Computing#BristolMet
Download