SE 3800, Assignment 2
Writing Your Own Google Tests

This assignment gives you practice at writing maintainable, testable code and developing a carefully written, automated test suite. It assumes you have set up your computer to run Docker as discussed in assignment 1. For this assignment, you will write your own code and construct a Google test suite for that code. You will use this to set up a "pipeline" in the next assignment.

To enable Google Test in your Ubuntu image, you need to execute the commands that are in the Dockerfile from assignment 1: Start your Ubuntu image, open the list of applications, and run Software Updater. This will look for updates and attempt to install them. You can do the same thing from the command prompt by opening a Terminal window and typing

sudo apt update sudo apt upgrade
but running Software Updater is more robust. Once the system is up-to-date, type
        sudo apt install -y g++ cmake git libgtest-dev
        cd /usr/src/gtest
        sudo cmake CMakeLists.txt
        sudo make
        sudo cp lib/*.a /usr/lib
(Note: if the last step fails, try sudo cp *.a /usr/lib. If that fails, ask for help.)

Once you have Google Test set up, cd to the directory containing your cube code (cd ~/cube) and type

        make
        ./cube_test
to confirm the tests build and pass.

Using the cube code as an example, write your own program that classifies triangles by the angles entered by a user. All data is entered as floats. The triangles are classified as right, equilateral, isosceles, acute, obtuse, or not a triangle. The 'not a triangle' classification applies whenever the angles do not add to 180. For this and all other rules, use 10-4 as the tolerance; that is, all matches must be within one part of ten thousand. For legal triangles, the 'right' classification applies whenever one angle is within the tolerance of 90 degrees, and the equilateral classification applies if the angles are (nearly the) same, and the isosceles classification applies if it is not a right triangle and two angles are (nearly) the same. Acute and obtuse apply only when none of the other categories apply and (for acute) all angles are (significantly) less than 90 or (for obtuse) one angle is (significantly) greater than 90. To understand why tolerances are necessary with floating-point values, see ../../samples/crazy-math.cpp.

A naive implementation would be a single main that prompts for the input and writes the results. That is not very testable: it requires you to do various back-flips to capture standard output from test code. A far simpler mechanism is to write functions (and classes in some cases, though probably not for this assignment) that compute the results and returns them as a reference parameter of function result. You can then write main to call these functions and display the results. The wins of this method:

Break your solution into multiple functions that support testing. Your main should be so simple that the only testing needed is to ensure it handles a single common case. You can do that testing at the command prompt (by hand) rather than attempting to automate it through GoogleTest.

The goal of this assignment is to get some experience at writing your own code and tests using the Google framework, not to make you an expert with Google Test. However, there is one common mistake that should be addressed: comparing to true or false is always a bad idea. Use EXPECT_TRUE and EXPECT_FALSE instead of EXPECT_EQ(true, xyz). For example:

        EXPECT_TRUE(is_prime(23));
        EXPECT_FALSE(is_prime(100));
For more detail on Google Test, see this article. It is a quick read and explains the Google Test framework in more detail for those who are looking for more information.

Do's and Don'ts

Submission

Create a Makefile that builds your system (including the test executable), then create a Dockerfile that does the build and test run. Note that your tests will likely not run your main, but are to perform thorough testing for all functionality other than input and output.

Capture an evidence document showing that

Ensure your error is not a syntax error; the question is not whether Docker shows your code fails to build - that is easy to see using a compiler - but whether Docker shows when the code runs but gives the wrong result. Be careful to keep your evidence document focused on useful sections of the Docker output; I do not need installation steps, but I do need to see that the tests run and produce the correct output. A critical part of the output is both the test runs and the summary at the end stating how many tests passed and how many failed.

Submit a .ZIP file containing your source code and appropriate build files in the topmost directory. Do not include non-source files (like screen captures, .git folders, etc.) or build projects (like .o files or executables). In particular, your .ZIP will not contain your report. In most cases, you will submit a .ZIP containing Dockerfile, Makefile, .h files, and .cpp files. A Readme.txt is always appropriate (capturing project goals, build steps, and testing), but not required for this assignment.

Avoid some common errors: tabs in source files, forgetting to put your name in files, submitting files I do not need, and failing to satisfy the coding standard. Double-check the writeup when you are done to make sure you have completed everything; issues like forgetting to test within a tolerance value result in 10-point deductions. This assignment is about learning to write good, automated tests, so logic of classifying triangles is just a small part of the points for this assignment. If you have any difficulty with that logic, talk to your instructor for lots of hints!