CSC 213 – Large Scale Programming. Today’s Goal  Understand why testing code is important  Result of poor or no testing & embarrassment caused  Learn.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Control Structures Ranga Rodrigo. Control Structures in Brief C++ or JavaEiffel if-elseif-elseif-else-end caseinspect for, while, do-whilefrom-until-loop-end.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Mock test review Revision of Activity Diagrams for Loops,
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
Creator: ACSession No: 13 Slide No: 1Reviewer: SS CSE300Advanced Software EngineeringFebruary 2006 Testing - Techniques CSE300 Advanced Software Engineering.
TESTING LOOPS ● Simple Loops ● Nested Loops ● Concatenated Loops ● Unstructured Loops.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Testing an individual module
Computer Science II Exam I Review Monday, February 6, 2006.
Data Structure Algorithm Analysis TA: Abbas Sarraf
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Bigointro1 Algorithm Analysis & Program Testing An introduction.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Lecture 16: Big-Oh Notation
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
Software Engineering Lecture 12 Software Testing Techniques 1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
System/Software Testing
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
CSC 213 – Large Scale Programming. Why Do We Test?
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
CSC 107 – Programming For Science. Announcements  Tutors available MTWR in WTC206/WTC208  Special lab (with Macs) & not in the Tutoring Center  Can.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Agenda Introduction Overview of White-box testing Basis path testing
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Problem of the Day  Why are manhole covers round?
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Problem of the Day  Why are manhole covers round?
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
White-box Testing.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Problem of the Day  I am thinking of a question and propose 3 possible answers. Exactly one of the following is the solution. Which is it? A. Answer 1.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
CSC Programming for Science Lecture 10: Boolean Expressions & More If ­ Else Statements.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
13 Aug 2013 Program Verification. Proofs about Programs Why make you study logic? Why make you do proofs? Because we want to prove properties of programs.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
LECTURE 20: RECURSION CSC 212 – Data Structures. Humorous Asides.
Theory and Practice of Software Testing
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
CSC 395 – Software Engineering Lecture 27: White-Box Testing.
PHY 107 – Programming For Science. Today’s Goal  How to use while & do / while loops in code  Know & explain when use of either loop preferable  Understand.
Problem of the Day  On the next slide I wrote today’s problem of the day. It has 3 possible answers. Can you guess which 1 of the following is the solution?
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
Software Testing.
Introduction To Repetition The for loop
Loop Structures.
Testing UW CSE 160 Spring 2018.
Conditions and Ifs BIS1523 – Lecture 8.
Chapter 3: Selection Structures: Making Decisions
CSE 1020:Software Development
Defensive Programming
Presentation transcript:

CSC 213 – Large Scale Programming

Today’s Goal  Understand why testing code is important  Result of poor or no testing & embarrassment caused  Learn basics of writing good suite of test cases  What test cases should do (& should not do)  Managing test cases to find as many bugs as possible  Make debugging easier with clear, focused tests  Analyzing tests to not waste time on useless ones  Learn types of test cases that most often used  Useful and helpful ideas from coders in real-world

Why Does Testing Matter?

Does It Work Correctly?  You have two options with all of this testing: 1. Show code works by writing working tests 2. Stop complaining & accept your punishment

What Is “Correct”?  Could check code against design being used  Verification is name for these checks  These tests are easy to create  Verification still assumes design is correct  Validation checks code does what it should

What Is “Correct”?  All roads lead back to requirements

What Is The Error?  Make sure each test method looks for 1 error  Easier debugging when you also use good names  Can you figure out when each of these tests fail? testAverageOnNullArray() testInsertFirstWhenEmpty() testPopOnEmptyStack() testOnTimeUsingTim() testDeposit2()

Critical Property of Test

Could We Find an Error?  Write tests with known, constant answers  Use constants in your assert* statements  Relying on other methods’ results propagate errors  Which would you want, if your money’s at stake? assertEquals(cut.addTwo(10), cut.addOne(11)); assertEquals(cut.addTwo(10), 12); assertEquals(cut.winner(), cut.runners[0]); assertEquals(cut.winner(), cut.getRunner(0)); assertEquals(cut.winner(), “Cheetah”);

Are We Sure There Is No Error?  Test all aspects of results to look for any errors  Should begin by looking that data returned correct  Check any fields and see if they are what is expected  Add assertions that array entries & other data okay  Problems caused when assume without full data

Are We Sure There Is No Error?  Test all aspects of results to look for any errors  Should begin by looking that data returned correct  Check any fields and see if they are what is expected  Add assertions that array entries & other data okay  Problems caused when assume without full data

Where Is The Error?  Check methods from simplest to most complex  Check easiest methods first and get them working  Once this done, test methods calling the easiest ones  Most complex methods tested last after all else works  Fixes method with bug & prevents wasting time  ONLY call method being tested to also help with this

Why Is This An Error?

How To Write Tests  Cannot prove there are no bugs on those tests  Only ever show no bugs exist on those tests  Unlikely & boundary scenarios are vital to test

How To Write Tests  Cannot prove there are no bugs on those tests  Only ever show no bugs exist on those tests  Unlikely & boundary scenarios are vital to test  Keep in mind why Willie Sutton robbed banks That’s where the money is

How To Test Boundaries  Each test should provide additional information  Why write two tests which expose same bug?  Before writing test ask: what error will this expose?  Must Include boundary checks for objects – null  Test each parameter unless pre-condition says no  Good set of tests should also check all fields used  Boundaries for arrays & Strings also very simple  Unless forbidden, should also check if these null  Lengths of 0, 1, & n also important to try

Interesting Boundary Cases  Number are much harder; no simple rules exist  To find boundaries, must look at variables used  Try negative, 0, & 1 when used in arithmetic  Check values around limit in if(…) statements public int gcd(int ap, int a, int b) { if (b == 7) { return ap; } ap = a; a = b; b = ap % a; return gcd(ap, a, b); }

Types of Loops Simple Loop Concatenated Loops Unstructured Loops Nested Loops

Types of Loops Simple Loop Concatenated Loops Unstructured Loops Nested Loops

Simple Loop  For all simple loops, try inputs that:  Skip loop entirely  Make 1 pass through the loop  Make 2 passes through the loop  Make m passes through the loop, where ( m > 2)

Simple Loop  For all simple loops, try inputs that:  Skip loop entirely  Make 1 pass through the loop  Make 2 passes through the loop  Make m passes through the loop, where ( m > 2) public int factorial(int i) { int retVal = 1; for (int j = 2; j < i; j++) { retVal *= j; } return retVal; }

Simple Loop  If loop executed at most n times, try inputs that:  Make n -1, n, & ( n +1) passes through the loop

Simple Loop  If loop executed at most n times, try inputs that:  Make n -1, n, & ( n +1) passes through the loop public boolean isPrime(int i) { for (int j = 2; j < i; j++) { if (i % j == 0) { return false; } } return true; }

Simple Loop  If loop executed at most n times, try inputs that:  Make n -1, n, & ( n +1) passes through the loop public int factorial(int i) { int retVal = 1; for (int j = 2; j < i; j++) { retVal *= j; } return retVal; }

Types of Loops Simple Loop Concatenated Loops Unstructured Loops Nested Loops

Nested Loops public sumMatrix(int[][] matrix) { int retVal = 0; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++){ retVal += matrix[i][j]; } } return retVal; }

Nested Loops  First test set runs all outer loops exactly once  Inner loop runs ( min +1), average, ( max -1) & max times  Then run all but two innermost loops exactly once  Inner loops run ( min +1), average, ( max -1) & max times  Tests should continue growing loop-by-loop

Nested Loops public sumMatrix(int[][] matrix) { int retVal = 0; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[i].length; j++){ retVal += matrix[i][j]; } } return retVal; }

Types of Loops Simple Loop Concatenated Loops Unstructured Loops Nested Loops

Concatenated Loops  If loops are entirely independent  No conditions, variables, or values in common  Woo-hoo! Just perform single loop tests on each  Otherwise treat as nested loops & make life easier  Work as if the first loop is outermost loops

Types of Loops

Unstructured Loops

For Next Lecture  Next weekly assignment available on Angel  Due as usual on Tuesday at 5PM  With good notes on reading can delay this due date  Reading on advanced testing techniques  Does un-testable code exist?  What do we do with this flaky, scary code?  What tricks are there to help us work with it?