From 317b6d73d757e766994e2e9064582fe9af7e6aed Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 22:55:29 -0700 Subject: [PATCH 01/16] ci(c++): update regex for detecting changes --- .github/workflows/cpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index a109f7af..2ceaba4a 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -29,7 +29,7 @@ jobs: # Check if the files are present in the changed file list (added, modified, deleted) then output to stdout. HAS_DIFF=false printf "=== Which C++ files changed? ===\n" - if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.*[.](cpp|h|hpp)|.*/[Ma]akefile|.github/workflows/cpp.yml)$'; then + if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.*[.](cpp|h|hpp)|.*/[Ma]akefile|.*/CMakeLists.txt|.github/workflows/cpp.yml)$'; then HAS_DIFF=true fi printf "\n" From 56b7a2c606e8f77b8b898408356215f9c537ac15 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 22:58:05 -0700 Subject: [PATCH 02/16] c++/hello_world: 2nd iteration - c header -> c++ header --- cpp/hello-world/CMakeLists.txt | 6 +- cpp/hello-world/hello_world.cpp | 2 +- .../{hello_world.h => hello_world.hpp} | 6 +- cpp/hello-world/hello_world_test.cpp | 2 +- cpp/hello-world/run-tests-cpp.txt | 76 ++++++++----------- 5 files changed, 39 insertions(+), 53 deletions(-) rename cpp/hello-world/{hello_world.h => hello_world.hpp} (89%) diff --git a/cpp/hello-world/CMakeLists.txt b/cpp/hello-world/CMakeLists.txt index d6325041..76ea78aa 100644 --- a/cpp/hello-world/CMakeLists.txt +++ b/cpp/hello-world/CMakeLists.txt @@ -20,20 +20,20 @@ endif() # Use the common Catch library? if(EXERCISM_COMMON_CATCH) # For Exercism track development only - add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp $) elseif(EXERCISM_TEST_SUITE) # The Exercism test suite is being run, the Docker image already includes a # pre-built version of Catch. find_package(Catch2 REQUIRED) - add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h) + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp) target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain) # When Catch is installed system wide we need to include a different header, # we need this define to use the correct one. target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE) else() # Build executable from sources and headers - add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp test/tests-main.cpp) endif() diff --git a/cpp/hello-world/hello_world.cpp b/cpp/hello-world/hello_world.cpp index 036b2f1f..26672bf0 100644 --- a/cpp/hello-world/hello_world.cpp +++ b/cpp/hello-world/hello_world.cpp @@ -1,4 +1,4 @@ -#include "hello_world.h" +#include "hello_world.hpp" using namespace std; diff --git a/cpp/hello-world/hello_world.h b/cpp/hello-world/hello_world.hpp similarity index 89% rename from cpp/hello-world/hello_world.h rename to cpp/hello-world/hello_world.hpp index 8f672011..494c35fb 100644 --- a/cpp/hello-world/hello_world.h +++ b/cpp/hello-world/hello_world.hpp @@ -1,8 +1,8 @@ // This is an include guard. // You could alternatively use '#pragma once' // See https://en.wikipedia.org/wiki/Include_guard -#if !defined(HELLO_WORLD_H) -#define HELLO_WORLD_H +#if !defined(HELLO_WORLD_HPP) +#define HELLO_WORLD_HPP // Include the string header so that we have access to 'std::string' #include @@ -19,4 +19,4 @@ std::string hello(); } // namespace hello_world -#endif +#endif // HELLO_WORLD_HPP diff --git a/cpp/hello-world/hello_world_test.cpp b/cpp/hello-world/hello_world_test.cpp index d62f9cae..0abc2ce0 100644 --- a/cpp/hello-world/hello_world_test.cpp +++ b/cpp/hello-world/hello_world_test.cpp @@ -1,5 +1,5 @@ // Include the header file with the definitions of the functions you create. -#include "hello_world.h" +#include "hello_world.hpp" // Include the test framework. #ifdef EXERCISM_TEST_SUITE diff --git a/cpp/hello-world/run-tests-cpp.txt b/cpp/hello-world/run-tests-cpp.txt index ddaef161..71a72b93 100644 --- a/cpp/hello-world/run-tests-cpp.txt +++ b/cpp/hello-world/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.004s -user 0m0.002s -sys 0m0.002s +real 0m0.007s +user 0m0.001s +sys 0m0.006s =============================================================================== @@ -82,17 +82,17 @@ TOTAL 38 31 81% lines: 81.6% (31 out of 38) branches: 28.6% (8 out of 28) -real 0m9.165s -user 0m8.313s -sys 0m0.844s +real 0m10.253s +user 0m9.264s +sys 0m0.980s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.224s -user 0m0.178s -sys 0m0.047s +real 0m0.183s +user 0m0.116s +sys 0m0.069s =============================================================================== @@ -114,64 +114,50 @@ found lint: Convention: 4 -real 0m0.198s -user 0m0.139s +real 0m0.165s +user 0m0.107s sys 0m0.059s =============================================================================== -Running: clang-format-16 -style=file -i ./hello_world.cpp ./hello_world_test.cpp ./hello_world.h +Running: clang-format-16 -style=file -i ./hello_world.cpp ./hello_world_test.cpp -real 0m0.020s -user 0m0.009s -sys 0m0.011s +real 0m0.022s +user 0m0.008s +sys 0m0.014s =============================================================================== Running: ../../.github/citools/cpp/clang-check -clang-check-16 --analyze ./hello_world.cpp ./hello_world_test.cpp ./hello_world.h -error: argument unused during compilation: '-stdlib=libstdc++' [-Werror,-Wunused-command-line-argument] -error: invalid argument '-std=c++17' not allowed with 'C' -/home/vpayno/git_vpayno/exercism-workspace/cpp/hello-world/hello_world.h:8:10: fatal error: 'string' file not found -#include - ^~~~~~~~ -1 error generated. -Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/hello-world/hello_world.h. +clang-check-16 --analyze ./hello_world.cpp ./hello_world_test.cpp ./hello_world.hpp -real 0m0.544s -user 0m0.491s -sys 0m0.053s +real 0m0.734s +user 0m0.675s +sys 0m0.058s -real 0m0.546s -user 0m0.492s -sys 0m0.053s +real 0m0.736s +user 0m0.676s +sys 0m0.060s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 11382 warnings generated. 46771 warnings generated. -46771 warnings and 3 errors generated. -Error while processing /home/vpayno/git_vpayno/exercism-workspace/cpp/hello-world/hello_world.h. -Suppressed 46776 warnings (46771 in non-user code, 5 NOLINT). +58151 warnings generated. +Suppressed 58156 warnings (58151 in non-user code, 5 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -Found compiler error(s). -real 0m6.209s -user 0m6.139s -sys 0m0.069s -Running: clang-tidy-16 ./hello_world.cpp ./hello_world_test.cpp ./hello_world.h -error: invalid argument '-std=c++17' not allowed with 'C' [clang-diagnostic-error] -error: argument unused during compilation: '-stdlib=libstdc++' [clang-diagnostic-unused-command-line-argument] -/home/vpayno/git_vpayno/exercism-workspace/cpp/hello-world/hello_world.h:8:10: error: 'string' file not found [clang-diagnostic-error] -#include - ^~~~~~~~ +real 0m7.959s +user 0m7.889s +sys 0m0.068s +Running: clang-tidy-16 ./hello_world.cpp ./hello_world_test.cpp ./hello_world.hpp -real 0m6.212s -user 0m6.140s -sys 0m0.073s +real 0m7.961s +user 0m7.892s +sys 0m0.068s =============================================================================== From 1f501c15b39ea874b633a275e304bac579efa9c5 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 23:05:38 -0700 Subject: [PATCH 03/16] c++/darts: lint clean up --- cpp/darts/darts.cpp | 3 +- cpp/darts/darts.hpp | 2 +- cpp/darts/run-tests-cpp.txt | 80 +++++++++++++++---------------------- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/cpp/darts/darts.cpp b/cpp/darts/darts.cpp index 8b221463..d9e5f472 100644 --- a/cpp/darts/darts.cpp +++ b/cpp/darts/darts.cpp @@ -2,8 +2,9 @@ namespace darts { +// NOLINTNEXTLINE(readability-identifier-length) int score(double x, double y) { - double distance = std::hypot(x, y); + const double distance = std::hypot(x, y); if (distance <= 1.0) { return 10; diff --git a/cpp/darts/darts.hpp b/cpp/darts/darts.hpp index a712ac40..b9e9f16e 100644 --- a/cpp/darts/darts.hpp +++ b/cpp/darts/darts.hpp @@ -5,7 +5,7 @@ namespace darts { - int score(double x, double y); + int score(double x, double y); // NOLINT(readability-identifier-length) } // namespace darts diff --git a/cpp/darts/run-tests-cpp.txt b/cpp/darts/run-tests-cpp.txt index e7a01a47..03515338 100644 --- a/cpp/darts/run-tests-cpp.txt +++ b/cpp/darts/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.006s -user 0m0.002s -sys 0m0.004s +real 0m0.017s +user 0m0.003s +sys 0m0.014s =============================================================================== @@ -78,17 +78,17 @@ TOTAL 68 63 92% lines: 92.6% (63 out of 68) branches: 38.6% (85 out of 220) -real 0m10.058s -user 0m9.218s -sys 0m0.835s +real 0m9.722s +user 0m8.891s +sys 0m0.827s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.157s -user 0m0.111s -sys 0m0.048s +real 0m0.144s +user 0m0.107s +sys 0m0.038s =============================================================================== @@ -110,16 +110,16 @@ found lint: Convention: 4 -real 0m0.161s -user 0m0.121s -sys 0m0.041s +real 0m0.169s +user 0m0.123s +sys 0m0.046s =============================================================================== Running: clang-format-16 -style=file -i ./darts.cpp ./darts_test.cpp -real 0m0.022s -user 0m0.010s +real 0m0.018s +user 0m0.006s sys 0m0.012s =============================================================================== @@ -127,49 +127,33 @@ sys 0m0.012s Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./darts.cpp ./darts_test.cpp ./darts.hpp -real 0m0.553s -user 0m0.517s -sys 0m0.036s +real 0m0.555s +user 0m0.526s +sys 0m0.029s -real 0m0.555s -user 0m0.519s -sys 0m0.036s +real 0m0.557s +user 0m0.526s +sys 0m0.031s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -8744 warnings generated. -44098 warnings generated. -52839 warnings generated. -Suppressed 52839 warnings (52834 in non-user code, 5 NOLINT). +8739 warnings generated. +44091 warnings generated. +52830 warnings generated. +Suppressed 52843 warnings (52830 in non-user code, 13 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m8.772s -user 0m8.698s -sys 0m0.074s -Running: clang-tidy-16 ./darts.cpp ./darts_test.cpp ./darts.hpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/darts/darts.cpp:5:18: warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length] -int score(double x, double y) { - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/darts/darts.cpp:5:28: warning: parameter name 'y' is too short, expected at least 3 characters [readability-identifier-length] -int score(double x, double y) { - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/darts/darts.cpp:6:5: warning: variable 'distance' of type 'double' can be declared 'const' [misc-const-correctness] - double distance = std::hypot(x, y); - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/darts/darts.hpp:8:22: warning: parameter name 'x' is too short, expected at least 3 characters [readability-identifier-length] - int score(double x, double y); - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/darts/darts.hpp:8:32: warning: parameter name 'y' is too short, expected at least 3 characters [readability-identifier-length] - int score(double x, double y); - ^ - - -real 0m8.774s -user 0m8.699s +real 0m8.648s +user 0m8.571s sys 0m0.076s +Running: clang-tidy-16 ./darts.cpp ./darts_test.cpp ./darts.hpp + + +real 0m8.650s +user 0m8.571s +sys 0m0.079s =============================================================================== From 51620d8c04e2eaacc8d0cd6f994583e8adc5fde0 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 23:10:24 -0700 Subject: [PATCH 04/16] c++/freelancer-rates: lint clean up --- cpp/freelancer-rates/freelancer_rates.cpp | 4 + cpp/freelancer-rates/run-tests-cpp.txt | 90 ++++++++--------------- 2 files changed, 34 insertions(+), 60 deletions(-) diff --git a/cpp/freelancer-rates/freelancer_rates.cpp b/cpp/freelancer-rates/freelancer_rates.cpp index 87d88e1a..3e4cbf8c 100644 --- a/cpp/freelancer-rates/freelancer_rates.cpp +++ b/cpp/freelancer-rates/freelancer_rates.cpp @@ -8,6 +8,7 @@ double daily_rate(double hourly_rate) { } // apply_discount calculates the price after a discount +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) double apply_discount(double before_discount, double discount) { const double charge_rate = (100 - discount) / 100; @@ -16,7 +17,9 @@ double apply_discount(double before_discount, double discount) { // monthly_rate calculates the monthly rate, given an hourly rate and a discount // The returned monthly rate is rounded up to the nearest integer. +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) int monthly_rate(double hourly_rate, double discount) { + const double billable_days = 22.0; const double monthly_cost = daily_rate(hourly_rate) * billable_days; @@ -29,6 +32,7 @@ int monthly_rate(double hourly_rate, double discount) { // days_in_budget calculates the number of workdays given a budget, hourly rate, // and discount The returned number of days is rounded down (take the floor) to // the next integer. +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) int days_in_budget(int budget, double hourly_rate, double discount) { const double daily_cost = daily_rate(hourly_rate); diff --git a/cpp/freelancer-rates/run-tests-cpp.txt b/cpp/freelancer-rates/run-tests-cpp.txt index b4aad475..e5ebb8de 100644 --- a/cpp/freelancer-rates/run-tests-cpp.txt +++ b/cpp/freelancer-rates/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.009s -user 0m0.000s -sys 0m0.009s +real 0m0.010s +user 0m0.003s +sys 0m0.007s =============================================================================== @@ -77,17 +77,17 @@ TOTAL 90 79 87% lines: 87.8% (79 out of 90) branches: 32.8% (67 out of 204) -real 0m10.424s -user 0m9.702s -sys 0m0.717s +real 0m9.836s +user 0m8.967s +sys 0m0.867s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.190s -user 0m0.117s -sys 0m0.048s +real 0m0.157s +user 0m0.091s +sys 0m0.066s =============================================================================== @@ -109,82 +109,52 @@ found lint: Convention: 4 -real 0m0.158s -user 0m0.105s -sys 0m0.042s +real 0m0.165s +user 0m0.116s +sys 0m0.050s =============================================================================== Running: clang-format-16 -style=file -i ./freelancer_rates.cpp ./freelancer_rates_test.cpp -real 0m0.029s -user 0m0.011s -sys 0m0.011s +real 0m0.019s +user 0m0.010s +sys 0m0.009s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./freelancer_rates.cpp ./freelancer_rates_test.cpp -real 0m0.482s -user 0m0.445s -sys 0m0.036s +real 0m0.502s +user 0m0.461s +sys 0m0.041s -real 0m0.484s -user 0m0.447s -sys 0m0.037s +real 0m0.504s +user 0m0.461s +sys 0m0.042s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -8742 warnings generated. -44098 warnings generated. -Suppressed 44099 warnings (44094 in non-user code, 5 NOLINT). +8739 warnings generated. +44092 warnings generated. +Suppressed 44102 warnings (44091 in non-user code, 11 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m6.984s -user 0m6.916s -sys 0m0.066s +real 0m6.923s +user 0m6.850s +sys 0m0.072s Running: clang-tidy-16 ./freelancer_rates.cpp ./freelancer_rates_test.cpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:11:23: warning: 2 adjacent parameters of 'apply_discount' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters] -double apply_discount(double before_discount, double discount) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:11:30: note: the first parameter in the range is 'before_discount' -double apply_discount(double before_discount, double discount) { - ^~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:11:54: note: the last parameter in the range is 'discount' -double apply_discount(double before_discount, double discount) { - ^~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:19:18: warning: 2 adjacent parameters of 'monthly_rate' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters] -int monthly_rate(double hourly_rate, double discount) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:19:25: note: the first parameter in the range is 'hourly_rate' -int monthly_rate(double hourly_rate, double discount) { - ^~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:19:45: note: the last parameter in the range is 'discount' -int monthly_rate(double hourly_rate, double discount) { - ^~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:32:20: warning: 3 adjacent parameters of 'days_in_budget' of convertible types are easily swapped by mistake [bugprone-easily-swappable-parameters] -int days_in_budget(int budget, double hourly_rate, double discount) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:32:24: note: the first parameter in the range is 'budget' -int days_in_budget(int budget, double hourly_rate, double discount) { - ^~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:32:59: note: the last parameter in the range is 'discount' -int days_in_budget(int budget, double hourly_rate, double discount) { - ^~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates.cpp:32:32: note: 'int' and 'double' may be implicitly converted -int days_in_budget(int budget, double hourly_rate, double discount) { - ^ /home/vpayno/git_vpayno/exercism-workspace/cpp/freelancer-rates/freelancer_rates_test.cpp:1:11: warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include] #include "freelancer_rates.cpp" ^ -real 0m6.987s -user 0m6.918s -sys 0m0.068s +real 0m6.925s +user 0m6.850s +sys 0m0.075s =============================================================================== From b67ec6e36d285c435456bd3cd7a471fa65ae2d78 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 23:13:49 -0700 Subject: [PATCH 05/16] c++/interest-is-interesting: lint clean up --- .../interest_is_interesting.cpp | 1 + cpp/interest-is-interesting/run-tests-cpp.txt | 64 ++++++++----------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/cpp/interest-is-interesting/interest_is_interesting.cpp b/cpp/interest-is-interesting/interest_is_interesting.cpp index ad8726c0..17e32c16 100644 --- a/cpp/interest-is-interesting/interest_is_interesting.cpp +++ b/cpp/interest-is-interesting/interest_is_interesting.cpp @@ -28,6 +28,7 @@ double annual_balance_update(double balance) { // years_until_desired_balance calculates the minimum number of years required // to reach the desired balance. +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) int years_until_desired_balance(double balance, double target_balance) { double moving_balance{balance}; int years_needed{0}; diff --git a/cpp/interest-is-interesting/run-tests-cpp.txt b/cpp/interest-is-interesting/run-tests-cpp.txt index d08c6a35..d88a6358 100644 --- a/cpp/interest-is-interesting/run-tests-cpp.txt +++ b/cpp/interest-is-interesting/run-tests-cpp.txt @@ -6,8 +6,8 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.007s -user 0m0.001s +real 0m0.008s +user 0m0.002s sys 0m0.005s =============================================================================== @@ -77,17 +77,17 @@ TOTAL 229 218 95% lines: 95.2% (218 out of 229) branches: 35.7% (168 out of 470) -real 0m10.208s -user 0m9.179s -sys 0m1.019s +real 0m9.602s +user 0m8.751s +sys 0m0.850s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.175s -user 0m0.119s -sys 0m0.058s +real 0m0.176s +user 0m0.135s +sys 0m0.042s =============================================================================== @@ -113,53 +113,43 @@ found lint: Convention: 5 -real 0m0.163s -user 0m0.115s -sys 0m0.047s +real 0m0.172s +user 0m0.098s +sys 0m0.071s =============================================================================== Running: clang-format-16 -style=file -i ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp -real 0m0.023s -user 0m0.009s -sys 0m0.014s +real 0m0.029s +user 0m0.012s +sys 0m0.017s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp -real 0m0.450s -user 0m0.409s -sys 0m0.041s +real 0m0.590s +user 0m0.529s +sys 0m0.060s -real 0m0.452s -user 0m0.409s -sys 0m0.043s +real 0m0.592s +user 0m0.529s +sys 0m0.062s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -1 warning generated. -35383 warnings generated. -Suppressed 35384 warnings (35379 in non-user code, 5 NOLINT). +35381 warnings generated. +Suppressed 35385 warnings (35378 in non-user code, 7 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m5.689s -user 0m5.622s -sys 0m0.067s +real 0m5.396s +user 0m5.330s +sys 0m0.066s Running: clang-tidy-16 ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting.cpp:31:33: warning: 2 adjacent parameters of 'years_until_desired_balance' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters] -int years_until_desired_balance(double balance, double target_balance) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting.cpp:31:40: note: the first parameter in the range is 'balance' -int years_until_desired_balance(double balance, double target_balance) { - ^~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting.cpp:31:56: note: the last parameter in the range is 'target_balance' -int years_until_desired_balance(double balance, double target_balance) { - ^~~~~~~~~~~~~~ /home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting_test.cpp:1:11: warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include] #include "interest_is_interesting.cpp" ^ @@ -173,8 +163,8 @@ int years_until_desired_balance(double balance, double target_balance) { const -real 0m5.691s -user 0m5.622s +real 0m5.399s +user 0m5.330s sys 0m0.070s =============================================================================== From 932bc3a2d5fbf825a4b28b2b8c44423867d4fae7 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 16 Jul 2023 23:25:38 -0700 Subject: [PATCH 06/16] c++/interest-is-interesting: add hpp file and namespace --- cpp/interest-is-interesting/CMakeLists.txt | 8 +- .../interest_is_interesting.cpp | 6 + .../interest_is_interesting.hpp | 15 ++ .../interest_is_interesting_test.cpp | 209 +++++++++--------- cpp/interest-is-interesting/run-tests-cpp.txt | 94 ++++---- 5 files changed, 177 insertions(+), 155 deletions(-) create mode 100644 cpp/interest-is-interesting/interest_is_interesting.hpp diff --git a/cpp/interest-is-interesting/CMakeLists.txt b/cpp/interest-is-interesting/CMakeLists.txt index aac52b34..8a303aab 100644 --- a/cpp/interest-is-interesting/CMakeLists.txt +++ b/cpp/interest-is-interesting/CMakeLists.txt @@ -20,19 +20,21 @@ endif() # Use the common Catch library? if(EXERCISM_COMMON_CATCH) # For Exercism track development only - add_executable(${exercise} ${file}_test.cpp $) + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp + $) elseif(EXERCISM_TEST_SUITE) # The Exercism test suite is being run, the Docker image already includes a # pre-built version of Catch. find_package(Catch2 REQUIRED) - add_executable(${exercise} ${file}_test.cpp) + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp) target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain) # When Catch is installed system wide we need to include a different header, # we need this define to use the correct one. target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE) else() # Build executable from sources and headers - add_executable(${exercise} ${file}_test.cpp test/tests-main.cpp) + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.hpp + test/tests-main.cpp) endif() set_target_properties( diff --git a/cpp/interest-is-interesting/interest_is_interesting.cpp b/cpp/interest-is-interesting/interest_is_interesting.cpp index 17e32c16..2b845d21 100644 --- a/cpp/interest-is-interesting/interest_is_interesting.cpp +++ b/cpp/interest-is-interesting/interest_is_interesting.cpp @@ -1,3 +1,7 @@ +#include "interest_is_interesting.hpp" + +namespace interest_is_interesting { + // interest_rate returns the interest rate for the provided balance. double interest_rate(double balance) { double rate{0.0}; @@ -41,3 +45,5 @@ int years_until_desired_balance(double balance, double target_balance) { return years_needed; ; } + +} // namespace interest_is_interesting diff --git a/cpp/interest-is-interesting/interest_is_interesting.hpp b/cpp/interest-is-interesting/interest_is_interesting.hpp new file mode 100644 index 00000000..697d0efb --- /dev/null +++ b/cpp/interest-is-interesting/interest_is_interesting.hpp @@ -0,0 +1,15 @@ +#if !defined(INTEREST_IS_INTERESTING_HPP) +#define INTEREST_IS_INTERESTING_HPP + +#include + +namespace interest_is_interesting { + + double interest_rate(double balance); + double yearly_interest(double balance); + double annual_balance_update(double balance); + int years_until_desired_balance(double balance, double target_balance); // NOLINT(bugprone-easily-swappable-parameters) + +} // namespace interest_is_interesting + +#endif // INTEREST_IS_INTERESTING_HPP diff --git a/cpp/interest-is-interesting/interest_is_interesting_test.cpp b/cpp/interest-is-interesting/interest_is_interesting_test.cpp index aab33d02..dcfc73e5 100644 --- a/cpp/interest-is-interesting/interest_is_interesting_test.cpp +++ b/cpp/interest-is-interesting/interest_is_interesting_test.cpp @@ -1,4 +1,4 @@ -#include "interest_is_interesting.cpp" +#include "interest_is_interesting.hpp" #ifdef EXERCISM_TEST_SUITE #include #else @@ -6,214 +6,221 @@ #endif TEST_CASE("Minimal first interest rate", "[task1]") { - double balance{0}; - double want{0.5}; - REQUIRE_THAT(interest_rate(balance), + const double balance{0}; + const double want{0.5}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("Tiny first interest rate", "[task1]") { - double balance{0.000001}; - double want{0.5}; - REQUIRE_THAT(interest_rate(balance), + const double balance{0.000001}; + const double want{0.5}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Maximum first interest rate", "[task1]") { - double balance{999.9999}; - double want{0.5}; - REQUIRE_THAT(interest_rate(balance), + const double balance{999.9999}; + const double want{0.5}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Minimal second interest rate", "[task1]") { - double balance{1000.0}; - double want{1.621}; - REQUIRE_THAT(interest_rate(balance), + const double balance{1000.0}; + const double want{1.621}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Tiny second interest rate", "[task1]") { - double balance{1000.0001}; - double want{1.621}; - REQUIRE_THAT(interest_rate(balance), + const double balance{1000.0001}; + const double want{1.621}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Maximum second interest rate", "[task1]") { - double balance{4999.9990}; - double want{1.621}; - REQUIRE_THAT(interest_rate(balance), + const double balance{4999.9990}; + const double want{1.621}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Minimal third interest rate", "[task1]") { - double balance{5000.0000}; - double want{2.475}; - REQUIRE_THAT(interest_rate(balance), + const double balance{5000.0000}; + const double want{2.475}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Tiny third interest rate", "[task1]") { - double balance{5000.0001}; - double want{2.475}; - REQUIRE_THAT(interest_rate(balance), + const double balance{5000.0001}; + const double want{2.475}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Large third interest rate", "[task1]") { - double balance{5639998.742909}; - double want{2.475}; - REQUIRE_THAT(interest_rate(balance), + const double balance{5639998.742909}; + const double want{2.475}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on minimal negative balance", "[task1]") { - double balance{-0.000001}; - double want{3.213}; - REQUIRE_THAT(interest_rate(balance), + const double balance{-0.000001}; + const double want{3.213}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on small negative balance", "[task1]") { - double balance{-0.123}; - double want{3.213}; - REQUIRE_THAT(interest_rate(balance), + const double balance{-0.123}; + const double want{3.213}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on regular negative balance", "[task1]") { - double balance{-300.0}; - double want{3.213}; - REQUIRE_THAT(interest_rate(balance), + const double balance{-300.0}; + const double want{3.213}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on large negative balance", "[task1]") { - double balance{-152964.231}; - double want{3.213}; - REQUIRE_THAT(interest_rate(balance), + const double balance{-152964.231}; + const double want{3.213}; + REQUIRE_THAT(interest_is_interesting::interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on negative balance", "[task2]") { - double balance{-10000.0}; - double want{-321.3}; - REQUIRE_THAT(yearly_interest(balance), + const double balance{-10000.0}; + const double want{-321.3}; + REQUIRE_THAT(interest_is_interesting::yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on small balance", "[task2]") { - double balance{555.43}; - double want{2.77715}; - REQUIRE_THAT(yearly_interest(balance), + const double balance{555.43}; + const double want{2.77715}; + REQUIRE_THAT(interest_is_interesting::yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on medium balance", "[task2]") { - double balance{4999.99}; - double want{81.0498379}; - REQUIRE_THAT(yearly_interest(balance), + const double balance{4999.99}; + const double want{81.0498379}; + REQUIRE_THAT(interest_is_interesting::yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on large balance", "[task2]") { - double balance{34600.80}; - double want{856.3698}; - REQUIRE_THAT(yearly_interest(balance), + const double balance{34600.80}; + const double want{856.3698}; + REQUIRE_THAT(interest_is_interesting::yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for empty start balance", "[task3]") { - double balance{0.0}; - double want{0.0000}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{0.0}; + const double want{0.0000}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for small positive start balance", "[task3]") { - double balance{0.000001}; - double want{0.000001005}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{0.000001}; + const double want{0.000001005}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for average positive start balance", "[task3]") { - double balance{1000.0}; - double want{1016.210000}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{1000.0}; + const double want{1016.210000}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for large positive start balance", "[task3]") { - double balance{1000.2001}; - double want{1016.413343621}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{1000.2001}; + const double want{1016.413343621}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for huge positive start balance", "[task3]") { - double balance{898124017.826243404425}; - double want{920352587.2674429417}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{898124017.826243404425}; + const double want{920352587.2674429417}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for small negative start balance", "[task3]") { - double balance{-0.123}; - double want{-0.12695199}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{-0.123}; + const double want{-0.12695199}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for large negative start balance", "[task3]") { - double balance{-152964.231}; - double want{-157878.97174203}; - REQUIRE_THAT(annual_balance_update(balance), + const double balance{-152964.231}; + const double want{-157878.97174203}; + REQUIRE_THAT(interest_is_interesting::annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Years before desired balance for small start balance") { - double balance{100.0}; - double target_balance{125.80}; - int want{47}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{100.0}; + const double target_balance{125.80}; + const int want{47}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Years before desired balance for average start balance") { - double balance{1000.0}; - double target_balance{1100.0}; - int want{6}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{1000.0}; + const double target_balance{1100.0}; + const int want{6}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Years before desired balance for large start balance") { - double balance{8080.80}; - double target_balance{9090.90}; - int want{5}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{8080.80}; + const double target_balance{9090.90}; + const int want{5}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Years before large difference between start and target balance") { - double balance{2345.67}; - double target_balance{12345.6789}; - int want{85}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{2345.67}; + const double target_balance{12345.6789}; + const int want{85}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Balance is already above target") { - double balance{2345.67}; - double target_balance{2345.0}; - int want{0}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{2345.67}; + const double target_balance{2345.0}; + const int want{0}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Balance is exactly same as target") { - double balance{2345.0}; - double target_balance{2345.0}; - int want{0}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{2345.0}; + const double target_balance{2345.0}; + const int want{0}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } TEST_CASE("Result balance would be exactly same as target") { - double balance{1000.0}; - double target_balance{1032.6827641}; - int want{2}; - REQUIRE(years_until_desired_balance(balance, target_balance) == want); + const double balance{1000.0}; + const double target_balance{1032.6827641}; + const int want{2}; + REQUIRE(interest_is_interesting::years_until_desired_balance( + balance, target_balance) == want); } #endif diff --git a/cpp/interest-is-interesting/run-tests-cpp.txt b/cpp/interest-is-interesting/run-tests-cpp.txt index d88a6358..586c6231 100644 --- a/cpp/interest-is-interesting/run-tests-cpp.txt +++ b/cpp/interest-is-interesting/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.008s +real 0m0.014s user 0m0.002s -sys 0m0.005s +sys 0m0.011s =============================================================================== @@ -36,8 +36,9 @@ make[2]: Entering directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/inte make[3]: Entering directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/build' make[3]: Leaving directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/build' make[3]: Entering directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/build' -[ 33%] Building CXX object CMakeFiles/interest-is-interesting.dir/interest_is_interesting_test.cpp.o -[ 66%] Building CXX object CMakeFiles/interest-is-interesting.dir/test/tests-main.cpp.o +[ 25%] Building CXX object CMakeFiles/interest-is-interesting.dir/interest_is_interesting_test.cpp.o +[ 50%] Building CXX object CMakeFiles/interest-is-interesting.dir/interest_is_interesting.cpp.o +[ 75%] Building CXX object CMakeFiles/interest-is-interesting.dir/test/tests-main.cpp.o [100%] Linking CXX executable interest-is-interesting make[3]: Leaving directory '/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/build' [100%] Built target interest-is-interesting @@ -75,19 +76,19 @@ test/catch.hpp 45 34 75% 1642-1643,2227 TOTAL 229 218 95% ------------------------------------------------------------------------------ lines: 95.2% (218 out of 229) -branches: 35.7% (168 out of 470) +branches: 37.4% (199 out of 532) -real 0m9.602s -user 0m8.751s -sys 0m0.850s +real 0m9.636s +user 0m8.932s +sys 0m0.703s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.176s -user 0m0.135s -sys 0m0.042s +real 0m0.173s +user 0m0.124s +sys 0m0.050s =============================================================================== @@ -96,15 +97,15 @@ CMakeLists.txt ============== CMakeLists.txt:15,06: [C0103] Invalid directory variable name "exercise_cpp" doesn't match `[A-Z][0-9A-Z_]+|_[0-9a-z_]+` CMakeLists.txt:17,06: [C0103] Invalid directory variable name "exercise_cpp" doesn't match `[A-Z][0-9A-Z_]+|_[0-9a-z_]+` -CMakeLists.txt:52,71: [C0307] Bad indentation: +CMakeLists.txt:54,71: [C0307] Bad indentation: ) - ^----BodyNode: 1:0->IfBlockNode: 46:0->BodyNode: 46:52->StatementNode: 47:2->TreeNode: 52:71 + ^----BodyNode: 1:0->IfBlockNode: 48:0->BodyNode: 48:52->StatementNode: 49:2->TreeNode: 54:71 -CMakeLists.txt:63,70: [C0307] Bad indentation: +CMakeLists.txt:65,70: [C0307] Bad indentation: ) - ^----BodyNode: 1:0->IfBlockNode: 61:0->BodyNode: 61:11->StatementNode: 62:2->TreeNode: 63:70 + ^----BodyNode: 1:0->IfBlockNode: 63:0->BodyNode: 63:11->StatementNode: 64:2->TreeNode: 65:70 -CMakeLists.txt:68,02: [C0113] Missing COMMENT in statement which allows it +CMakeLists.txt:70,02: [C0113] Missing COMMENT in statement which allows it Summary ======= @@ -113,59 +114,50 @@ found lint: Convention: 5 -real 0m0.172s -user 0m0.098s -sys 0m0.071s +real 0m0.155s +user 0m0.109s +sys 0m0.046s =============================================================================== Running: clang-format-16 -style=file -i ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp -real 0m0.029s -user 0m0.012s -sys 0m0.017s +real 0m0.023s +user 0m0.009s +sys 0m0.014s =============================================================================== Running: ../../.github/citools/cpp/clang-check -clang-check-16 --analyze ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp +clang-check-16 --analyze ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp ./interest_is_interesting.hpp -real 0m0.590s -user 0m0.529s -sys 0m0.060s +real 0m0.565s +user 0m0.519s +sys 0m0.046s -real 0m0.592s -user 0m0.529s -sys 0m0.062s +real 0m0.567s +user 0m0.519s +sys 0m0.048s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -35381 warnings generated. -Suppressed 35385 warnings (35378 in non-user code, 7 NOLINT). +8739 warnings generated. +44086 warnings generated. +52825 warnings generated. +Suppressed 52831 warnings (52825 in non-user code, 6 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m5.396s -user 0m5.330s -sys 0m0.066s -Running: clang-tidy-16 ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting_test.cpp:1:11: warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include] -#include "interest_is_interesting.cpp" - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting_test.cpp:9:5: warning: variable 'balance' of type 'double' can be declared 'const' [misc-const-correctness] - double balance{0}; - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/interest-is-interesting/interest_is_interesting_test.cpp:10:5: warning: variable 'want' of type 'double' can be declared 'const' [misc-const-correctness] - double want{0.5}; - ^ - const - - -real 0m5.399s -user 0m5.330s -sys 0m0.070s +real 0m8.699s +user 0m8.620s +sys 0m0.078s +Running: clang-tidy-16 ./interest_is_interesting.cpp ./interest_is_interesting_test.cpp ./interest_is_interesting.hpp + + +real 0m8.701s +user 0m8.621s +sys 0m0.081s =============================================================================== From 0ed0fbbc4df58acf9a87b7c51b77871e4272cf49 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 17 Jul 2023 11:01:50 -0700 Subject: [PATCH 07/16] c++/lasagna: lint clean up --- cpp/lasagna/lasagna.cpp | 6 ++- cpp/lasagna/lasagna_test.cpp | 56 ++++++++++++------------- cpp/lasagna/run-tests-cpp.txt | 79 +++++++++++++---------------------- 3 files changed, 62 insertions(+), 79 deletions(-) diff --git a/cpp/lasagna/lasagna.cpp b/cpp/lasagna/lasagna.cpp index 611a31c7..8f5ff4a8 100644 --- a/cpp/lasagna/lasagna.cpp +++ b/cpp/lasagna/lasagna.cpp @@ -1,5 +1,7 @@ -#define OVEN_TIME (40) -#define TIME_PER_LAYER (2) +enum { + OVEN_TIME = 40, + TIME_PER_LAYER = 2, +}; // ovenTime returns the amount in minutes that the lasagna should stay in the // oven. diff --git a/cpp/lasagna/lasagna_test.cpp b/cpp/lasagna/lasagna_test.cpp index d1c98f7a..865c980e 100644 --- a/cpp/lasagna/lasagna_test.cpp +++ b/cpp/lasagna/lasagna_test.cpp @@ -8,65 +8,65 @@ using namespace std; TEST_CASE("Preparation time correct") { - int actual = 40; - int expected = ovenTime(); + const int actual = 40; + const int expected = ovenTime(); REQUIRE(expected == actual); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("Correct for six layers") { - int timePerLayer = 2; - int layers = 6; - int actual = preparationTime(layers); - int expected{timePerLayer * layers}; + const int timePerLayer = 2; + const int layers = 6; + const int actual = preparationTime(layers); + const int expected{timePerLayer * layers}; REQUIRE(expected == actual); } TEST_CASE("Correct for 11 layers") { - int timePerLayer = 2; - int layers = 11; - int actual = preparationTime(layers); - int expected{timePerLayer * layers}; + const int timePerLayer = 2; + const int layers = 11; + const int actual = preparationTime(layers); + const int expected{timePerLayer * layers}; REQUIRE(expected == actual); } TEST_CASE("Fresh in the oven") { - int timeSpendInOven = 0; - int neededBakeTime = 40; - int actual = remainingOvenTime(timeSpendInOven); - int expected{neededBakeTime - timeSpendInOven}; + const int timeSpendInOven = 0; + const int neededBakeTime = 40; + const int actual = remainingOvenTime(timeSpendInOven); + const int expected{neededBakeTime - timeSpendInOven}; REQUIRE(expected == actual); } TEST_CASE("Halfway done") { - int timeSpendInOven = 20; - int neededBakeTime = 40; - int actual = remainingOvenTime(timeSpendInOven); - int expected{neededBakeTime - timeSpendInOven}; + const int timeSpendInOven = 20; + const int neededBakeTime = 40; + const int actual = remainingOvenTime(timeSpendInOven); + const int expected{neededBakeTime - timeSpendInOven}; REQUIRE(expected == actual); } TEST_CASE("Fresh in the oven, 12 layers!") { - int timeSpendInOven = 0; - int timePerLayer = 2; - int layers = 11; - int actual = elapsedTime(layers, timeSpendInOven); - int expected{timePerLayer * layers + timeSpendInOven}; + const int timeSpendInOven = 0; + const int timePerLayer = 2; + const int layers = 11; + const int actual = elapsedTime(layers, timeSpendInOven); + const int expected{timePerLayer * layers + timeSpendInOven}; REQUIRE(expected == actual); } TEST_CASE("One minute left, 5 layers!") { - int timeSpendInOven = 39; - int timePerLayer = 2; - int layers = 5; - int actual = elapsedTime(layers, timeSpendInOven); - int expected{timePerLayer * layers + timeSpendInOven}; + const int timeSpendInOven = 39; + const int timePerLayer = 2; + const int layers = 5; + const int actual = elapsedTime(layers, timeSpendInOven); + const int expected{timePerLayer * layers + timeSpendInOven}; REQUIRE(expected == actual); } diff --git a/cpp/lasagna/run-tests-cpp.txt b/cpp/lasagna/run-tests-cpp.txt index e2a69868..2c652727 100644 --- a/cpp/lasagna/run-tests-cpp.txt +++ b/cpp/lasagna/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.003s -user 0m0.001s -sys 0m0.002s +real 0m0.009s +user 0m0.000s +sys 0m0.009s =============================================================================== @@ -79,17 +79,17 @@ TOTAL 88 83 94% lines: 94.3% (83 out of 88) branches: 34.6% (36 out of 104) -real 0m9.390s -user 0m8.629s -sys 0m0.750s +real 0m9.587s +user 0m8.739s +sys 0m0.824s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.175s -user 0m0.130s -sys 0m0.047s +real 0m0.178s +user 0m0.134s +sys 0m0.046s =============================================================================== @@ -115,70 +115,51 @@ found lint: Convention: 5 -real 0m0.153s -user 0m0.107s -sys 0m0.046s +real 0m0.166s +user 0m0.111s +sys 0m0.055s =============================================================================== Running: clang-format-16 -style=file -i ./lasagna.cpp ./lasagna_test.cpp -real 0m0.022s +real 0m0.024s user 0m0.011s -sys 0m0.011s +sys 0m0.012s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./lasagna.cpp ./lasagna_test.cpp -real 0m0.391s -user 0m0.361s -sys 0m0.030s +real 0m0.396s +user 0m0.356s +sys 0m0.039s -real 0m0.393s -user 0m0.363s -sys 0m0.030s +real 0m0.397s +user 0m0.358s +sys 0m0.040s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -3 warnings generated. -35392 warnings generated. -Suppressed 35391 warnings (35386 in non-user code, 5 NOLINT). +35384 warnings generated. +Suppressed 35388 warnings (35383 in non-user code, 5 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m5.330s -user 0m5.281s -sys 0m0.049s +real 0m5.267s +user 0m5.194s +sys 0m0.072s Running: clang-tidy-16 ./lasagna.cpp ./lasagna_test.cpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna.cpp:1:1: warning: replace macro with enum [modernize-macro-to-enum] -#define OVEN_TIME (40) -^~~~~~~~ - = , -/home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna.cpp:1:9: warning: macro 'OVEN_TIME' defines an integral constant; prefer an enum instead [modernize-macro-to-enum] -#define OVEN_TIME (40) - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna.cpp:2:9: warning: macro 'TIME_PER_LAYER' defines an integral constant; prefer an enum instead [modernize-macro-to-enum] -#define TIME_PER_LAYER (2) - ^ /home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna_test.cpp:1:11: warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include] #include "lasagna.cpp" ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna_test.cpp:11:5: warning: variable 'actual' of type 'int' can be declared 'const' [misc-const-correctness] - int actual = 40; - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/lasagna/lasagna_test.cpp:12:5: warning: variable 'expected' of type 'int' can be declared 'const' [misc-const-correctness] - int expected = ovenTime(); - ^ - const - - -real 0m5.332s -user 0m5.281s -sys 0m0.051s + + +real 0m5.269s +user 0m5.197s +sys 0m0.073s =============================================================================== From f3ab7d6878ceed014c80f87ab47e404a8bebf746 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 17 Jul 2023 11:05:51 -0700 Subject: [PATCH 08/16] c++/last-will: lint clean up --- cpp/last-will/last_will.cpp | 27 ++++++++++-- cpp/last-will/last_will_test.cpp | 2 +- cpp/last-will/run-tests-cpp.txt | 75 ++++++++++++-------------------- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/cpp/last-will/last_will.cpp b/cpp/last-will/last_will.cpp index 6d765eab..3beec5b1 100644 --- a/cpp/last-will/last_will.cpp +++ b/cpp/last-will/last_will.cpp @@ -2,44 +2,65 @@ // Secret knowledge of the Zhang family: namespace zhang { + int bank_number_part(int secret_modifier) { - int zhang_part{8'541}; + const int zhang_part{8'541}; return (zhang_part * secret_modifier) % 10000; } + namespace red { + int code_fragment() { return 512; } + } // namespace red + namespace blue { + int code_fragment() { return 677; } + } // namespace blue + } // namespace zhang // Secret knowledge of the Khan family: namespace khan { + int bank_number_part(int secret_modifier) { - int khan_part{4'142}; + const int khan_part{4'142}; return (khan_part * secret_modifier) % 10000; } + namespace red { + int code_fragment() { return 148; } + } // namespace red + namespace blue { + int code_fragment() { return 875; } } // namespace blue + } // namespace khan // Secret knowledge of the Garcia family: namespace garcia { + int bank_number_part(int secret_modifier) { - int garcia_part{4'023}; + const int garcia_part{4'023}; return (garcia_part * secret_modifier) % 10000; } + namespace red { + int code_fragment() { return 118; } } // namespace red + namespace blue { + int code_fragment() { return 923; } } // namespace blue + } // namespace garcia // Enter your code below diff --git a/cpp/last-will/last_will_test.cpp b/cpp/last-will/last_will_test.cpp index 084ed664..18983557 100644 --- a/cpp/last-will/last_will_test.cpp +++ b/cpp/last-will/last_will_test.cpp @@ -1,6 +1,6 @@ // 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_account_number(int secret_modifier) __attribute__((weak)); int assemble_code() __attribute__((weak)); } // namespace estate_executor diff --git a/cpp/last-will/run-tests-cpp.txt b/cpp/last-will/run-tests-cpp.txt index f3c78d3f..4e4b99e0 100644 --- a/cpp/last-will/run-tests-cpp.txt +++ b/cpp/last-will/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.011s -user 0m0.002s -sys 0m0.009s +real 0m0.004s +user 0m0.000s +sys 0m0.004s =============================================================================== @@ -79,17 +79,17 @@ TOTAL 95 90 94% lines: 94.7% (90 out of 95) branches: 35.4% (87 out of 246) -real 0m8.632s -user 0m7.922s -sys 0m0.706s +real 0m9.632s +user 0m8.644s +sys 0m0.929s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.304s -user 0m0.193s -sys 0m0.085s +real 0m0.180s +user 0m0.130s +sys 0m0.051s =============================================================================== @@ -115,68 +115,51 @@ found lint: Convention: 5 -real 0m0.156s -user 0m0.105s -sys 0m0.051s +real 0m0.299s +user 0m0.227s +sys 0m0.074s =============================================================================== Running: clang-format-16 -style=file -i ./last_will.cpp ./last_will_test.cpp -real 0m0.021s -user 0m0.009s -sys 0m0.011s +real 0m0.034s +user 0m0.019s +sys 0m0.015s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./last_will.cpp ./last_will_test.cpp -real 0m0.398s -user 0m0.358s -sys 0m0.039s +real 0m0.540s +user 0m0.504s +sys 0m0.036s -real 0m0.399s -user 0m0.358s -sys 0m0.041s +real 0m0.542s +user 0m0.504s +sys 0m0.038s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -3 warnings generated. -35406 warnings generated. -Suppressed 35407 warnings (35401 in non-user code, 6 NOLINT). +35399 warnings generated. +Suppressed 35404 warnings (35398 in non-user code, 6 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m5.123s -user 0m5.057s -sys 0m0.065s +real 0m5.723s +user 0m5.647s +sys 0m0.073s Running: clang-tidy-16 ./last_will.cpp ./last_will_test.cpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/last-will/last_will.cpp:6:5: warning: variable 'zhang_part' of type 'int' can be declared 'const' [misc-const-correctness] - int zhang_part{8'541}; - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/last-will/last_will.cpp:20:5: warning: variable 'khan_part' of type 'int' can be declared 'const' [misc-const-correctness] - int khan_part{4'142}; - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/last-will/last_will.cpp:34:5: warning: variable 'garcia_part' of type 'int' can be declared 'const' [misc-const-correctness] - int garcia_part{4'023}; - ^ - const -/home/vpayno/git_vpayno/exercism-workspace/cpp/last-will/last_will_test.cpp:3:32: warning: all parameters should be named in a function [readability-named-parameter] -int assemble_account_number(int) __attribute__((weak)); - ^ - /*secret_modifier*/ /home/vpayno/git_vpayno/exercism-workspace/cpp/last-will/last_will_test.cpp:7:11: warning: suspicious #include of file with '.cpp' extension [bugprone-suspicious-include] #include "last_will.cpp" ^ -real 0m5.125s -user 0m5.059s -sys 0m0.067s +real 0m5.726s +user 0m5.650s +sys 0m0.074s =============================================================================== From 4fed15f912b5bc4767cf8855e1214819e8c101c9 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 17 Jul 2023 12:32:26 -0700 Subject: [PATCH 09/16] c++/reverse-string: lint clean up --- cpp/reverse-string/reverse_string_test.cpp | 2 +- cpp/reverse-string/run-tests-cpp.txt | 88 +++++++++------------- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/cpp/reverse-string/reverse_string_test.cpp b/cpp/reverse-string/reverse_string_test.cpp index 1c8612b2..3fbb3c77 100644 --- a/cpp/reverse-string/reverse_string_test.cpp +++ b/cpp/reverse-string/reverse_string_test.cpp @@ -6,7 +6,7 @@ #endif TEST_CASE("an_empty_string") { - REQUIRE("" == reverse_string::reverse_string("")); + REQUIRE(reverse_string::reverse_string("").empty()); } #if defined(EXERCISM_RUN_ALL_TESTS) diff --git a/cpp/reverse-string/run-tests-cpp.txt b/cpp/reverse-string/run-tests-cpp.txt index 57844f2b..2cb0f183 100644 --- a/cpp/reverse-string/run-tests-cpp.txt +++ b/cpp/reverse-string/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.016s -user 0m0.006s -sys 0m0.010s +real 0m0.014s +user 0m0.002s +sys 0m0.012s =============================================================================== @@ -71,24 +71,24 @@ File Lines Exec Cover Missing ------------------------------------------------------------------------------ reverse_string.cpp 6 6 100% reverse_string_test.cpp 15 15 100% -test/catch.hpp 34 27 79% 1642-1643,1710-1711,2227,2229,2560 +test/catch.hpp 46 37 80% 1642-1643,1710-1711,2227,2229,2301-2302,2560 ------------------------------------------------------------------------------ -TOTAL 55 48 87% +TOTAL 67 58 86% ------------------------------------------------------------------------------ -lines: 87.3% (48 out of 55) -branches: 37.7% (40 out of 106) +lines: 86.6% (58 out of 67) +branches: 37.0% (40 out of 108) -real 0m10.882s -user 0m10.102s -sys 0m0.761s +real 0m9.301s +user 0m8.441s +sys 0m0.858s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.175s -user 0m0.119s -sys 0m0.055s +real 0m0.144s +user 0m0.099s +sys 0m0.045s =============================================================================== @@ -110,66 +110,50 @@ found lint: Convention: 4 -real 0m0.165s -user 0m0.117s -sys 0m0.045s +real 0m0.150s +user 0m0.111s +sys 0m0.039s =============================================================================== Running: clang-format-16 -style=file -i ./reverse_string.cpp ./reverse_string_test.cpp -real 0m0.028s -user 0m0.009s -sys 0m0.019s +real 0m0.021s +user 0m0.010s +sys 0m0.011s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.hpp -real 0m0.738s -user 0m0.693s -sys 0m0.043s +real 0m0.598s +user 0m0.562s +sys 0m0.036s -real 0m0.740s -user 0m0.695s -sys 0m0.043s +real 0m0.600s +user 0m0.563s +sys 0m0.036s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 12523 warnings generated. -47957 warnings generated. -60471 warnings generated. -Suppressed 60474 warnings (60469 in non-user code, 5 NOLINT). +47942 warnings generated. +60456 warnings generated. +Suppressed 60461 warnings (60456 in non-user code, 5 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m8.601s -user 0m8.513s -sys 0m0.080s +real 0m7.613s +user 0m7.534s +sys 0m0.078s Running: clang-tidy-16 ./reverse_string.cpp ./reverse_string_test.cpp ./reverse_string.hpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/reverse_string_test.cpp:9:13: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty] - REQUIRE("" == reverse_string::reverse_string("")); - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - reverse_string::reverse_string("").empty() -/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/test/catch.hpp:17637:90: note: expanded from macro 'REQUIRE' -#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ ) - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/test/catch.hpp:2703:40: note: expanded from macro 'INTERNAL_CATCH_TEST' - CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \ - ^ -/home/vpayno/git_vpayno/exercism-workspace/cpp/reverse-string/test/catch.hpp:165:76: note: expanded from macro 'CATCH_INTERNAL_IGNORE_BUT_WARN' -# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ - ^ -/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h:1002:7: note: method 'basic_string'::empty() defined here - empty() const _GLIBCXX_NOEXCEPT - ^ - - -real 0m8.604s -user 0m8.514s -sys 0m0.083s + + +real 0m7.616s +user 0m7.535s +sys 0m0.081s =============================================================================== From ec448fc5188dcc35504aef360c45bd3ae9b72689 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 17 Jul 2023 12:36:57 -0700 Subject: [PATCH 10/16] c++/vehicle-purchase: lint clean up --- cpp/vehicle-purchase/run-tests-cpp.txt | 75 ++++++++----------- cpp/vehicle-purchase/vehicle_purchase.cpp | 8 +- .../vehicle_purchase_test.cpp | 66 ++++++++-------- 3 files changed, 69 insertions(+), 80 deletions(-) diff --git a/cpp/vehicle-purchase/run-tests-cpp.txt b/cpp/vehicle-purchase/run-tests-cpp.txt index 5fd59f21..9ae26e2d 100644 --- a/cpp/vehicle-purchase/run-tests-cpp.txt +++ b/cpp/vehicle-purchase/run-tests-cpp.txt @@ -6,9 +6,9 @@ Running automated test file(s): Running: make clean rm -rf ./build -real 0m0.011s -user 0m0.004s -sys 0m0.008s +real 0m0.013s +user 0m0.001s +sys 0m0.012s =============================================================================== @@ -78,17 +78,17 @@ TOTAL 156 140 89% lines: 89.7% (140 out of 156) branches: 38.6% (139 out of 360) -real 0m8.324s -user 0m7.492s -sys 0m0.831s +real 0m8.555s +user 0m7.867s +sys 0m0.686s =============================================================================== cmake-format --in-place CMakeLists.txt -real 0m0.139s -user 0m0.095s -sys 0m0.046s +real 0m0.152s +user 0m0.110s +sys 0m0.043s =============================================================================== @@ -110,63 +110,50 @@ found lint: Convention: 4 -real 0m0.164s -user 0m0.107s -sys 0m0.058s +real 0m0.162s +user 0m0.110s +sys 0m0.053s =============================================================================== Running: clang-format-16 -style=file -i ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp -real 0m0.023s +real 0m0.020s user 0m0.009s -sys 0m0.014s +sys 0m0.010s =============================================================================== Running: ../../.github/citools/cpp/clang-check clang-check-16 --analyze ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.hpp -real 0m0.620s -user 0m0.579s -sys 0m0.041s +real 0m0.657s +user 0m0.616s +sys 0m0.040s -real 0m0.622s -user 0m0.579s +real 0m0.658s +user 0m0.616s sys 0m0.042s =============================================================================== Running: ../../.github/citools/cpp/clang-tidy | head -n 100 -15010 warnings generated. -50356 warnings generated. -65355 warnings generated. -Suppressed 65358 warnings (65353 in non-user code, 5 NOLINT). +15009 warnings generated. +50354 warnings generated. +65353 warnings generated. +Suppressed 65359 warnings (65353 in non-user code, 6 NOLINT). Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well. -real 0m9.103s -user 0m9.037s -sys 0m0.063s +real 0m10.193s +user 0m10.117s +sys 0m0.075s Running: clang-tidy-16 ./vehicle_purchase.cpp ./vehicle_purchase_test.cpp ./vehicle_purchase.hpp -/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:31: warning: 2 adjacent parameters of 'calculate_resell_price' of similar type ('double') are easily swapped by mistake [bugprone-easily-swappable-parameters] -double calculate_resell_price(double original_price, double age) { - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:38: note: the first parameter in the range is 'original_price' -double calculate_resell_price(double original_price, double age) { - ^~~~~~~~~~~~~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase.cpp:28:61: note: the last parameter in the range is 'age' -double calculate_resell_price(double original_price, double age) { - ^~~ -/home/vpayno/git_vpayno/exercism-workspace/cpp/vehicle-purchase/vehicle_purchase_test.cpp:10:5: warning: variable 'kind' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness] - std::string kind{"car"}; - ^ - const - - -real 0m9.104s -user 0m9.037s -sys 0m0.066s + + +real 0m10.196s +user 0m10.119s +sys 0m0.076s =============================================================================== diff --git a/cpp/vehicle-purchase/vehicle_purchase.cpp b/cpp/vehicle-purchase/vehicle_purchase.cpp index af9fa7ca..d6057cf9 100644 --- a/cpp/vehicle-purchase/vehicle_purchase.cpp +++ b/cpp/vehicle-purchase/vehicle_purchase.cpp @@ -4,13 +4,14 @@ namespace vehicle_purchase { // needs_license determines whether a license is needed to drive a type of // vehicle. Only "car" and "truck" require a license. -bool needs_license(std::string kind) { +bool needs_license(const std::string kind) { return kind == "truck" || kind == "car"; } // choose_vehicle recommends a vehicle for selection. It always recommends the // vehicle that comes first in lexicographical order. -std::string choose_vehicle(std::string option1, std::string option2) { +std::string choose_vehicle(const std::string option1, + const std::string option2) { std::string choice; const std::string comment = " is clearly the better choice."; @@ -25,7 +26,8 @@ std::string choose_vehicle(std::string option1, std::string option2) { // calculate_resell_price calculates how much a vehicle can resell for at a // certain age. -double calculate_resell_price(double original_price, double age) { +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) +double calculate_resell_price(const double original_price, const double age) { double offset{0.50}; if (age < 3) { diff --git a/cpp/vehicle-purchase/vehicle_purchase_test.cpp b/cpp/vehicle-purchase/vehicle_purchase_test.cpp index 4517f17c..bb6046a5 100644 --- a/cpp/vehicle-purchase/vehicle_purchase_test.cpp +++ b/cpp/vehicle-purchase/vehicle_purchase_test.cpp @@ -7,99 +7,99 @@ #endif TEST_CASE("need a license for a car") { - std::string kind{"car"}; + const std::string kind{"car"}; REQUIRE(vehicle_purchase::needs_license(kind)); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("need a license for a truck") { - std::string kind{"truck"}; + const std::string kind{"truck"}; REQUIRE(vehicle_purchase::needs_license(kind)); } TEST_CASE("does not need a license for a bike") { - std::string kind{"bike"}; + const std::string kind{"bike"}; REQUIRE_FALSE(vehicle_purchase::needs_license(kind)); } TEST_CASE("does not need a license for a stroller") { - std::string kind{"stroller"}; + const std::string kind{"stroller"}; REQUIRE_FALSE(vehicle_purchase::needs_license(kind)); } TEST_CASE("does not need a license for a e-scooter") { - std::string kind{"e-scooter"}; + const std::string kind{"e-scooter"}; REQUIRE_FALSE(vehicle_purchase::needs_license(kind)); } TEST_CASE("chooses Bugatti over Ford") { - std::string choice1{"Bugatti Veyron"}; - std::string choice2{"Ford Pinto"}; + const std::string choice1{"Bugatti Veyron"}; + const std::string choice2{"Ford Pinto"}; REQUIRE(vehicle_purchase::choose_vehicle(choice1, choice2) == "Bugatti Veyron is clearly the better choice."); } TEST_CASE("chooses Chery over Kia") { - std::string choice1{"Chery EQ"}; - std::string choice2{"Kia Niro Elektro"}; + const std::string choice1{"Chery EQ"}; + const std::string choice2{"Kia Niro Elektro"}; REQUIRE(vehicle_purchase::choose_vehicle(choice1, choice2) == "Chery EQ is clearly the better choice."); } TEST_CASE("chooses Ford Focus over Ford Pinto") { - std::string choice1{"Ford Focus"}; - std::string choice2{"Ford Pinto"}; + const std::string choice1{"Ford Focus"}; + const std::string choice2{"Ford Pinto"}; REQUIRE(vehicle_purchase::choose_vehicle(choice1, choice2) == "Ford Focus is clearly the better choice."); } TEST_CASE("chooses 2018 over 2020") { - std::string choice1{"2018 Bergamont City"}; - std::string choice2{"2020 Gazelle Medeo"}; + const std::string choice1{"2018 Bergamont City"}; + const std::string choice2{"2020 Gazelle Medeo"}; REQUIRE(vehicle_purchase::choose_vehicle(choice1, choice2) == "2018 Bergamont City is clearly the better choice."); } TEST_CASE("chooses Bugatti over ford") { - std::string choice1{"Bugatti Veyron"}; - std::string choice2{"ford"}; + const std::string choice1{"Bugatti Veyron"}; + const std::string choice2{"ford"}; REQUIRE(vehicle_purchase::choose_vehicle(choice1, choice2) == "Bugatti Veyron is clearly the better choice."); } TEST_CASE("price is reduced to 80% for age of 2") { - double original_price{40000}; - double age{2}; - double expected{32000}; + const double original_price{40000}; + const double age{2}; + const double expected{32000}; REQUIRE(vehicle_purchase::calculate_resell_price(original_price, age) == expected); } TEST_CASE("price is reduced to 80% for age of 2.5") { - double original_price{40000}; - double age{2.5}; - double expected{32000}; + const double original_price{40000}; + const double age{2.5}; + const double expected{32000}; REQUIRE(vehicle_purchase::calculate_resell_price(original_price, age) == expected); } TEST_CASE("price is reduced to 70% for age 7") { - double original_price{40000}; - double age{7}; - double expected{28000}; + const double original_price{40000}; + const double age{7}; + const double expected{28000}; REQUIRE(vehicle_purchase::calculate_resell_price(original_price, age) == expected); } TEST_CASE("price is reduced to 50% for age 10") { - double original_price{25000}; - double age{10}; - double expected{12500}; + const double original_price{25000}; + const double age{10}; + const double expected{12500}; REQUIRE(vehicle_purchase::calculate_resell_price(original_price, age) == expected); } TEST_CASE("price is reduced to 50% for age 11") { - double original_price{50000}; - double age{11}; - double expected{25000}; + const double original_price{50000}; + const double age{11}; + const double expected{25000}; REQUIRE(vehicle_purchase::calculate_resell_price(original_price, age) == expected); } TEST_CASE("float price is reduced to 70% for age 8,") { - double original_price{39000.000001}; - double age{8}; - double expected{27300.0000007}; + const double original_price{39000.000001}; + const double age{8}; + const double expected{27300.0000007}; REQUIRE_THAT(vehicle_purchase::calculate_resell_price(original_price, age), Catch::Matchers::WithinRel(expected, 0.001)); } From 99c8c3d2691a71885d9b203f9735bc186e019588 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 17 Jul 2023 12:40:26 -0700 Subject: [PATCH 11/16] c++/difference-of-squares: download exercise --- .../.exercism/config.json | 30 + .../.exercism/metadata.json | 1 + cpp/difference-of-squares/CMakeLists.txt | 64 + cpp/difference-of-squares/HELP.md | 55 + cpp/difference-of-squares/README.md | 41 + .../difference_of_squares.cpp | 5 + .../difference_of_squares.h | 8 + .../difference_of_squares_test.cpp | 29 + cpp/difference-of-squares/test/catch.hpp | 17937 ++++++++++++++++ cpp/difference-of-squares/test/tests-main.cpp | 2 + 10 files changed, 18172 insertions(+) create mode 100644 cpp/difference-of-squares/.exercism/config.json create mode 100644 cpp/difference-of-squares/.exercism/metadata.json create mode 100644 cpp/difference-of-squares/CMakeLists.txt create mode 100644 cpp/difference-of-squares/HELP.md create mode 100644 cpp/difference-of-squares/README.md create mode 100644 cpp/difference-of-squares/difference_of_squares.cpp create mode 100644 cpp/difference-of-squares/difference_of_squares.h create mode 100644 cpp/difference-of-squares/difference_of_squares_test.cpp create mode 100644 cpp/difference-of-squares/test/catch.hpp create mode 100644 cpp/difference-of-squares/test/tests-main.cpp diff --git a/cpp/difference-of-squares/.exercism/config.json b/cpp/difference-of-squares/.exercism/config.json new file mode 100644 index 00000000..12c5c1e8 --- /dev/null +++ b/cpp/difference-of-squares/.exercism/config.json @@ -0,0 +1,30 @@ +{ + "authors": [ + "LegalizeAdulthood" + ], + "contributors": [ + "cyborgsphinx", + "elyashiv", + "jackhughesweb", + "KevinWMatthews", + "kytrinyx", + "patricksjackson", + "Scientifica96" + ], + "files": { + "solution": [ + "difference_of_squares.cpp", + "difference_of_squares.h" + ], + "test": [ + "difference_of_squares_test.cpp" + ], + "example": [ + ".meta/example.cpp", + ".meta/example.h" + ] + }, + "blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.", + "source": "Problem 6 at Project Euler", + "source_url": "http://projecteuler.net/problem=6" +} diff --git a/cpp/difference-of-squares/.exercism/metadata.json b/cpp/difference-of-squares/.exercism/metadata.json new file mode 100644 index 00000000..7cb7f4ac --- /dev/null +++ b/cpp/difference-of-squares/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"cpp","exercise":"difference-of-squares","id":"1d6ee9dc443a4708a1986d9c1d94f29d","url":"https://exercism.org/tracks/cpp/exercises/difference-of-squares","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/cpp/difference-of-squares/CMakeLists.txt b/cpp/difference-of-squares/CMakeLists.txt new file mode 100644 index 00000000..3b0589fd --- /dev/null +++ b/cpp/difference-of-squares/CMakeLists.txt @@ -0,0 +1,64 @@ +# Get the exercise name from the current directory +get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME) + +# Basic CMake project +cmake_minimum_required(VERSION 3.5.1) + +# Name the project after the exercise +project(${exercise} CXX) + +# Get a source filename from the exercise name by replacing -'s with _'s +string(REPLACE "-" "_" file ${exercise}) + +# Implementation could be only a header +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp) + set(exercise_cpp ${file}.cpp) +else() + set(exercise_cpp "") +endif() + +# Use the common Catch library? +if(EXERCISM_COMMON_CATCH) + # For Exercism track development only + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $) +elseif(EXERCISM_TEST_SUITE) + # The Exercism test suite is being run, the Docker image already + # includes a pre-built version of Catch. + find_package(Catch2 REQUIRED) + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h) + target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain) + # When Catch is installed system wide we need to include a different + # header, we need this define to use the correct one. + target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE) +else() + # Build executable from sources and headers + add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp) +endif() + +set_target_properties(${exercise} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED OFF + CXX_EXTENSIONS OFF +) + +set(CMAKE_BUILD_TYPE Debug) + +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)") + set_target_properties(${exercise} PROPERTIES + COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror" + ) +endif() + +# Configure to run all the tests? +if(${EXERCISM_RUN_ALL_TESTS}) + target_compile_definitions(${exercise} PRIVATE EXERCISM_RUN_ALL_TESTS) +endif() + +# Tell MSVC not to warn us about unchecked iterators in debug builds +if(${MSVC}) + set_target_properties(${exercise} PROPERTIES + COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS) +endif() + +# Run the tests on every build +add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise}) diff --git a/cpp/difference-of-squares/HELP.md b/cpp/difference-of-squares/HELP.md new file mode 100644 index 00000000..47e4317f --- /dev/null +++ b/cpp/difference-of-squares/HELP.md @@ -0,0 +1,55 @@ +# Help + +## Running the tests + +Running the tests involves running `cmake -G` and then using the build command appropriate for your platform. +Detailed instructions on how to do this can be found on the [Running the Tests](https://exercism.io/tracks/cpp/tests) page for C++ on exercism.io. + +## Passing the Tests + +Get the first test compiling, linking and passing by following the [three +rules of test-driven development](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd). +Create just enough structure by declaring namespaces, functions, classes, +etc., to satisfy any compiler errors and get the test to fail. Then write +just enough code to get the test to pass. Once you've done that, +uncomment the next test by moving the following line past the next test. + +```C++ +#if defined(EXERCISM_RUN_ALL_TESTS) +``` + +This may result in compile errors as new constructs may be invoked that +you haven't yet declared or defined. Again, fix the compile errors minimally +to get a failing test, then change the code minimally to pass the test, +refactor your implementation for readability and expressiveness and then +go on to the next test. + +Try to use standard C++11 facilities in preference to writing your own +low-level algorithms or facilities by hand. + +## Submitting your solution + +You can submit your solution using the `exercism submit difference_of_squares.cpp difference_of_squares.h` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [C++ track's documentation](https://exercism.org/docs/tracks/cpp) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [`c++-faq` tag on StackOverflow](https://stackoverflow.com/tags/c%2b%2b-faq/info) +- [C++ FAQ from isocpp.com](https://isocpp.org/faq) +- [CppReference](http://en.cppreference.com/) is a wiki reference to the C++ language and standard library +- [C traps and pitfalls](http://www.slideshare.net/LegalizeAdulthood/c-traps-and-pitfalls-for-c-programmers) is useful if you are new to C++, but have programmed in C \ No newline at end of file diff --git a/cpp/difference-of-squares/README.md b/cpp/difference-of-squares/README.md new file mode 100644 index 00000000..08d31b93 --- /dev/null +++ b/cpp/difference-of-squares/README.md @@ -0,0 +1,41 @@ +# Difference of Squares + +Welcome to Difference of Squares on Exercism's C++ Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. + +The square of the sum of the first ten natural numbers is +(1 + 2 + ... + 10)² = 55² = 3025. + +The sum of the squares of the first ten natural numbers is +1² + 2² + ... + 10² = 385. + +Hence the difference between the square of the sum of the first +ten natural numbers and the sum of the squares of the first ten +natural numbers is 3025 - 385 = 2640. + +You are not expected to discover an efficient solution to this yourself from first principles; research is allowed, indeed, encouraged. +Finding the best algorithm for the problem is a key skill in software engineering. + +## Source + +### Created by + +- @LegalizeAdulthood + +### Contributed to by + +- @cyborgsphinx +- @elyashiv +- @jackhughesweb +- @KevinWMatthews +- @kytrinyx +- @patricksjackson +- @Scientifica96 + +### Based on + +Problem 6 at Project Euler - http://projecteuler.net/problem=6 \ No newline at end of file diff --git a/cpp/difference-of-squares/difference_of_squares.cpp b/cpp/difference-of-squares/difference_of_squares.cpp new file mode 100644 index 00000000..ae1287eb --- /dev/null +++ b/cpp/difference-of-squares/difference_of_squares.cpp @@ -0,0 +1,5 @@ +#include "difference_of_squares.h" + +namespace difference_of_squares { + +} // namespace difference_of_squares diff --git a/cpp/difference-of-squares/difference_of_squares.h b/cpp/difference-of-squares/difference_of_squares.h new file mode 100644 index 00000000..1196425d --- /dev/null +++ b/cpp/difference-of-squares/difference_of_squares.h @@ -0,0 +1,8 @@ +#if !defined(DIFFERENCE_OF_SQUARES_H) +#define DIFFERENCE_OF_SQUARES_H + +namespace difference_of_squares { + +} // namespace difference_of_squares + +#endif // DIFFERENCE_OF_SQUARES_H \ No newline at end of file diff --git a/cpp/difference-of-squares/difference_of_squares_test.cpp b/cpp/difference-of-squares/difference_of_squares_test.cpp new file mode 100644 index 00000000..e3a882a8 --- /dev/null +++ b/cpp/difference-of-squares/difference_of_squares_test.cpp @@ -0,0 +1,29 @@ +#include "difference_of_squares.h" +#ifdef EXERCISM_TEST_SUITE +#include +#else +#include "test/catch.hpp" +#endif + +TEST_CASE("up_to_5") +{ + REQUIRE(225 == difference_of_squares::square_of_sum(5)); + REQUIRE(55 == difference_of_squares::sum_of_squares(5)); + REQUIRE(170 == difference_of_squares::difference(5)); +} + +#if defined(EXERCISM_RUN_ALL_TESTS) +TEST_CASE("up_to_10") +{ + REQUIRE(3025 == difference_of_squares::square_of_sum(10)); + REQUIRE(385 == difference_of_squares::sum_of_squares(10)); + REQUIRE(2640 == difference_of_squares::difference(10)); +} + +TEST_CASE("up_to_100") +{ + REQUIRE(25502500 == difference_of_squares::square_of_sum(100)); + REQUIRE(338350 == difference_of_squares::sum_of_squares(100)); + REQUIRE(25164150 == difference_of_squares::difference(100)); +} +#endif diff --git a/cpp/difference-of-squares/test/catch.hpp b/cpp/difference-of-squares/test/catch.hpp new file mode 100644 index 00000000..36eaeb27 --- /dev/null +++ b/cpp/difference-of-squares/test/catch.hpp @@ -0,0 +1,17937 @@ +/* + * Catch v2.13.6 + * Generated: 2021-04-16 18:23:38.044268 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2021 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 13 +#define CATCH_VERSION_PATCH 6 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +// See e.g.: +// https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html +#ifdef __APPLE__ +# include +# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \ + (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1) +# define CATCH_PLATFORM_MAC +# elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1) +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER +# endif + +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +// Only GCC compiler should be used in this block, so other compilers trying to +// mask themselves as GCC should be ignored. +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif + +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug +// which results in calls to destructors being emitted for each temporary, +// without a matching initialization. In practice, this can result in something +// like `std::string::~string` being called on an uninitialized value. +// +// For example, this code will likely segfault under IBM XL: +// ``` +// REQUIRE(std::string("12") + "34" == "1234") +// ``` +// +// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented. +# if !defined(__ibmxl__) && !defined(__CUDACC__) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */ +# endif + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#if defined(_MSC_VER) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(__clang__) // Handle Clang masquerading for msvc +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED +#endif + +//////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif + +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # include + # if __cpp_lib_byte > 0 + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) +#else +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) +#endif + +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; + + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include +#include + +namespace Catch { + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { + public: + using size_type = std::size_t; + using const_iterator = const char*; + + private: + static constexpr char const* const s_empty = ""; + + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; + + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + explicit operator std::string() const { + return std::string(m_start, m_size); + } + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } + + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } + + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } + + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; + + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; + + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; + + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } + }; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch + +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); +} + +// end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template