Cosc175/testing1 Testing Software errors are costly GIGO Preventing Errors –Echo checking –Range and limit checking –Defensive programming.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
Selection (decision) control structure Learning objective
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 4 Repetitive Execution. 2 Types of Repetition There are two basic types of repetition: 1) Repetition controlled by a counter; The body of the.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Pseudocode and Algorithms
Computer Science 1620 Programming & Problem Solving.
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
1 Chapter 6 Looping Dale/Weems/Headington. 2 l Physical order vs. logical order l A loop is a repetition control structure based on a condition. l it.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Python quick start guide
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 4 Selection Structures: Making Decisions.
Chapter 02 (Part III) Introduction to C++ Programming.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
Control Structures Repetition or Iteration or Looping Part II.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Application: Correctness of Algorithms Lecture 22 Section 4.5 Fri, Feb 18, 2005.
1 Program Planning and Design Important stages before actual program is written.
Cosc175/module.ppt1 Introduction to Modularity Function/procedures void/value-returning Arguments/parameters Formal arguments/actual arguments Pass by.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
1 Programming 2 Overview of Programming 1. Write the equations in C++ notation : a) R =   a + b  24  2 a  b) W = a 12 + b 2 – 2abcos(y) 2a.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Computer Programming Control Structure
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Basic concepts of C++ Presented by Prof. Satyajit De
while Repetition Structure
Bill Tucker Austin Community College COSC 1315
Chapter 2 Assignment and Interactive Input
Lecture 07 More Repetition Richard Gesick.
Lesson Outcomes Be able to identify differentiate between types of error in programs Be able to interpret error messages and identify, locate.
Lecture 4B More Repetition Richard Gesick
CS 1430: Programming in C++ No time to cover HiC.
Coding Concepts (Basics)
Chapter 5: Control Structure
Repetition Statements (Loops) - 2
Unit 3: Variables in Java
CSE 1020:Software Development
Pseudo-Code Conditional Branches
CHAPTER 6 Testing and Debugging.
Presentation transcript:

cosc175/testing1 Testing Software errors are costly GIGO Preventing Errors –Echo checking –Range and limit checking –Defensive programming

cosc175/testing2 Testing Precondition – assertion that must be true for an algorithm to work correctly Postcondition – assertion that should be true after the module has executed

cosc175/testing3 //****************************************************** float Cube( /* in */ float x ) // Precondition: // The absolute value of x cubed does not exceed the // machine's maximum float value // Postcondition: // Function value == x cubed { return x * x * x; }

cosc175/testing4 Deskcheck Code walkthrough Trace –Write variable names across top of page –Trace each line of code and indicate new value in variable

cosc175/testing5 Trace const int X = 5; int main() { int a,b,c; b = 1; c = X + b; a = X + 4; a = c; b = c; a = a + b + c; c = c % X; c = c * a; a = a % b; cout << a << b << c; return 0; } abc

cosc175/testing6 trace the following with the values 90, 80, 40 Procedure PrintActivity( int temp ) Print "The recommended activity is "; if (temp > 85)AND (temp < 95) Print "swimming." else if (temp > 70) Print "tennis." else if (temp > 32) Print "golf." else if (temp > 0) Print "skiing." else Print "Chinese Checkers." End PrintActivity

cosc175/testing7 Testing strategy Start with values with known result Test all branches of conditionals Check limits of loops Logic errors - bug

cosc175/testing8 Debugging Breakpoint Stepping

cosc175/testing9 To start debugging 1.Click Start Debug on the Build menu. 2.Click Go, Step Into, or Run to Cursor.

cosc175/testing10 To run the program and execute the next statement (Step Into) 1.While the program is paused in break mode (program is waiting for user input after completing a debugging command), click Step Into from the Debug menu. The debugger executes the next statement, then pauses execution in break mode. If the next statement is a function call, the debugger steps into that function, then pauses execution at the beginning of the function. 2.Repeat step 1 to continue executing the program one statement at a time.

cosc175/testing11 Write a procedure that will input a y or n from the user and repeatedly print an error message and input another character until y or n is received. void GetYesOrNo(out char response ) Write a procedure that will input and validate an age for an employee. Write the postcondition void InputAge(out integer age )

cosc175/testing12 Use the following data sets: Set 1: 10,3,8,0 Set 2: 0 Set 3: 20,20,0 // calculate the average age While (age > 0) Input age total = total + age numAges = numAges + 1 End while Average = total + numAges

cosc175/testing13 Example 1: Ulam's Conjecture: Start with any number, n. If n is even, divide it by 2. If n is odd, multiply it by three and add 1. Repeat this process as long as n is greater than 1. Ulam's Conjecture is that n always becomes 1 eventually. Write a loop that tests this Conjecture for a specific value of n input by the user. Print each number in the series and at the end tell how many numbers were printed.

cosc175/testing14 Get number. count = 0. While (number > 1) If (number mod 2 = 0) number = number / 2. Else number = number * endif Print number. count = count + 1 End while. Print "count = " count Print "the Conjecture held."

cosc175/testing15 Example 2:Have the user enter 8 numbers from the keyboard and print out the largest of the numbers. Get number. biggest = number. count = 1 While count < 8 Get number. If number > biggest biggest = number. count = count + 1 End while Print biggest.

cosc175/testing16 Exercises 1.Perform a trace of example 1 using the following data sets: a.Set1: 10 b.Set2: 15 2.Perform a trace of example 2 from this weeks lecture notes using the following data sets: a.Set1: 5,10,15,20,25,30,35,0 b.Set2: 1,2,3,4,5,4,3,2 c.Set3: 0,0,0,0,5,5,5,5

cosc175/testing17 Exercises 1.Write the pseudocode to perform the following: You go to the local burger joint and order a burger, fries and a drink. You pay for your meal with a $5 bill. The total cost of your meal is $X (X is in dollars and cents - i.e., it's a float). Build a program that the cashier can use to help him/her give you your change. The program should tell the cashier how many half-dollars, quarters, dimes, nickels, and pennies (s)he should give you. 2.Have the user enter 8 numbers from the keyboard and print out the smallest and the largest of the numbers. 3.Build a predicate (a Boolean-valued function) that accepts a year. Its value is TRUE if the year is a leap year and is FALSE otherwise. A leap year is one that is evenly divisible by four, except for centuries - which are usually not, unless they are also evenly divisible by 400. So, 1996 is a leap year, 1900 is not a leap year, and 2000 is a leap year. 4.Build a function that tells the winner of the paper-rock-scissors game. Paper covers rock; rock breaks scissors; scissors cuts paper. Your function should accept the choices made by two players, and it should return the winner - or Nobody, in case the two players make the same selection.