From 61e814c303c7544bac35a52790f759570ee37287 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sat, 5 Oct 2024 23:26:33 +0200 Subject: [PATCH 01/11] Move setting of alt_exercise_tree closer to where it is used. --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f06cab610..72a238d5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,6 @@ 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) string(REPLACE "-" "_" file ${exercise_dir}) set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/${exercise_dir}) @@ -31,7 +29,7 @@ if(EXERCISM_COMMON_CATCH) endif() file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*) - +set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice) foreach(exercise_dir ${exercise_list}) get_filename_component(exercise ${exercise_dir} NAME) build_fixup(${exercise} ${alt_exercise_tree}) From 3e19baa902c5f68854f7eea09cb9f9897375a8b6 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sat, 5 Oct 2024 23:30:27 +0200 Subject: [PATCH 02/11] Make name of example configurable. --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72a238d5b..d8f69259e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,17 @@ cmake_minimum_required(VERSION 3.5.1) project(exercism CXX) -function(build_fixup exercise_dir alt_exercise_root) +function(build_fixup exercise_dir alt_exercise_root example_name) string(REPLACE "-" "_" file ${exercise_dir}) set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/${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() @@ -32,6 +32,6 @@ file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*) set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice) foreach(exercise_dir ${exercise_list}) get_filename_component(exercise ${exercise_dir} NAME) - build_fixup(${exercise} ${alt_exercise_tree}) + build_fixup(${exercise} ${alt_exercise_tree} "example") add_subdirectory(${alt_exercise_tree}/${exercise}) endforeach() From 2af4c06a7e1a86419e013c3402c2aece46863698 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sat, 5 Oct 2024 23:34:22 +0200 Subject: [PATCH 03/11] Make exercise type configurable. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8f69259e..19e496937 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.5.1) project(exercism CXX) -function(build_fixup exercise_dir alt_exercise_root example_name) +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}) @@ -32,6 +32,6 @@ file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*) set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice) foreach(exercise_dir ${exercise_list}) get_filename_component(exercise ${exercise_dir} NAME) - build_fixup(${exercise} ${alt_exercise_tree} "example") + build_fixup(${exercise} ${alt_exercise_tree} "practice" "example") add_subdirectory(${alt_exercise_tree}/${exercise}) endforeach() From 2558b299cb6b38a3c900b0a0426e2c782afc238f Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sat, 5 Oct 2024 23:41:14 +0200 Subject: [PATCH 04/11] Make a function that iterates the exercises and call it for the practice exercises. --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19e496937..ceaceb4fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,16 @@ function(build_fixup exercise_dir alt_exercise_root exercise_type example_name) endif() endfunction() +function(iterate_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) @@ -28,10 +38,4 @@ if(EXERCISM_COMMON_CATCH) ) endif() -file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*) -set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice) -foreach(exercise_dir ${exercise_list}) - get_filename_component(exercise ${exercise_dir} NAME) - build_fixup(${exercise} ${alt_exercise_tree} "practice" "example") - add_subdirectory(${alt_exercise_tree}/${exercise}) -endforeach() +iterate_exercises("practice" "example") From 6a5cb0ba31e67f481703e33bc44f13e7caed9279 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sat, 5 Oct 2024 23:46:15 +0200 Subject: [PATCH 05/11] Also iterate the concept exercises. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ceaceb4fc..004ce1637 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,4 +38,5 @@ if(EXERCISM_COMMON_CATCH) ) endif() +iterate_exercises("concept" "exemplar") iterate_exercises("practice" "example") From ed204a48661c80790cacd11f0b886eb32a35669b Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Sun, 6 Oct 2024 12:42:47 +0200 Subject: [PATCH 06/11] =?UTF-8?q?Fix:=20'error:=20narrowing=20conversion?= =?UTF-8?q?=20of=20=E2=80=98ceil(after=5Fdiscount)=E2=80=99=20from=20?= =?UTF-8?q?=E2=80=98double=E2=80=99=20to=20=E2=80=98int=E2=80=99=20[-Werro?= =?UTF-8?q?r=3Dnarrowing]'=20caused=20by=20list=20initialization=20syntax?= =?UTF-8?q?=20converting=20a=20double=20to=20int.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/concept/freelancer-rates/.meta/exemplar.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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, From 95380481a64d5896ad8dcc5bd3117949f631aabf Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Thu, 10 Oct 2024 19:19:48 +0200 Subject: [PATCH 07/11] Rename iterate_exercises to add_exercises. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 004ce1637..814642e51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ function(build_fixup exercise_dir alt_exercise_root exercise_type example_name) endif() endfunction() -function(iterate_exercises exercise_type example_name) +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}) @@ -38,5 +38,5 @@ if(EXERCISM_COMMON_CATCH) ) endif() -iterate_exercises("concept" "exemplar") -iterate_exercises("practice" "example") +add_exercises("concept" "exemplar") +add_exercises("practice" "example") From 235b2eabd5f6ae7cef7653860d1f4d3869b8298a Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Thu, 10 Oct 2024 19:33:30 +0200 Subject: [PATCH 08/11] Fix typo: 'These operators modifies' -> 'These operators modify'. --- concepts/numbers/about.md | 2 +- concepts/numbers/introduction.md | 2 +- exercises/concept/freelancer-rates/.docs/introduction.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/concepts/numbers/about.md b/concepts/numbers/about.md index 8ef58f28f..c0b79e0d6 100644 --- a/concepts/numbers/about.md +++ b/concepts/numbers/about.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modifies the current value of a variable by performing an operation on it. +These operators modify the current value of a variable by performing an operation on it. ```cpp // we start with 0 people diff --git a/concepts/numbers/introduction.md b/concepts/numbers/introduction.md index a97f047d8..be17bde75 100644 --- a/concepts/numbers/introduction.md +++ b/concepts/numbers/introduction.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modifies the current value of a variable by performing an operation on it. +These operators modify the current value of a variable by performing an operation on it. ```cpp // we start with 0 people diff --git a/exercises/concept/freelancer-rates/.docs/introduction.md b/exercises/concept/freelancer-rates/.docs/introduction.md index a97f047d8..be17bde75 100644 --- a/exercises/concept/freelancer-rates/.docs/introduction.md +++ b/exercises/concept/freelancer-rates/.docs/introduction.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modifies the current value of a variable by performing an operation on it. +These operators modify the current value of a variable by performing an operation on it. ```cpp // we start with 0 people From 4b4a739ad55f40f1a2fbd876359192319f2e5bf5 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Fri, 11 Oct 2024 18:34:14 +0200 Subject: [PATCH 09/11] Revert "Fix typo: 'These operators modifies' -> 'These operators modify'." This reverts commit 235b2eabd5f6ae7cef7653860d1f4d3869b8298a. --- concepts/numbers/about.md | 2 +- concepts/numbers/introduction.md | 2 +- exercises/concept/freelancer-rates/.docs/introduction.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/concepts/numbers/about.md b/concepts/numbers/about.md index c0b79e0d6..8ef58f28f 100644 --- a/concepts/numbers/about.md +++ b/concepts/numbers/about.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modify the current value of a variable by performing an operation on it. +These operators modifies the current value of a variable by performing an operation on it. ```cpp // we start with 0 people diff --git a/concepts/numbers/introduction.md b/concepts/numbers/introduction.md index be17bde75..a97f047d8 100644 --- a/concepts/numbers/introduction.md +++ b/concepts/numbers/introduction.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modify the current value of a variable by performing an operation on it. +These operators modifies the current value of a variable by performing an operation on it. ```cpp // we start with 0 people diff --git a/exercises/concept/freelancer-rates/.docs/introduction.md b/exercises/concept/freelancer-rates/.docs/introduction.md index be17bde75..a97f047d8 100644 --- a/exercises/concept/freelancer-rates/.docs/introduction.md +++ b/exercises/concept/freelancer-rates/.docs/introduction.md @@ -60,7 +60,7 @@ Consider also that we are only assigning the value of `width` to `length` at the Therefore, if the value of `width` changes at a later moment, it will not affect the value taken by `length`. Assignment operator can be combined with the other operators(arithmetic & bitwise) known as `compound assignment` operators `+=`, `-=`, `*=`, `/=`, `%=`. -These operators modify the current value of a variable by performing an operation on it. +These operators modifies the current value of a variable by performing an operation on it. ```cpp // we start with 0 people From 0d270c14e482e628cb36c6b2eedbb27bbfb64e7f Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Fri, 11 Oct 2024 19:26:47 +0200 Subject: [PATCH 10/11] Remove GCC specific code from last_will_test. --- exercises/concept/last-will/last_will_test.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/exercises/concept/last-will/last_will_test.cpp b/exercises/concept/last-will/last_will_test.cpp index bd69bbc39..130aa62d5 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 From e50aadf61687b6a35f6587275f9248f29ea55aa5 Mon Sep 17 00:00:00 2001 From: Peter van der Heijden Date: Fri, 11 Oct 2024 19:44:35 +0200 Subject: [PATCH 11/11] Run clang-tidy. --- exercises/concept/last-will/last_will_test.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/exercises/concept/last-will/last_will_test.cpp b/exercises/concept/last-will/last_will_test.cpp index 130aa62d5..66fd16bf4 100644 --- a/exercises/concept/last-will/last_will_test.cpp +++ b/exercises/concept/last-will/last_will_test.cpp @@ -8,9 +8,9 @@ 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); @@ -29,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)); } @@ -39,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()); }