mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Add initial test set-up.
This commit is contained in:
@@ -16,3 +16,4 @@ addons:
|
|||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- libboost-program-options-dev
|
- libboost-program-options-dev
|
||||||
|
- libboost-test-dev
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
|
|||||||
|
|
||||||
project(aoc2019)
|
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)
|
add_library(AoCSolutions src/solutions.hpp src/solutions.cpp src/day01.cpp)
|
||||||
target_compile_features(AoCSolutions PUBLIC cxx_std_17)
|
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)
|
add_executable(runner src/runner.cpp)
|
||||||
target_compile_features(runner PUBLIC cxx_std_17)
|
target_compile_features(runner PUBLIC cxx_std_17)
|
||||||
target_link_libraries(runner AoCSolutions Boost::program_options)
|
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)
|
||||||
|
|||||||
24
2019/tests/test_solutions.cpp
Normal file
24
2019/tests/test_solutions.cpp
Normal 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user