Testing & Quality Assurance Strategy¶
A comprehensive testing strategy ensures algorithmic correctness, memory safety, and command-line stability.
graph TD
subgraph "Testing Pyramid"
Unit["<b>Unit Tests (GoogleTest)</b><br/>Point, Graph, Dijkstra, I/O<br/>34 Test Cases"]
Smoke["<b>Integration & Smoke Tests</b><br/>CLI flags, pipelines, JSON parsing, error codes"]
Sanitizers["<b>Dynamic Analysis</b><br/>AddressSanitizer (ASan) & UndefinedBehaviorSanitizer (UBSan)"]
end
Unit --> Smoke --> Sanitizers
1. Unit Tests (GoogleTest)¶
Unit tests are located in test/unit/ and verify isolated components:
- Point Tests (
point_test.cpp): Euclidean distance edge cases, coordinate boundaries, deterministic random point distributions. - Graph Tests (
graph_test.cpp): Insertion, deletion, neighbor queries, edge weights, directed/undirected graphs, matrix/DOT serialization, graph resizing, and domain exception throwing. - Dijkstra Tests (
dijkstra_test.cpp): Canonical 6-node Wikipedia graph validation, disconnected graphs, single-node graphs, zero-weight edges, target-specific early exit, and reachability. - I/O Tests (
io_test.cpp): Stream extraction/insertion roundtrips, malformed stream error recovery, and path summary formatting.
Running Unit Tests¶
2. Integration & Smoke Tests¶
The CLI integration suite (test/integration/cli_test.sh) runs the actual compiled binaries against edge cases:
- Verification of
--helpand-hexit codes. - Rejection of invalid flags with non-zero exit codes.
- Pipe communication between
random-graphanddijkstra. - Target node path resolution.
- JSON payload syntax validation using Python's
jsonmodule. - DOT format graph structure validation.
- File input vs
stdinequivalence. - Proper error handling for nonexistent or corrupted files.
3. Dynamic Analysis: Sanitizers (ASan & UBSan)¶
To guarantee zero memory leaks, buffer overflows, and undefined behavior, the build supports LLVM/GCC sanitizers:
# Configure and build with AddressSanitizer and UndefinedBehaviorSanitizer
cmake -B build-asan -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON
cmake --build build-asan -j$(nproc)
# Run test suite under sanitizers
ctest --test-dir build-asan --output-on-failure
4. CMake Presets¶
Standard workflows are codified in CMakePresets.json: