CS 257: Software Design

Autocomplete, Phase 2 of 3

Continue with the partner you worked with to get set up in IntelliJ, GitHub, and git.

Lots of modern software has some kind of autocomplete feature. Google's autocomplete feature, for example:

is so widely used that it has been made into popular games. (Perhaps more notably, it has also provided a prominent example of how ostensibly neutral algorithms can do bad stuff.)

During the baseball season, I make heavy use of a site called Baseball HQ. Among many other things, this site allows me to search for specific baseball players by name, with an autocomplete feature to help me. Here, for example, I am provided with a scrollable list of Hernandezes when I enter "hernan":

But check this out. When I type "her", this is what I get:
What do you think? Is this the right first few items on the list of matches for "her"? Or should this autocomplete algorithm be improved? And if so, how?

1. The autocomplete task

For this assignment, you are going to implement an autocomplete feature for a dataset consisting of actor's names, much like the Baseball HQ autocomplete. The implementation of this feature will be reasonably interesting, and could be extremely useful in practice in the right context. But for our purposes, the main reason for implementing this system will be to help us practice test-driven development.

For Phase 2 of this assignment, you will not implement the autocomplete feature. Rather, you will develop a set of unit tests intended to ensure that your yet-to-be-implemented autocomplete feature does the right thing. Once you have developed a suitable set of unit tests, you will (in Phase 3) write the autocomplete feature itself. Once all your unit tests pass, you will have reasonable confidence that you have implemented your autocomplete feature correctly.

Before you can write a suite of unit tests, we need to describe the autocomplete feature in appropriate detail. Here's how it goes. When the user enters a search string S, then our program will invoke the getCompletions method on an Autocompleter object using the parameter S. In Java, this would look something like:

List<String> completions = myAutocompleter.getCompletions(S);

After this, the program would do whatever it wanted to do with the list of completions. For example, truncate the list to its first five items and display those in a popup window.

So, what remains is to describe the process by which Autocompleter.getCompletions should identify actors' names that are legal completions of S, and how it should sort those names once they are found. Here's my shot at doing that.

2. Required for phase 2

As noted above, your job for this part of the assignment is to implement a thorough collection of unit tests for the non-constructor public methods in Autocompleter. (As it happens, there is only one such method--getCompletions.) How many distinct unit tests you write is up to you. That said, you should strive for a thorough exploration of the testing space, including typical cases and boundary cases of various sorts.

You may not change Autocompleter in any way during Phase 2. In particular, the signatures for the Autocompleter constructor and the getCompletions method should never change during any phase of this project.

Writing tests without yet having the thing-to-be-tested in hand can feel a little weird. For example, it's hard to tell whether your testing code is correct until you have something to test against. But something has to be written first, and the benefits of writing tests first are substantial, so we're taking a strict line on that in this assignment. Don't write the code until you've first written the tests.

3. Notes about IntelliJ

To create your AutocompleterTest.java file in IntelliJ:

You may discover that when you first create your test file, there are some compile errors. You can address these problems by clicking on red text, clicking on the resulting red lightbulb, and following your nose from there. Be careful when taking the red lightbulb's advice, though--you might want to write down what decisions you made with the lightbulb, so you can track down any problems that pop up later.

4. General advice

5. Handing it in

Submit your program by committing and pushing to your GitHub repository and tagging the commit you want graded with a tag named "autocomplete_phase2".

Have fun!