180 likes | 388 Views
CMPF 144. Testing and Validating program. Programming errors. Debugging – is the process of finding and correcting errors in computer programs. Program debugging is another form of problem solving. 3 types of programming errors: Design errors Syntax errors Run-time errors. Design errors.
E N D
CMPF 144 Testing and Validating program
Programming errors • Debugging – is the process of finding and correcting errors in computer programs. • Program debugging is another form of problem solving. • 3 types of programming errors: • Design errors • Syntax errors • Run-time errors
Design errors • Occurs during : • Analysis • Design • Implementation phases • Make mistake in translating an algorithm into program • Choose incorrect method of solution for the problem to be solved • Design erroneous data for the program. Difficult to detect Debugging process: review careful the problem analysis , algorithm design , test data
Syntax errors/compilation errors • Violation of syntax rules • Syntax rules – define how the elements of a programming language must be written • Occur during the implementation phase –detected by compiler during compilation process • Compiler issues diagnostic message-warning message/error message
continue • Warning message • Indicates a minor error that may lead to a problem during program execution. • Does not cause the termination of the compilation process. • May cause errors sometimes (if serious)… • It is a good practice to warning seriously and eliminate their causes in the program.
continue • Error message • Will cause the compiler stop from compiling the program • It tell that nature of the errors and the location of errors in the program • Since compiler explicitly ‘inform” the errors, thus syntax errors is relatively easy
Example: syntax error >>> while True print 'Hello world‘ File "<stdin>", line 1, in ? while True print 'Hello world' ^ SyntaxError: invalid syntax
continue • The parser repeats the offending line and displays a little ‘arrow’ pointing at the earliest point in the line where the error was detected. • The error is caused by (or at least detected at) the token preceding the arrow: in the example, the error is detected at the keyword print since a colon (':') is missing before it. • File name and line number are printed so you know where to look in case the input came from a script.
Example 2 >>> print a+b: SyntaxError: invalid syntax
Run-times errors • Detected by computer while your program is being executed. • They are cause by program instructions that require the computer to do something illegal such as attempting to store inappropriate data or divide a number by 0. • When a run-time error is encountered, the computer produces an error diagnostic message and terminates the program execution.
Example: run-time errors >>> print 1/0 Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> print 1/0 ZeroDivisionError: integer division or modulo by zero
Example 2 >>> list=[123,'abc'] >>> print list[1] abc >>> print list[2] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range
Testing and verification • Program verification- is the process of ensuring that a program meets user requirements • Technique that can be use to verify program is by using program testing. • What is program testing???? • program testing is the process of executing a program to demonstrate its correctness.
continue • Used a set of data to test your program • Corrected output not necessarily means your program is logically correct.??? Why??? • Must test all the conditions (if any) , selection, looping all must be tested to look at the flow …logic or not…
Data validation • In computer science data validation is the process of ensuring that a program operates on clean, correct and useful data. • It uses routines, often called “validation rules " or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system. Visual Studio .NET 2003
example • The simplest data validation verifies that the characters provided come from a valid set. • For example, telephone numbers should include the digits and possibly the characters +, -, (, and ) (plus, minus, and brackets). • A more sophisticated data validation routine would check to see the user had entered a valid country code, i.e., that the number of digits entered matched the convention for the country or area specified. Visual Studio .NET 2003