diff --git a/.travis.yml b/.travis.yml index 275187d..1d6629a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,3 +16,4 @@ addons: apt: packages: - libboost-program-options-dev + - libboost-test-dev diff --git a/2019/CMakeLists.txt b/2019/CMakeLists.txt index 7492ad1..90a4179 100644 --- a/2019/CMakeLists.txt +++ b/2019/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project(aoc2019) -find_package(Boost REQUIRED COMPONENTS program_options) +find_package(Boost REQUIRED COMPONENTS program_options unit_test_framework) add_library(AoCSolutions src/solutions.hpp src/solutions.cpp src/day01.cpp) target_compile_features(AoCSolutions PUBLIC cxx_std_17) @@ -10,3 +10,11 @@ target_compile_features(AoCSolutions PUBLIC cxx_std_17) add_executable(runner src/runner.cpp) target_compile_features(runner PUBLIC cxx_std_17) target_link_libraries(runner AoCSolutions Boost::program_options) + +add_executable(test_solutions tests/test_solutions.cpp) +target_compile_features(test_solutions PUBLIC cxx_std_17) +target_link_libraries(test_solutions AoCSolutions Boost::unit_test_framework) +target_include_directories(test_solutions PRIVATE ${CMAKE_SOURCE_DIR}/src) + +enable_testing() +add_test(test_solutions test_solutions) diff --git a/2019/tests/test_solutions.cpp b/2019/tests/test_solutions.cpp new file mode 100644 index 0000000..c0ddf7a --- /dev/null +++ b/2019/tests/test_solutions.cpp @@ -0,0 +1,24 @@ +#define BOOST_TEST_MODULE solutions_tests + +#include +#include +#include "solutions.hpp" + +static std::string run_day1_part1(std::string_view input) { + std::stringstream input_stream; + input_stream.write(input.data(), input.size()); + + std::stringstream output_stream; + + aoc2019::day01_part1(input_stream, output_stream); + return output_stream.str(); +} + +BOOST_AUTO_TEST_CASE(sample_day1_part1) +{ + BOOST_TEST(run_day1_part1("+1\n-2\n+3\n+1") == "3\n"); + BOOST_TEST(run_day1_part1("+1\n+1\n+1") == "3\n"); + BOOST_TEST(run_day1_part1("+1\n+1\n-2") == "0\n"); +} + +