This is a modern C++ template project specifically designed for solving Advent of Code challenges. It provides a structured environment for implementing solutions with test-driven development (TDD) in mind.
- Modern C++17 support with std::filesystem for robust file handling
- GoogleTest integration for unit testing
- Organized project structure for multiple years and days
- Flexible build system with warning controls
- Input file management
- Test-driven development support
.
├── src/
│ └── advent_of_code/
│ ├── 2015/
│ │ ├── day01/
│ │ │ ├── day01.cpp # Implementation
│ │ │ ├── day01.hpp # Header
│ │ │ ├── main.cpp # Main executable
│ │ │ └── input.txt # Puzzle input
│ │ └── ...
│ └── ...
├── test/
│ └── advent_of_code/
│ ├── 2015/
│ │ ├── day01_test.cpp
│ │ └── ...
│ └── ...
└── ...
- CMake 3.31 or higher
- C++17 compatible compiler
- Make
The project uses a simple Make-based build system with the following commands:
# Build the project (warnings disabled by default)
make build
# Build with warnings enabled
make build WARNINGS=on
# Run all tests
make test
# Run tests with warnings enabled
make test WARNINGS=on
# Run a specific day's solution
make run day=2015_day01
# Clean build directory
make cleanEach day's solution requires an input.txt file containing the puzzle input. Place these files in the corresponding day's directory:
src/advent_of_code/YYYY/dayXX/input.txt
For example, for Day 1 of 2015:
src/advent_of_code/2015/day01/input.txt
-
Create a new day's solution:
- Create directory:
src/advent_of_code/YYYY/dayXX/ - Add implementation files:
dayXX.cpp,dayXX.hpp,main.cpp - Add input file:
input.txt - Add test file:
test/advent_of_code/YYYY/dayXX_test.cpp
- Create directory:
-
Implement your solution:
- Write tests first (TDD approach)
- Implement the solution
- Run tests:
make test - Run solution:
make run day=YYYY_dayXX
-
Build options:
- Default build (no warnings):
make build - Build with warnings:
make build WARNINGS=on - Clean build:
make clean
- Default build (no warnings):
The project uses GoogleTest for unit testing. Test files should be placed in the test/advent_of_code/ directory, following the same year/day structure as the source files.
Example test file structure:
#include <gtest/gtest.h>
#include "day01.hpp"
TEST(Day01Test, Part1) {
// Your test cases here
}
TEST(Day01Test, Part2) {
// Your test cases here
}Run tests with:
make testPlease read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
- Advent of Code for the programming challenges
- GoogleTest for the testing framework
- Modern C++ Template for the base project structure