Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS367 Intro to Data Structures

Similar presentations


Presentation on theme: "CS367 Intro to Data Structures"— Presentation transcript:

1 CS367 Intro to Data Structures
For Reading Assignments: See Syllabus Link Vote Today! Should have completed JUnit Tutorial, TestDie and Die of A0. ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

2 This Lecture A0 Questions Testing List Be sure to read the FAQs
Alternative to Array Implementation ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

3 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 © Used by permission. 12/7/2018

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

5 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 © Used by permission. 12/7/2018

6 Black Box Testing Advantages: test is unbiased
point of view of the user, not programmer. tests can be designed as soon as the specifications are complete. will discover if part of the specification has not been fulfilled. Advantages: The test is unbiased because the designer and the tester are independent of each other. The tester does not need knowledge of any specific programming languages. The test is done from the point of view of the user, not the designer. Test cases can be designed as soon as the specifications are complete. ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

7 Black Box Testing Disadvantages:
redundant if the software designer has already run the test case. can be difficult to design. testing every possible input stream is unrealistic; therefore, many program paths will go untested. (undetected bugs) Disadvantages: The test can be redundant if the software designer has already run a test case. The test cases are difficult to design. Testing every possible input stream is unrealistic because it would take a inordinate amount of time; therefore, many program paths will go untested. ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

8 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 © Used by permission. 12/7/2018

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

10 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 © Used by permission. 12/7/2018

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

12 ListArray: Remove Operation
Removing an element from an array leaves a hole! 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 © Used by permission. 12/7/2018

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

14 Alternate List Implementation
Can we implement a List without using an array? 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 © Used by permission. 12/7/2018

15 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 © Used by permission. 12/7/2018

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

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

18 Design of each Link (ListNode)
Object data ListNode next ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

19 Link (ListNode) with data
next String eggs null ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

20 add( "bacon" ) ListNode String eggs data next ListNode String bacon
null next String bacon ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

21 add( 1, "milk" ) ListNode String eggs data ListNode String next milk
null next String milk ListNode data null next String bacon ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

22 add( 1, "milk" ) ListNode String eggs data ListNode String next milk
null next String bacon ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

23 1 2 add( 1, "milk" ) ListNode String eggs data ListNode String next
1 2 ListNode data next String milk ListNode data null next String bacon ©2004 Deb Deppeler. Some content based on work by Susan Horwitz © Used by permission. 12/7/2018

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

25 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 © Used by permission. 12/7/2018


Download ppt "CS367 Intro to Data Structures"

Similar presentations


Ads by Google