LAB 06B - STRING TEST

Concepts

This assignment introduces you to a simple form of "unit testing" as a mechanism for exploring the string API. Focus on learning what unit tests are, what an "API" is, and what you can do with string objects.

APIs (Application Programming Interface)

As you can see above, the acronym API stands for Application Programming Interface. But what does that mean? In a nutshell, an API describes what you can do with a particular library or object that you are provided (or that you create). It describes how your code can "interface with" or "use" a particular library or object.

For example, the string API consists of member functions that tell you how long the string is, allow you to capitalize the string, tell you whether it contains a specific character, or allow you to extract a part of the string.

While the API really is the programmatic components that you can actually use, we often rely on API documentation to discover what you can do with a particular library or object. For example, in this assignment you will use the string API, and you will need to look up some API documentation about how you can use string objects.

Unit Testing

As entire books have been written on unit testing, we will merely introduce the topic here. A "unit test" is a small piece of code designed to test a specific part of a program's functionality. In other words, they are bits of code that test the functionality of other code!

For this assignment, that's all the preliminary information you really need to know about unit testing. You will actually write the unit tests, eventually getting the entire test suite to pass (at which point you should go outside and run a victory lap).

The string Mantra

How you read and interpret object-oriented code is important when it comes to understanding the difference between data types, variables, and the "values" that a variable represents. Take a look at the following code.

string name = "Jimi Hendrix";

You are familiar with that syntax, but as we delve into objects we want to emphasize a particular way of translating that from "computerese" to English. When reading the above code, you should say to yourself "name is a string whose contents are the words Jimi Hendrix." Say that sentence aloud while reading the line of code above. Seriously, say it aloud about three or four times:

"name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix. name is a string whose contents are the words Jimi Hendrix."

Doing this will help hammer home the way you should translate this line of code (and make anyone near you think there is something seriously wrong with you).

Instructions

A skeletal test suite (a collection of functions) has been provided for you in Lab06Bmain.cpp. Notice that the functions in this code are defined below main.cpp. Say what?? We'll cover why this works in class, as well as why this is actually the preferred style for a program such as Lab06Bmain.cpp.

Your job: complete the function implementations using the string API such that all tests pass. You should not modify the contents of main in this lab, and instead only implement the test functions.

You should start by reading the body of the function called RunAllTests in order to see what your functions must accomplish. For example, the function StringLength must return the length of the string "Now" using the string API. Take a look at the function StringLength to see an example of a successful implementation.

When your program prints "PASSED" for a given unit test instead of "FAILED," then you know that your function implementation for that test is complete. Once you get all functions to print "PASSED", do your victory lap!

Hints

We recommend that you complete the functions in the order in which they are called in RunAllTests.

If you have trouble getting a function to pass its test, use cout statements to help you troubleshoot what your code is doing.

The last six functions may require some extra effort (especially MiddleName, Capitalize and Substitute).

Leverage the string API as much as you can. Explore the string API to see how the functions work. The documentation may be somewhat confusing; thus, if there is something you don't understand, be sure to ask!