Add initial test set-up.

This commit is contained in:
2019-09-12 13:36:46 +02:00
parent 5585bce297
commit e26c90d54a
3 changed files with 34 additions and 1 deletions

View File

@@ -16,3 +16,4 @@ addons:
apt:
packages:
- libboost-program-options-dev
- libboost-test-dev

View File

@@ -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)

View File

@@ -0,0 +1,24 @@
#define BOOST_TEST_MODULE solutions_tests
#include <string>
#include <boost/test/included/unit_test.hpp>
#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");
}