1 Lab Objectives
2 Testing has Route
3 Creating Graphs
4 Testing reachable From
5 If you have time left over
6 What to Turn in

Lab 6: Creating and Testing Graphs

1 Lab Objectives

In class, you developed a data structure for graphs consisting of a list of nodes, each of which has a list of other nodes (its outgoing "edges"). You also started writing a hasRoute method, that would determine whether one could get from a starting city (node) to a given destination (node).

In this lab, we want you to build examples of data and a good set of test cases for graph problems. Here is the code from Tuesday without the Examples class (so you can create your own Examples class for lab)

2 Testing hasRoute

Develop a good set of examples and test cases for testing hasRoute. You may find it easier to work on paper (at least at first), so you can draw good example graphs. Think about the various kinds of situations that a hasRoute method needs to handle. Create as many graphs and test cases as you need to cover those situations. Label each test case with a comment describing the situation that it is trying to test.

3 Creating Graphs

If you aren’t comfortable creating graphs, download Tuesday’s graphs code and try to create your examples in Java.

4 Testing reachableFrom

Now we want to add a method reachableFrom to the Graph class. It will take the name of a city (a String) and return a list of the names of all cities that one can get to starting from the input city. Design a set of examples and test cases for reachableFrom. You may find that your examples from hasRoute are sufficient. If so, that’s fine. But you should still write the test cases.

Be sure to write out the test cases as actual checkExpects, whether typed in or on paper. The goal of this exercise is for you to be very explicit about what these tests will look like.

Meet with your discussion groups and go over your tests, especially for reachableFrom.

5 If you have time left over

Actually try running your hasRoute tests on the code as we left it at the end of class on Tuesday. Do they work as expected? Or start trying to write reachableFrom (which we won’t write in class). Figure out what you most need practice on, and use the Tuesday code file as a starting point to work on it.

6 What to Turn in

If you wrote code, turn it in through Turnin. If you only worked on paper, no need to submit anything. Just make sure you signed in on the attendance sheet (whether or not you upload files to turnin).