CS 110 Elements of Computing

aniseedsplashΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 8 μήνες)

211 εμφανίσεις

CS 280

Data Structures

Professor John Peterson




Questions?

I’ll collect
Mergesort

this evening. Ask
questions now! It must be turned in by
Wednesday


I’ll hand out the solution
then.


Quiz

We’ll do these on the board.

Another similar quiz will hit on Friday

Remember: you can’t use .link or .data
until you’ve checked for null!


Debugging

Today we’re going to start talking about
unit testing


a more organized approach
to debugging.

Basic idea: instead of “typing in” test
cases, create a file containing test
cases using an automated framework to
run these test.

NEVER THROW AWAY A TEST!

Working With
DebugTest

On to Netbeans!

Start with the existing Link class and add
a
JUnit

test for the Link class.

Leave all the boxes checked.

Add the following instance variables to
TestLink
:


public Link<Integer> list1234;


public Link<Integer> list23;


Setup

The “setup” method creates fresh values
for the test cases. Here’s ours:


int

[] a1234 = {1,2,3,4};


int

[] a23 = {2,3};


list1234 =
Link.makeLI
(a1234);


list23 =
Link.makeLI
(a23);

The Tests

We’ll start with “
printLI



notice that there
is already a test there!

Let’s do this:

System.out.println
("
printLI
");


Link<Integer> l = null;


assertEquals
("Testing
printLI
(null)",
Link.printLI
(l), "{}");


assertEquals
("Testing
printLI
({1,2,3,4}",
Link.printLI
(list1234),


"{1, 2, 3, 4}");


Testing
makeLI

Test this by looking at the links in the
list23:

this.assertNotNull
("list23 is null!", list23);

this.assertEquals
("list23.data = 2", (
int
) list23.data, 2);

this.assertNotNull
("list23.link is null!", list23.link);

this.assertEquals
("list23.link.data = 3", (
int
) list23.link.data, 3);

this.assertNull
("list23.link.link should be null", list23.link.link);