Linked List - Data Structures and Algorithms - Lab 2 | CS 331, Lab Reports of Data Structures and Algorithms

Material Type: Lab; Class: Data Structures and Algorithms; Subject: Computer Science; University: Illinois Institute of Technology; Term: Spring 2009;

Typology: Lab Reports

Pre 2010

Uploaded on 08/18/2009

koofers-user-bhp
koofers-user-bhp 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Linked Lists 3 YOUR WORK
CS 331 Lab 2: Linked Lists
Spring 2009
1 Introduction
In this lab you will code some of the basic functions for a singly linked list, and write
tests to verify that they work correctly.
1.1 Objectives
Your objectives for this lab:
Verify that you understand the basic operations on a singly linked list.
Gain experience using JUnit to test your code.
2 Linked List Files
Run git pull on your working copy, and you will find that the staff have added a
directory called linked-list-lab, which in turn contains three files.
LinkList.java This is the main file, where your class definition will live.
TestLinkList.java This is the JUnit test file.
Makefile This contains the compiling and testing scripts.
3 Your Work
Your job is to add a few functions, and the test cases necessary to verify them. It
is highly recommended that you write the JUnit tests before writing these
methods! To do this, write a stub function in LinkList.java that returns some-
thing of the correct type, and then add your test function. Once it compiles and
runs, commit the files to your repository. After that, start writing the method.
size returns the size of the list
1
pf3
pf4

Partial preview of the text

Download Linked List - Data Structures and Algorithms - Lab 2 | CS 331 and more Lab Reports Data Structures and Algorithms in PDF only on Docsity!

CS 331 Lab 2: Linked Lists

Spring 2009

1 Introduction

In this lab you will code some of the basic functions for a singly linked list, and write tests to verify that they work correctly.

1.1 Objectives

Your objectives for this lab:

  • Verify that you understand the basic operations on a singly linked list.
  • Gain experience using JUnit to test your code.

2 Linked List Files

Run git pull on your working copy, and you will find that the staff have added a directory called linked-list-lab, which in turn contains three files.

LinkList.java This is the main file, where your class definition will live.

TestLinkList.java This is the JUnit test file.

Makefile This contains the compiling and testing scripts.

3 Your Work

Your job is to add a few functions, and the test cases necessary to verify them. It is highly recommended that you write the JUnit tests before writing these methods! To do this, write a stub function in LinkList.java that returns some- thing of the correct type, and then add your test function. Once it compiles and runs, commit the files to your repository. After that, start writing the method.

size returns the size of the list

Inputs none Output an integer

Actually, this is already written for you. Sort of. It has a bug, but it will not show up until later. Don’t fix the bug just yet, leave it in there so you know that your tests are working.

insert place an element at the front of the list

Inputs E data — the element to add Output none

Once you’ve added this, you can update the testSize test to see how size works when you add things to it. You can fix that bug now. So far, you do not have any way of telling whether or not insert is working, but you can test that the size of the list is being updated correctly, and you should. But to really test it you will have to assume that find has been written. So, your tests should verify insert, size, and find simultaneously. What should you test?

  • Make sure that an empty list does not “find” anything, and that the size is zero.
  • Add one integer, test that the size is correct, and the integer you added is findable, but that the other integers are not. You only really need to check one of the “not found” integers.
  • Add another integer. Test that the size is correct, and that both of the integers you’ve added are there, but that the other ones are not.

find returns the location of an element within the list

Inputs E data Output int — the location of the element in the list. 0 not found 1,2,... first element, second element, ...

Use the .equals method to check for equality, not ==.

Linked Lists 4 HANDING IN

4 Handing In

To hand in your code, commit your final changes to the repository, and push the results to the server. We will test your code with our own JUnit tests. We will also test your JUnit tests with several broken versions of the solutions, to make sure you did them well.