diff --git a/CMakeLists.txt b/CMakeLists.txt index f06cab610..814642e51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,31 @@ cmake_minimum_required(VERSION 3.5.1) project(exercism CXX) -set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice) - -function(build_fixup exercise_dir alt_exercise_root) +function(build_fixup exercise_dir alt_exercise_root exercise_type example_name) string(REPLACE "-" "_" file ${exercise_dir}) - set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/${exercise_dir}) + set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/${exercise_dir}) if(EXISTS ${source}) set(alt_exercise_dir ${alt_exercise_root}/${exercise_dir}) file(COPY ${source} DESTINATION ${alt_exercise_root}) - if(EXISTS ${alt_exercise_dir}/.meta/example.h) - file(RENAME ${alt_exercise_dir}/.meta/example.h ${alt_exercise_dir}/${file}.h) + if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.h) + file(RENAME ${alt_exercise_dir}/.meta/${example_name}.h ${alt_exercise_dir}/${file}.h) endif() - if(EXISTS ${alt_exercise_dir}/.meta/example.cpp) - file(RENAME ${alt_exercise_dir}/.meta/example.cpp ${alt_exercise_dir}/${file}.cpp) + if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.cpp) + file(RENAME ${alt_exercise_dir}/.meta/${example_name}.cpp ${alt_exercise_dir}/${file}.cpp) endif() endif() endfunction() +function(add_exercises exercise_type example_name) + file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/*) + set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/${exercise_type}) + foreach(exercise_dir ${exercise_list}) + get_filename_component(exercise ${exercise_dir} NAME) + build_fixup(${exercise} ${alt_exercise_tree} ${exercise_type} ${example_name}) + add_subdirectory(${alt_exercise_tree}/${exercise}) + endforeach() +endfunction() + option(EXERCISM_RUN_ALL_TESTS "Run all Exercism tests" On) option(EXERCISM_COMMON_CATCH "Link against a common Catch2 main lib." On) @@ -30,10 +38,5 @@ if(EXERCISM_COMMON_CATCH) ) endif() -file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*) - -foreach(exercise_dir ${exercise_list}) - get_filename_component(exercise ${exercise_dir} NAME) - build_fixup(${exercise} ${alt_exercise_tree}) - add_subdirectory(${alt_exercise_tree}/${exercise}) -endforeach() +add_exercises("concept" "exemplar") +add_exercises("practice" "example") diff --git a/exercises/concept/freelancer-rates/.meta/exemplar.cpp b/exercises/concept/freelancer-rates/.meta/exemplar.cpp index 89d8bc823..a1809a36b 100644 --- a/exercises/concept/freelancer-rates/.meta/exemplar.cpp +++ b/exercises/concept/freelancer-rates/.meta/exemplar.cpp @@ -19,9 +19,8 @@ int monthly_rate(double hourly_rate, double discount) { int workdays_per_month{22}; double per_month{per_day * workdays_per_month}; double after_discount{apply_discount(per_month, discount)}; - int rounded_up{std::ceil(after_discount)}; - return rounded_up; + return std::ceil(after_discount); } // days_in_budget calculates the number of workdays given a budget, hourly rate, diff --git a/exercises/concept/last-will/last_will_test.cpp b/exercises/concept/last-will/last_will_test.cpp index bd69bbc39..66fd16bf4 100644 --- a/exercises/concept/last-will/last_will_test.cpp +++ b/exercises/concept/last-will/last_will_test.cpp @@ -1,9 +1,3 @@ -// Trick to let the code compile, even if the function has not been implemented: -namespace estate_executor { - int assemble_account_number(int) __attribute__((weak)); - int assemble_code() __attribute__((weak)); -} - #include "last_will.cpp" #ifdef EXERCISM_TEST_SUITE #include @@ -14,9 +8,9 @@ namespace estate_executor { using namespace std; TEST_CASE("Family secrets have not been altered", "[task_1]") { - // We cannot test the existence of a namespace in the compiled + // We cannot test the existence of a namespace in the compiled // Code. - // This test merely checks if the numbers in the file have + // This test merely checks if the numbers in the file have // been changed. They have to be correct for the test to work. REQUIRE(zhang::bank_number_part(1) == 8541); @@ -35,7 +29,8 @@ TEST_CASE("Family secrets have not been altered", "[task_1]") { REQUIRE(garcia::blue::code_fragment() == 923); } -TEST_CASE("Account number assembly function exists in correct namespace", "[task_2]") { +TEST_CASE("Account number assembly function exists in correct namespace", + "[task_2]") { REQUIRE_NOTHROW(estate_executor::assemble_account_number(0)); } @@ -45,11 +40,14 @@ TEST_CASE("Account number assembly works correctly", "[task_2]") { int account_with_secret_1{16706}; int account_with_secret_23{14238}; - REQUIRE(estate_executor::assemble_account_number(1) == account_with_secret_1); - REQUIRE(estate_executor::assemble_account_number(23) == account_with_secret_23); + REQUIRE(estate_executor::assemble_account_number(1) == + account_with_secret_1); + REQUIRE(estate_executor::assemble_account_number(23) == + account_with_secret_23); } -TEST_CASE("Code fragment number assembly function exists in correct namespace", "[task_3]") { +TEST_CASE("Code fragment number assembly function exists in correct namespace", + "[task_3]") { REQUIRE_NOTHROW(estate_executor::assemble_code()); }