-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
Every project here is tested the same way, with a convention the course called file-per-test. There is no Catch2 or GoogleTest. The whole harness is <cassert> and the Makefile, which is the point: you see exactly what a test does because there is nothing between you and the assertion.
Each test_*.cpp is a complete program with its own main. It does three things in order:
- Set up a fixture (construct the objects under test).
- Run the operation being tested.
- Check the outcome with
assert.
A test usually packs several cases into separate { } blocks so each one has its own scope. Here is the shape, from the BigInt addition test:
{
bigint left(9);
bigint right(1);
bigint result;
result = left + right; // run
assert(left == 9); // verify
assert(right == 1);
assert(result == 10);
}If every assertion holds, the program prints a short "done" line and exits 0. The first assertion that fails calls abort, which exits non-zero, so a passing run and a clean exit code mean the same thing.
Each project's Makefile has a pattern rule that compiles any test_*.cpp against the class object file:
test_%: string.o test_%.o
$(CPP) $(OPTIONS) string.o test_$*.o -o test_$*and a tests target that builds the whole list and runs each binary in sequence. So make tests is the one command that checks a project.
-
BigInt: constructors, equality, addition, multiplication, subscript, and the
times10/timesDigithelpers. - Custom String: constructors, copy, assignment and swap, equality, less-than, concatenation, subscript, length and capacity, input, substring, find-char, find-string, and split.
-
Assembler: the stack, with default and copy construction, assignment, destruction, and push/pop across
int,double, andString.
Some folders contain test_generic_*.cpp files. These are the course's blank templates, with placeholder tokens like X and YYY where the real values would go. They are meant to be copied and filled in, so they do not compile or pass as written. The CI workflow skips any file matching test_generic_* and runs the rest.
The GitHub Actions workflow compiles each class and its tests with g++ -std=c++11 and runs every non-template test. The course Makefiles pin clang++ and -std=c++17 and several run targets read data files from the project directory, so CI compiles directly rather than calling make. The code builds clean under both toolchains.
Projects
Reference