ProgrammingProgramming
TranslatorsTranslators
Learning ObjectivesLearning Objectives
Explain: What translators do The process of source-object code The three major error types which will need to be tested The concept of developing a test plan. Black box testing White box testing The concepts of Alpha tests and Beta tests Translator diagnostics Cross referencing Program traces Variable dumps Dry runs (desk checks)
• The general term used to describe all the programs, routines or procedures that run on a computer.
• Makes a computer do something and are written to run on the hardware.
•Computer instructions or data.
•Any instructions that can be stored electronically are software.
SoftwareSoftware
SoftwareSoftware
Computer instructions or data. Computer instructions or data.
Makes a computer do something and are Makes a computer do something and are written to run on the hardware.written to run on the hardware.
Hardware
Software
Hardware
High Level Languagese.g. Pascal, Visual Basic, C, Fortran
Machine Code
Software is usually written in a high level Software is usually written in a high level language which is fairly similar to our own language which is fairly similar to our own spoken languages.spoken languages. This makes it easier for us humans to use.This makes it easier for us humans to use.
However, computers only understand However, computers only understand machine code which is in binary form (1s machine code which is in binary form (1s and 0s).and 0s).
Translators High Level Languages
Machine Code
SourceCode
ObjectCode
TranslatorsTranslators
Translate high level languages (the Translate high level languages (the translator’s source code) into machine translator’s source code) into machine code (the translator’s object code) which code (the translator’s object code) which can be executed by a computer.can be executed by a computer.
Code written in a high level
language.
Code in executable
form.
There are three types program error (bug)
1. Syntax errors1. Syntax errors
Errors in a program that break the Errors in a program that break the grammar rulesgrammar rules of the language of the language being being used.used. e.g. e.g.
PLINTPLINT instead of instead of PRINTPRINT
3*(2+A) = X3*(2+A) = X instead of instead of X = 3*(2+A) X = 3*(2+A)
Simplest errors to solve as the translator Simplest errors to solve as the translator will find these errors before the program is will find these errors before the program is run.run.
Translator diagnosticsTranslator diagnostics
The translator looks up each word from a program in The translator looks up each word from a program in a dictionary. a dictionary. The dictionary tells the translator program what the rules The dictionary tells the translator program what the rules
are for that particular word. are for that particular word.
A wrongly typed word will not appear in the A wrongly typed word will not appear in the dictionary. dictionary. If rules governing how it should be used have not If rules governing how it should be used have not been followed properly, the translator will know that been followed properly, the translator will know that there is something wrong. there is something wrong. Either way, the translator program knows that a mistake Either way, the translator program knows that a mistake
has been made, it knows where the mistake is and, often, has been made, it knows where the mistake is and, often, it also knows what mistake has been made. it also knows what mistake has been made.
Translator diagnosticsTranslator diagnostics
Messages detailing syntax errors sent to Messages detailing syntax errors sent to the programmer and usually giving hints the programmer and usually giving hints as to what to do.as to what to do.
2. Logic errors 2. Logic errors (also known as run-time (also known as run-time errors if found when a program is run)errors if found when a program is run)
A mistake in the way the program solution A mistake in the way the program solution has been designed.has been designed. e.g.e.g.
An instruction in a program may tell the computer to An instruction in a program may tell the computer to jump to the wrong part of the program.jump to the wrong part of the program.
Total_number = Previous_total – New_numberTotal_number = Previous_total – New_number
Known as logic errors if found whilst not running a Known as logic errors if found whilst not running a program and using white box testing program and using white box testing – see later – see later slide 24..
Known as run-time errors if found when actually Known as run-time errors if found when actually running a program running a program (black box testing – see slide (black box testing – see slide 17))..
3. Arithmetic Errors 3. Arithmetic Errors (also known run-time errors (also known run-time errors if found when a program is run)if found when a program is run)
Inappropriate use of arithmetic. Inappropriate use of arithmetic. E.g. dividing by zeroE.g. dividing by zero
Known as arithmetic errors if found whilst Known as arithmetic errors if found whilst not running a program and using white box not running a program and using white box testing testing – see later – see later slide 24..
Known as run-time errors if found when Known as run-time errors if found when actually running a program actually running a program (black box testing – (black box testing –
see slide see slide 17))..
The last two errors (logic and arithmetic) The last two errors (logic and arithmetic) will not be found by the translator, so the will not be found by the translator, so the program will run but won’t work properly.program will run but won’t work properly.
Known collectively as Known collectively as run-time errorsrun-time errors if found if found when actually running a program (black box when actually running a program (black box testing – see slide testing – see slide 17).).
Program DevelopmentProgram Development
1.1. Testing:Testing:Are there any errors (bugs)?Are there any errors (bugs)?
2.2. Debugging:Debugging:Where is the error (bug) and what is causing Where is the error (bug) and what is causing it? it?
Solve the error (bug).Solve the error (bug).
Test Plan
A schedule drawn up which contains a test for every type of input that could be made and methods of testing that the program actually does what it was meant to do.
Alpha TestingAlpha Testing
Performed by the programmers involved in Performed by the programmers involved in writing the program.writing the program.
Focus on error free processing.Focus on error free processing.
Black box testing
Use of different input values to determine Use of different input values to determine whether the program can cope with them. whether the program can cope with them. These values should include These values should include
Different types of input e.g.Different types of input e.g. Typical valuesTypical values Borderline values Borderline values Unacceptable valuesUnacceptable values
Cannot see into the box (program) all you Cannot see into the box (program) all you see is what comes out at the end. see is what comes out at the end.
Example 1 of Black Box TestingExample 1 of Black Box Testing
A program which uses marks out of 100 A program which uses marks out of 100 from a math's examination as input.from a math's examination as input. Typical data like: 27, 73.., Typical data like: 27, 73.., Borderline data: 0 and 100Borderline data: 0 and 100 Unacceptable data like: –34, 123, 16.345 Unacceptable data like: –34, 123, 16.345
Example 2 of Black Box TestingExample 2 of Black Box Testing
A program to work out the mean of three A program to work out the mean of three numbers.numbers. 1, 2, 3 Will integers give an integer answer?1, 2, 3 Will integers give an integer answer? 1, 2, 4 Can the software cope with a recurring 1, 2, 4 Can the software cope with a recurring
decimal answer?decimal answer?(Note that “1, 2, 4 to test a different set of integers” would (Note that “1, 2, 4 to test a different set of integers” would not get a mark because the reason for the test is not not get a mark because the reason for the test is not different)different)
1, 2.5, 3 Can the program handle decimal inputs?1, 2.5, 3 Can the program handle decimal inputs? 1, 2½, 3 Are fractions allowed?1, 2½, 3 Are fractions allowed? -1, -2, -3 Can negative numbers be handled?-1, -2, -3 Can negative numbers be handled? 1, 2 What happens when only two values are input?1, 2 What happens when only two values are input?
Debugging ToolsDebugging Tools
Debugging tools to allow programmers to Debugging tools to allow programmers to investigate conditions where errors occur.investigate conditions where errors occur.
The following slides describe some The following slides describe some debugging tools.debugging tools.
Cross-referencingCross-referencing
This software checks the program that has This software checks the program that has been written and finds places where been written and finds places where particular variables have been used. particular variables have been used.
This lets the programmer check to make This lets the programmer check to make sure that the same variable has not been sure that the same variable has not been used twice for different things.used twice for different things.
Tracing variable values / Variable Tracing variable values / Variable Watching / SteppingWatching / Stepping
Where the program is run and the values Where the program is run and the values of all the relevant variables are printed out, of all the relevant variables are printed out, as are the individual instructions, as each as are the individual instructions, as each instruction is executed. instruction is executed.
In this way, the values can be checked to In this way, the values can be checked to see where they suddenly change or take see where they suddenly change or take on an unexpected value.on an unexpected value.
Break Points / Variable dumps / Break Points / Variable dumps / Variable WatchesVariable Watches
At specified parts of the program, the values of At specified parts of the program, the values of all the variables are displayed to enable the user all the variables are displayed to enable the user to compare them with the expected results.to compare them with the expected results.
This enables the programmer to see where This enables the programmer to see where sudden, unexpected changes occur.sudden, unexpected changes occur. Often used in conjunction with tOften used in conjunction with tracing variable racing variable
values / Variable Watching / Stepping values / Variable Watching / Stepping i.e. set breakpoints and then use tracing from these points as i.e. set breakpoints and then use tracing from these points as required.required.
Particularly useful for long programs where errors are Particularly useful for long programs where errors are believed to be only in certain parts of the code.believed to be only in certain parts of the code.
White Box Testing / Dry Runs / White Box Testing / Dry Runs / Desk CheckingDesk Checking
The user works through every logical path of the The user works through every logical path of the program instructions manually, keeping track of the program instructions manually, keeping track of the values of the variables. values of the variables.
Basically manual tracing or variable watches.Basically manual tracing or variable watches.
Most computer programs require a very large number of Most computer programs require a very large number of instructions to be carried out, so it is usual to only dry run instructions to be carried out, so it is usual to only dry run small segments of code that the programmer suspects of small segments of code that the programmer suspects of harboring an error.harboring an error.Testing knowing the code.Testing knowing the code.Testing the structure and logic of all the algorithms within Testing the structure and logic of all the algorithms within the code.the code.
Known as “white box” as testing is done by looking at the code Known as “white box” as testing is done by looking at the code so the program is like a transparent box.so the program is like a transparent box.
Beta TestingBeta Testing
Testing carried out by the users of the Testing carried out by the users of the programprogram.. Eventually, the company will want ordinary Eventually, the company will want ordinary
users to test the program because they are users to test the program because they are likely to find errors that the programmers did likely to find errors that the programmers did not find.not find.
Focus on usability, functionality, and Focus on usability, functionality, and performance.performance.
PlenaryPlenary
What is:What is: Source code?Source code?
Code written in hll.Code written in hll. Object code?Object code?
Code in executable form Code in executable form Machine code?Machine code?
Code in binary form. Code in binary form.
What is the process which connects source What is the process which connects source and object code?and object code?
A translator turns the source code into the object A translator turns the source code into the object code. code.
PlenaryPlenary
Explain how the translator program Explain how the translator program prepares the programmer’s code into a prepares the programmer’s code into a program that the machine can run.program that the machine can run.
Translator program turns source into object.Translator program turns source into object. Spots some of the errors in the source code.Spots some of the errors in the source code.
Wrong (reserved) wordsWrong (reserved) words
Wrong syntax in instruction constructionWrong syntax in instruction construction Reports errors to user.Reports errors to user.
PlenaryPlenary
State the meaning of the following types of State the meaning of the following types of testing.testing.
White box testing.White box testing.Testing all possible routes through the program Testing all possible routes through the program logic/Testing knowing the code/Test the algorithm. Note: logic/Testing knowing the code/Test the algorithm. Note: not dry run on its own not dry run on its own
Black box testing.Black box testing.Test that the outcome is as expected for a given Test that the outcome is as expected for a given input/Testing not knowing the codeinput/Testing not knowing the code
Alpha testing.Alpha testing.Testing by programmer/in-houseTesting by programmer/in-house
Beta testing. Beta testing. Testing by public/end users/potential users/unconnected Testing by public/end users/potential users/unconnected with writingwith writing
PlenaryPlenary
State State threethree types of program error and give an types of program error and give an example of each. example of each.
Syntax errorSyntax errorMistyping a reserved word, e.g. typing plint instead of printMistyping a reserved word, e.g. typing plint instead of print
Logic errorLogic errorA jump instruction that tells the computer to jump to the A jump instruction that tells the computer to jump to the wrong placewrong place
Arithmetic errorArithmetic errorInappropriate use of arithmetic.Inappropriate use of arithmetic. Dividing by zeroDividing by zero
PlenaryPlenary
Describe the techniques that can be used Describe the techniques that can be used to help debug a program.to help debug a program.
White Box Testing / Dry Runs / White Box Testing / Dry Runs / Desk CheckingDesk Checking
The user works through the program instructions The user works through the program instructions manually, keeping track of the values of the manually, keeping track of the values of the variables. variables. Most computer programs require a very large Most computer programs require a very large number of instructions to be carried out, so it is number of instructions to be carried out, so it is usual to only dry run small segments of code usual to only dry run small segments of code that the programmer suspects of harboring an that the programmer suspects of harboring an error.error.Testing knowing the code.Testing knowing the code.Testing specific algorithms within the code.Testing specific algorithms within the code. Known as “white box” as testing is done by looking at Known as “white box” as testing is done by looking at
the code so the program is like a transparent box.the code so the program is like a transparent box.
Cross-referencingCross-referencing
This software checks the program that has This software checks the program that has been written and finds places where been written and finds places where particular variables have been used. particular variables have been used.
This lets the programmer check to make This lets the programmer check to make sure that the same variable has not been sure that the same variable has not been used twice for different things.used twice for different things.
TracesTraces
A trace is where the program is run and A trace is where the program is run and the values of all the relevant variables are the values of all the relevant variables are printed out, as are the individual printed out, as are the individual instructions, as each instruction is instructions, as each instruction is executed. executed.
In this way, the values can be checked to In this way, the values can be checked to see where they suddenly change or take see where they suddenly change or take on an unexpected value.on an unexpected value.
Variable dumpsVariable dumps
At specified parts of the program, the At specified parts of the program, the values of all the variables are displayed to values of all the variables are displayed to enable the user to compare them with the enable the user to compare them with the expected results.expected results.