Testing and Debugging

Similar documents
Lecture 3: Working with Data Structures

Testing and Debugging

Lecture 3: Maps and Iterators

Lecture 3: Queues, Testing, and Working with Code

Lecture 2: Implementing ADTs

Lecture 2: Stacks and Queues

Implementing Hash and AVL

CSE 373 APRIL 3 RD ALGORITHM ANALYSIS

ECE 122. Engineering Problem Solving Using Java

CSE 373 SEPTEMBER 29 STACKS AND QUEUES

Introduction to the Analysis of Algorithms. Algorithm

CSE 373: Data Structures and Algorithms. Asymptotic Analysis. Autumn Shrirang (Shri) Mare

Testing and Debugging

Priority Queues and Heaps

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

CS159. Nathan Sprague. September 30, 2015

CSE 373: Data Structures and Algorithms. Binary Search Trees. Autumn Shrirang (Shri) Mare

Lecture 1: Welcome! CSE 373: Data Structures and Algorithms CSE WI - KASEY CHAMPION 1

Binary Search and Worst-Case Analysis

Section 05: Solutions

CSc 110, Spring 2017 Lecture 39: searching

Java Software Solutions for AP Computer Science 3rd Edition, Lewis et al. 2011

CSE wi: Practice Midterm

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

CSCI-1200 Data Structures Fall 2017 Lecture 13 Problem Solving Techniques

Lecture Notes on Quicksort

Data Structures Lecture 3 Order Notation and Recursion

How invariants help writing loops Author: Sander Kooijmans Document version: 1.0

Algorithm Analysis. Big Oh

Scan and its Uses. 1 Scan. 1.1 Contraction CSE341T/CSE549T 09/17/2014. Lecture 8

[ 11.2, 11.3, 11.4] Analysis of Algorithms. Complexity of Algorithms. 400 lecture note # Overview

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

Lecture Notes on Quicksort

Binary Search and Worst-Case Analysis

CSE 373: Data Structures and Algorithms

CSE373 Winter 2014, Midterm Examination January 29, 2014

Lecture 7 Quicksort : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees. Linda Shapiro Spring 2016

Balanced Trees Part Two

Scan and Quicksort. 1 Scan. 1.1 Contraction CSE341T 09/20/2017. Lecture 7

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

CSE 373: Data Structures and Algorithms. Hash Tables. Autumn Shrirang (Shri) Mare

Unit Testing as Hypothesis Testing

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Principles of Algorithm Design

Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

n = 1 What problems are interesting when n is just 1?

Assertions. Assertions - Example

More Counting Sort and Sorting-by-Key

Lecture Notes on Binary Search Trees

Section 05: Solutions

CSE373 Fall 2013, Midterm Examination October 18, 2013

Lecture 6: Divide-and-Conquer

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

For searching and sorting algorithms, this is particularly dependent on the number of data elements.

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise

Reasoning about programs

What is an algorithm?

CSCI 104 Runtime Complexity. Mark Redekopp David Kempe Sandra Batista

Lecture 1: CSE 373. Data Structures and Algorithms

Why study algorithms? CS 561, Lecture 1. Today s Outline. Why study algorithms? (II)

Testing and Debugging

CSE 373: Data Structures and Algorithms

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Lecture 10: Introduction to Hash Tables

MITOCW watch?v=w_-sx4vr53m

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

DO NOT REPRODUCE. CS61B, Fall 2008 Test #3 (revised) P. N. Hilfinger

x-fast and y-fast Tries

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Unit Testing as Hypothesis Testing

CS 2230 CS II: Data structures. Meeting 26: the Set ADT Brandon Myers University of Iowa

Lecture 26. Introduction to Trees. Trees

Algorithm Analysis. CENG 707 Data Structures and Algorithms

CompuScholar, Inc. Alignment to Nevada "Computer Science" Course Standards

Lecture 15 Binary Search Trees

CSE 374 Programming Concepts & Tools

Numerical Methods in Scientific Computation

CSE332: Data Abstractions Lecture 4: Priority Queues; Heaps. James Fogarty Winter 2012

CSE373: Data Structures & Algorithms Lecture 9: Priority Queues and Binary Heaps. Linda Shapiro Spring 2016

CSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

x-fast and y-fast Tries

CS1 Lecture 22 Mar. 6, 2019

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016

CS:3330 (22c:31) Algorithms

CSE373: Data Structures & Algorithms Lecture 4: Dictionaries; Binary Search Trees. Kevin Quinn Fall 2015

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

ALGORITHM ANALYSIS. cs2420 Introduction to Algorithms and Data Structures Spring 2015

CSE 100 Advanced Data Structures

Intro to Algorithms. Professor Kevin Gold

Lecture 13: AVL Trees and Binary Heaps

Program Correctness and Efficiency. Chapter 2

CSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session

Transcription:

Testing and Debugging Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Warm Up From Last Lecture: - What are the expected operations for a map ADT? - How would you implement a Map - To optimize for insertion? - To optimize for retrieval? - What is an Iterator and what are its two key operations? Socrative: www.socrative.com Room Name: CSE373 Please enter your name as: Last, First CSE 373 SP 18 - KASEY CHAMPION 2

Administrivia Fill out class survey posted today Find a partner by Thursday! CSE 373 SP 18 - KASEY CHAMPION 3

Testing Computers don t make mistakes- people do! I m almost done, I just need to make sure it works Naive 14Xers Software Test: a separate piece of code that exercises the code you are assessing by providing input to your code and finishes with an assertion of what the result should be. 1. Isolate break your code into small modules 2. Build in increments Make a plan from simplest to most complex cases 3. Test as you go As your code grows, so should your tests CSE 373 SP 18 - KASEY CHAMPION 4

Types of Tests Black Box - Behavior only ADT requirements - From an outside point of view - Does your code uphold its contracts with its users? - Performance/efficiency White Box - Includes an understanding of the implementation - Written by the author as they develop their code - Break apart requirements into smaller steps - unit tests break implementation into single assertions CSE 373 SP 18 - KASEY CHAMPION 5

What to test? Expected behavior - The main use case scenario - Does your code do what it should given friendly conditions? Forbidden Input - What are all the ways the user can mess up? Empty/Null - Protect yourself! - How do things get started? Boundary/Edge Cases - First - last Scale - Is there a difference between 10, 100, 1000, 10000 items? CSE 373 SP 18 - KASEY CHAMPION 6

Tips for testing You cannot test every possible input, parameter value, etc. - Think of a limited set of tests likely to expose bugs. Think about boundary cases - Positive; zero; negative numbers - Right at the edge of an array or collection's size Think about empty cases and error cases - 0, -1, null; an empty list or array test behavior in combination - Maybe add usually works, but fails after you call remove - Make multiple calls; maybe size fails the second time only

Thought Experiment Discuss with your neighbors: Imagine you are writing an implementation of the List interface that stores integers in an Array. What are some ways you can assess your program s correctness in the following cases: Expected Behavior - Create a new list - Add some amount of items to it - Remove a couple of them Forbidden Input - Add a negative number - Add duplicates - Add extra large numbers Empty/Null - Call remove on an empty list - Add to a null list - Call size on an null list Boundary/Edge Cases - Add 1 item to an empty list - Set an item at the front of the list - Set an item at the back of the list Scale - Add 1000 items to the list - Remove 100 items in a row - Set the value of the same item 50 times CSE 373 SP 18 - KASEY CHAMPION 8

JUnit JUnit: a testing framework that works with IDEs to give you a special GUI experience when testing your code @Test public void mytest() { } Map<String, Integer> basicmap = new LinkedListDict<String, Integer>(); basicmap.put( Kasey, 42); assertequals(42, basicmap.get( Kasey )); Assertions: - assertequals(item1, item2) - asserttrue(boolean expression) - assertfalse(bollean expression) - assertnotnull(item) More: https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/assertions.html CSE 373 SP 18 - KASEY CHAMPION 9

Write Tests for our Dictionary CSE 373 SP 18 - KASEY CHAMPION 10

Debugger CSE 373 SP 18 - KASEY CHAMPION 11

Algorithm Analysis CSE 373 SP 18 - KASEY CHAMPION 12

Review: Sequential Search sequential search: Locates a target value in an array / list by examining each element from start to finish. - How many elements will it need to examine? - Example: Searching the array below for the value 42: index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 value -4 2 7 10 15 20 22 25 30 36 42 50 56 68 85 92 103 - What is the best case? - What is the worst case? - What is the complexity class? i CSE 143 SP 17 ZORA FUNG 13

Review: Binary Search binary search: Locates a target value in a sorted array or list by successively eliminating half of the array from consideration. - How many elements will it need to examine? - Example: Searching the array below for the value 42: index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 value -4 2 7 10 15 20 22 25 30 36 42 50 56 68 85 92 103 - What is the best case? - What is the worst case? - What is the complexity class? min mid max CSE 143 SP 17 ZORA FUNG 14

Analyzing Binary Search What is the pattern? - At each iteration, we eliminate half of the remaining elements How long does it take to finish? - 1 st iteration N/2 elements remain - 2 nd iteration N/4 elements remain - Kth iteration - N/2^k elements remain - Done when N/2^k = 1 index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 value -4 2 7 10 15 20 22 25 30 36 42 50 56 68 85 92 103 CSE 373 SP 18 - KASEY CHAMPION 15

Analyzing Binary Search Finishes when N / 2 K = 1 N / 2 K = 1 -> multiply right side by 2 K N = 2 K -> isolate K exponent with logarithm Log 2 N = k Is this exact? - N can be things other than powers of 2 - If N is odd we can t technically use Log 2 - When we have an odd number of elements we select the larger half - Within a fair rounding error CSE 373 SP 18 - KASEY CHAMPION 16

Asymptotic Analysis asymptotic analysis: how the runtime of an algorithm grows as the data set grows - bigo is the upper bound of an algorithm s asymptotic runtime Approximations - Basic operations take constant time - Assigning a variable - Accessing a field or array index - Consecutive statements - Some of time for each statement - Function calls - Time of function s body - Conditionals - Time of condition + maximum time of branch code - Loops - Number of iterations x time for loop body CSE 373 SP 18 - KASEY CHAMPION 17