Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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")
3 changes: 1 addition & 2 deletions exercises/concept/freelancer-rates/.meta/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 10 additions & 12 deletions exercises/concept/last-will/last_will_test.cpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/catch.hpp>
Expand All @@ -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);
Expand All @@ -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));
}

Expand All @@ -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());
}

Expand Down