CS 367 Intro to Data Structures 1 For

  • Slides: 25
Download presentation
CS 367 Intro to Data Structures 1. For Reading Assignments: See Syllabus Link http:

CS 367 Intro to Data Structures 1. For Reading Assignments: See Syllabus Link http: //www. cs. wisc. edu/~cs 367 -1 2. Vote Today! 3. Should have completed JUnit Tutorial, Test. Die and Die of A 0. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 1 12/14/2021

This Lecture ëA 0 Questions X Be sure to read the FAQs ëTesting ëList

This Lecture ëA 0 Questions X Be sure to read the FAQs ëTesting ëList X Alternative to Array Implementation © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 2 12/14/2021

Testing ëWhat should I test? ëHow many tests are enough? ëDo I have to

Testing ëWhat should I test? ëHow many tests are enough? ëDo I have to test my tests? ëHow do I test my tests? ëHow can I make my tests more understandable? ëHow can I make my software easier to test? © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 3 12/14/2021

Testing ëLevel X System (application) testing X Unit (class) testing ëDesign Strategy X Black

Testing ëLevel X System (application) testing X Unit (class) testing ëDesign Strategy X Black box (behavioral, functional, closed) X White box (structural, clear box, open) © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 4 12/14/2021

Black Box Testing ëTesting against the specification ëTester does not examine the program source

Black Box Testing ëTesting against the specification ëTester does not examine the program source and does not need any further knowledge of the program other than its specifications. ëInternal workings are unknown © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 5 12/14/2021

Black Box Testing ëAdvantages: X test is unbiased X point of view of the

Black Box Testing ëAdvantages: X test is unbiased X point of view of the user, not programmer. X tests can be designed as soon as the specifications are complete. X will discover if part of the specification has not been fulfilled. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 6 12/14/2021

Black Box Testing ëDisadvantages: X redundant if the software designer has already run the

Black Box Testing ëDisadvantages: X redundant if the software designer has already run the test case. X can be difficult to design. X testing every possible input stream is unrealistic; therefore, many program paths will go untested. (undetected bugs) © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 7 12/14/2021

White Box Testing ëtesting against the implementation ëuse specific knowledge of code to design

White Box Testing ëtesting against the implementation ëuse specific knowledge of code to design tests such that every line of source code is executed at least once. ëtests exception handling code. ëcan include requiring every method to be individually tested. Example: int result = addition(2, 2); if ( result == 4 ) System. out. print( "Pass: "); else System. out. print( "Fail: "); System. out. println( "addition(2, 2)=" + result ); © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 8 12/14/2021

White Box Testing ëAdvantages X will discover if any part of the implementation is

White Box Testing ëAdvantages X will discover if any part of the implementation is faulty X can test all paths (all lines of source). ëDisadvantages X will not discover if part is missing X works only if the tester knows what the program is supposed to do X all visible (public) code must also be readable by tester. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 9 12/14/2021

Black Box vs White Box ëIn order to fully test a software product both

Black Box vs White Box ëIn order to fully test a software product both black and white box testing are required. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 10 12/14/2021

Back to List ADT Method prototype Method Description List() constructor void add(Object ob) add

Back to List ADT Method prototype Method Description List() constructor void add(Object ob) add ob to end of list void add(int pos, Object ob) add ob to list at position pos true if ob is in the list boolean contains(Object ob) Object get(int pos) int size() Object remove(int pos) boolean is. Empty() returns the object at position pos returns the number of elements returns the object at position pos and shifts the rest returns true if there are no elements in the list © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 11 12/14/2021

List. Array: Remove Operation ëRemoving an element from an array leaves a hole! X

List. Array: Remove Operation ëRemoving an element from an array leaves a hole! X All remaining elements must be shifted to preserve the order of the elements and the efficiency of add and lookup operations. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 12 12/14/2021

List. ADT ëAny disadvantages to array-based? X initialize unknown size: must guess X add

List. ADT ëAny disadvantages to array-based? X initialize unknown size: must guess X add array may be full: must expand (how much? ) to add at position: elements must be moved X access: need to know position X remove: to eliminate holes: elements must be moved © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 13 12/14/2021

Alternate List Implementation ëCan we implement a List without using an array? X YES

Alternate List Implementation ëCan we implement a List without using an array? X YES ëUse a sequence of data and links to the next data to a. . . LIST © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 14 12/14/2021

Imagine ëa chain of links ëa train with linking cars ëa barrel of monkeys

Imagine ëa chain of links ëa train with linking cars ëa barrel of monkeys © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 15 12/14/2021

Linked Implementation ëEach item has data and link to next element eggs bacon bread

Linked Implementation ëEach item has data and link to next element eggs bacon bread milk © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 16 12/14/2021

How can I link data items? ëDesign and implement a List. Node class, where

How can I link data items? ëDesign and implement a List. Node class, where each instance has: X a reference to some data X a link (a reference) to the next instance of List. Node. © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 17 12/14/2021

Design of each Link (List. Node) List. Node Object data List. Node next ©

Design of each Link (List. Node) List. Node Object data List. Node next © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 18 12/14/2021

Link (List. Node) with data List. Node eggs data next String null © 2004

Link (List. Node) with data List. Node eggs data next String null © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 19 12/14/2021

add( "bacon" ) List. Node data String eggs next List. Node data next String

add( "bacon" ) List. Node data String eggs next List. Node data next String bacon null © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 20 12/14/2021

add( 1, "milk" ) List. Node data String eggs List. Node next data next

add( 1, "milk" ) List. Node data String eggs List. Node next data next List. Node data next String milk null String bacon null © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 21 12/14/2021

add( 1, "milk" ) List. Node data String eggs List. Node next data String

add( 1, "milk" ) List. Node data String eggs List. Node next data String milk next List. Node data next String bacon null © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 22 12/14/2021

add( 1, "milk" ) List. Node 0 data next String eggs List. Node data

add( 1, "milk" ) List. Node 0 data next String eggs List. Node data next List. Node 2 data next 1 String milk String bacon null © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 23 12/14/2021

Summary ëTesting X Black box vs White Box ëSingle-Linked List ADT © 2004 Deb

Summary ëTesting X Black box vs White Box ëSingle-Linked List ADT © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 24 12/14/2021

Next Lecture ëMore Linked List stuff ëIterators & Big-O ëRead Chapter 7, 9 &

Next Lecture ëMore Linked List stuff ëIterators & Big-O ëRead Chapter 7, 9 & 10 © 2004 Deb Deppeler. Some content based on work by Susan Horwitz © 2003. Used by permission. 25 12/14/2021