Defects in Ordinary Algorithms Not terminating a loop or recursion Defect a loop or a recursion does not always terminate 1e itis‘ infinite lesting strategies -Analyse what causes a repetitive action to be stoppe -Run test cases that you anticipate might not be handled correctly www.oseng.com C Lethbridge/Laganiere 2001 Chapter 10: Testing and Inspecting for High Quality 16
© Lethbridge/Laganière 2001 Chapter 10: Testing and Inspecting for High Quality 16 Defects in Ordinary Algorithms Not terminating a loop or recursion • Defect: —A loop or a recursion does not always terminate, i.e. it is ‘infinite’. • Testing strategies: —Analyse what causes a repetitive action to be stopped. —Run test cases that you anticipate might not be handled correctly
Defects in Ordinary Algorithms Not setting up the correct preconditions for an algorith Defect Preconditions state what must be true before the algorithm should be executed a defect would exist if a program proceeds to do its work, even when the preconditions are not satisfied Testing strategy -Run test cases in which each precondition is not satisfied www.oseng.com C Lethbridge/Laganiere 2001 Chapter 10: Testing and Inspecting for High Quality 17
© Lethbridge/Laganière 2001 Chapter 10: Testing and Inspecting for High Quality 17 Defects in Ordinary Algorithms Not setting up the correct preconditions for an algorithm • Defect: —Preconditions state what must be true before the algorithm should be executed. —A defect would exist if a program proceeds to do its work, even when the preconditions are not satisfied. • Testing strategy: —Run test cases in which each precondition is not satisfied
Defects in Ordinary Algorithms Not handling null conditions Defect a null condition is a situation where there normally are one or more data items to process but sometimes there are none -lt is a defect when a program behaves abnormally when a null condition is encountered Testing strateg -Brainstorm to determine unusual conditions and run appropriate tests www.oseng.com C Lethbridge/Laganiere 2001 Chapter 10: Testing and Inspecting for High Quality 18
© Lethbridge/Laganière 2001 Chapter 10: Testing and Inspecting for High Quality 18 Defects in Ordinary Algorithms Not handling null conditions • Defect: —A null condition is a situation where there normally are one or more data items to process, but sometimes there are none. —It is a defect when a program behaves abnormally when a null condition is encountered. • Testing strategy: —Brainstorm to determine unusual conditions and run appropriate tests
Defects in Ordinary Algorithms Not handling singleton or non-singleton conditions Defect -a singleton condition occurs when there is normally more than one of something, but sometimes there is only one a non -singleton condition is the inverse Defects occur when the unusual case is not properly handled ° esting strategy Brainstorm to determine unusual conditions and run appropriate tests www.oseng.com C Lethbridge/Laganiere 2001 Chapter 10: Testing and Inspecting for High Quality
© Lethbridge/Laganière 2001 Chapter 10: Testing and Inspecting for High Quality 19 Defects in Ordinary Algorithms Not handling singleton or non-singleton conditions • Defect: —A singleton condition occurs when there is normally more than one of something, but sometimes there is only one. —A non-singleton condition is the inverse. —Defects occur when the unusual case is not properly handled. • Testing strategy: —Brainstorm to determine unusual conditions and run appropriate tests
Defects in Ordinary Algorithms Off-by-one errors Defect -a program inappropriately adds or subtracts one -Or loops one too many times or one too few times -This is a particularly common type of defect ° esting strategy Develop tests in which you verify that the program computes the correct numerical answer performs the correct number of iterations www.oseng.com C Lethbridge/Laganiere 2001 Chapter 10: Testing and Inspecting for High Quality
© Lethbridge/Laganière 2001 Chapter 10: Testing and Inspecting for High Quality 20 Defects in Ordinary Algorithms Off-by-one errors • Defect: —A program inappropriately adds or subtracts one. —Or loops one too many times or one too few times. —This is a particularly common type of defect. • Testing strategy: —Develop tests in which you verify that the program: - computes the correct numerical answer. - performs the correct number of iterations