diff --git a/exercises/concept/doctor-data/doctor_data.h b/exercises/concept/doctor-data/doctor_data.h index d4ea27b06..54aa69087 100644 --- a/exercises/concept/doctor-data/doctor_data.h +++ b/exercises/concept/doctor-data/doctor_data.h @@ -1,3 +1,8 @@ // ERROR: FILE CORRUPTED. Please supply valid C++ Code. -hp1,üapöhp2ö%Äcountöiöma1,öhp2ö%Älawöhp3öö/önextöstepö%Ädacöiöml1ö%Älawö7ö%Ädacöiömb1ö%Ärandomöö%Äscrö9sö%Äsirö9sö%Äxctöhr1ö%Äaddöiömx1ö%Ädacöiömx1ö%Äswapö%Äaddöiömy1ö%Ädacöiömy1ö%Ärandomö%Äscrö9sö%Äsirö9sö%Äxctöhr2ö%Ädacöiömdyö%Ädioöiömdxö%Äsetupö.hpt,3ö%Älacöranö%Ädacöiömth +hp1, üapöhp2ö % Äcountöiöma1, + öhp2ö % Älawöhp3öö / önextöstepö % Ädacöiöml1ö % Älawö7ö % Ädacöiömb1ö % + Ärandomöö % Äscrö9sö % Äsirö9sö % Äxctöhr1ö % Äaddöiömx1ö % + Ädacöiömx1ö % Äswapö % Äaddöiömy1ö % Ädacöiömy1ö % Ärandomö % Äscrö9sö % + Äsirö9sö % Äxctöhr2ö % Ädacöiömdyö % Ädioöiömdxö % Äsetupö.hpt, + 3ö % Älacöranö % Ädacöiömth diff --git a/exercises/concept/election-day/.meta/exemplar.cpp b/exercises/concept/election-day/.meta/exemplar.cpp index e1202866b..a630b57c2 100644 --- a/exercises/concept/election-day/.meta/exemplar.cpp +++ b/exercises/concept/election-day/.meta/exemplar.cpp @@ -31,7 +31,7 @@ void increment_vote_count(ElectionResult& result, int votes) { ElectionResult& determine_result(std::vector& count) { int winner_idx = 0; for (int i{}; i < count.size(); ++i) { - if(count.at(i).votes > count.at(winner_idx).votes) { + if (count.at(i).votes > count.at(winner_idx).votes) { winner_idx = i; } } diff --git a/exercises/concept/election-day/election_day.cpp b/exercises/concept/election-day/election_day.cpp index 67ab88890..01af92991 100644 --- a/exercises/concept/election-day/election_day.cpp +++ b/exercises/concept/election-day/election_day.cpp @@ -16,13 +16,11 @@ struct ElectionResult { // vote_count takes a reference to an `ElectionResult` as an argument and will // return the number of votes in the `ElectionResult. - // TODO: Task 2 // increment_vote_count takes a reference to an `ElectionResult` as an argument // and a number of votes (int), and will increment the `ElectionResult` by that // number of votes. - // TODO: Task 3 // determine_result receives the reference to a final_count and returns a // reference to the `ElectionResult` of the new president. It also changes the @@ -30,5 +28,4 @@ struct ElectionResult { // in the form of a `reference` to `std::vector`, a vector with // `ElectionResults` of all the participating candidates. - } // namespace election \ No newline at end of file diff --git a/exercises/concept/election-day/election_day_test.cpp b/exercises/concept/election-day/election_day_test.cpp index ce22962d4..b6b060498 100644 --- a/exercises/concept/election-day/election_day_test.cpp +++ b/exercises/concept/election-day/election_day_test.cpp @@ -63,7 +63,6 @@ TEST_CASE("Presidency, two candidates", "[task_3]") { REQUIRE(result.name == expected); } - TEST_CASE("Presidency, several candidates", "[task_3]") { ElectionResult option1{"David", 11}; ElectionResult option2{"Shaw", 12}; diff --git a/exercises/concept/ellens-alien-game/ellens_alien_game_test.cpp b/exercises/concept/ellens-alien-game/ellens_alien_game_test.cpp index e1b719074..c1bdbfdff 100644 --- a/exercises/concept/ellens-alien-game/ellens_alien_game_test.cpp +++ b/exercises/concept/ellens-alien-game/ellens_alien_game_test.cpp @@ -32,7 +32,9 @@ TEST_CASE("Alien is always hit", "[task_2]") { REQUIRE(alien.hit()); } -TEST_CASE("Alien is alive while health is greater than 0 and stays dead afterwards", "[task_3]") { +TEST_CASE( + "Alien is alive while health is greater than 0 and stays dead afterwards", + "[task_3]") { Alien alien{2, 54}; REQUIRE(alien.is_alive()); alien.hit(); diff --git a/exercises/concept/freelancer-rates/freelancer_rates_test.cpp b/exercises/concept/freelancer-rates/freelancer_rates_test.cpp index 857af4e83..a08fa7636 100644 --- a/exercises/concept/freelancer-rates/freelancer_rates_test.cpp +++ b/exercises/concept/freelancer-rates/freelancer_rates_test.cpp @@ -7,15 +7,22 @@ using namespace std; -TEST_CASE("it's the hourly_rate times 8", "[task_1]") { REQUIRE(daily_rate(50) == 400.0); } +TEST_CASE("it's the hourly_rate times 8", "[task_1]") { + REQUIRE(daily_rate(50) == 400.0); +} #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("it always returns a float", "[task_1]") { REQUIRE(daily_rate(60) == 480.0); } +TEST_CASE("it always returns a float", "[task_1]") { + REQUIRE(daily_rate(60) == 480.0); +} -TEST_CASE("it does not round", "[task_1]") { REQUIRE(daily_rate(55.1) == 440.8); } +TEST_CASE("it does not round", "[task_1]") { + REQUIRE(daily_rate(55.1) == 440.8); +} -TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", "[task_2]") { +TEST_CASE("a discount of 10 percent leaves 90 percent of the original price", + "[task_2]") { REQUIRE(apply_discount(140.0, 10) == 126.0); } diff --git a/exercises/concept/interest-is-interesting/interest_is_interesting_test.cpp b/exercises/concept/interest-is-interesting/interest_is_interesting_test.cpp index 55f289b93..646c875ae 100644 --- a/exercises/concept/interest-is-interesting/interest_is_interesting_test.cpp +++ b/exercises/concept/interest-is-interesting/interest_is_interesting_test.cpp @@ -8,7 +8,8 @@ TEST_CASE("Minimal first interest rate", "[task_1]") { double balance{0}; double want{0.5}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } #if defined(EXERCISM_RUN_ALL_TESTS) @@ -16,136 +17,164 @@ TEST_CASE("Minimal first interest rate", "[task_1]") { TEST_CASE("Tiny first interest rate", "[task_1]") { double balance{0.000001}; double want{0.5}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Maximum first interest rate", "[task_1]") { double balance{999.9999}; double want{0.5}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Minimal second interest rate", "[task_1]") { double balance{1000.0}; double want{1.621}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Tiny second interest rate", "[task_1]") { double balance{1000.0001}; double want{1.621}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Maximum second interest rate", "[task_1]") { double balance{4999.9990}; double want{1.621}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Minimal third interest rate", "[task_1]") { double balance{5000.0000}; double want{2.475}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Tiny third interest rate", "[task_1]") { double balance{5000.0001}; double want{2.475}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Large third interest rate", "[task_1]") { double balance{5639998.742909}; double want{2.475}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on minimal negative balance", "[task_1]") { double balance{-0.000001}; double want{3.213}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on small negative balance", "[task_1]") { double balance{-0.123}; double want{3.213}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on regular negative balance", "[task_1]") { double balance{-300.0}; double want{3.213}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Rate on large negative balance", "[task_1]") { double balance{-152964.231}; double want{3.213}; - REQUIRE_THAT(interest_rate(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(interest_rate(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on negative balance", "[task_2]") { double balance{-10000.0}; double want{-321.3}; - REQUIRE_THAT(yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(yearly_interest(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on small balance", "[task_2]") { double balance{555.43}; double want{2.77715}; - REQUIRE_THAT(yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(yearly_interest(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on medium balance", "[task_2]") { double balance{4999.99}; double want{81.0498379}; - REQUIRE_THAT(yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(yearly_interest(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Interest on large balance", "[task_2]") { double balance{34600.80}; double want{856.3698}; - REQUIRE_THAT(yearly_interest(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(yearly_interest(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for empty start balance", "[task_3]") { double balance{0.0}; double want{0.0000}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } -TEST_CASE("Annual balance update for small positive start balance", "[task_3]") { +TEST_CASE("Annual balance update for small positive start balance", + "[task_3]") { double balance{0.000001}; double want{0.000001005}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } -TEST_CASE("Annual balance update for average positive start balance", "[task_3]") { +TEST_CASE("Annual balance update for average positive start balance", + "[task_3]") { double balance{1000.0}; double want{1016.210000}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } -TEST_CASE("Annual balance update for large positive start balance", "[task_3]") { +TEST_CASE("Annual balance update for large positive start balance", + "[task_3]") { double balance{1000.2001}; double want{1016.413343621}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Annual balance update for huge positive start balance", "[task_3]") { double balance{898124017.826243404425}; double want{920352587.2674429417}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } -TEST_CASE("Annual balance update for small negative start balance", "[task_3]") { +TEST_CASE("Annual balance update for small negative start balance", + "[task_3]") { double balance{-0.123}; double want{-0.12695199}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } -TEST_CASE("Annual balance update for large negative start balance", "[task_3]") { +TEST_CASE("Annual balance update for large negative start balance", + "[task_3]") { double balance{-152964.231}; double want{-157878.97174203}; - REQUIRE_THAT(annual_balance_update(balance), Catch::Matchers::WithinRel(want, 0.000001)); + REQUIRE_THAT(annual_balance_update(balance), + Catch::Matchers::WithinRel(want, 0.000001)); } TEST_CASE("Years before desired balance for small start balance", "[task_4]") { @@ -154,7 +183,8 @@ TEST_CASE("Years before desired balance for small start balance", "[task_4]") { int want{47}; REQUIRE(years_until_desired_balance(balance, target_balance) == want); } -TEST_CASE("Years before desired balance for average start balance", "[task_4]") { +TEST_CASE("Years before desired balance for average start balance", + "[task_4]") { double balance{1000.0}; double target_balance{1100.0}; int want{6}; @@ -166,7 +196,8 @@ TEST_CASE("Years before desired balance for large start balance", "[task_4]") { int want{5}; REQUIRE(years_until_desired_balance(balance, target_balance) == want); } -TEST_CASE("Years before large difference between start and target balance", "[task_4]") { +TEST_CASE("Years before large difference between start and target balance", + "[task_4]") { double balance{2345.67}; double target_balance{12345.6789}; int want{85}; diff --git a/exercises/concept/lasagna-master/.meta/exemplar.cpp b/exercises/concept/lasagna-master/.meta/exemplar.cpp index 00e8e954b..f293dbca2 100644 --- a/exercises/concept/lasagna-master/.meta/exemplar.cpp +++ b/exercises/concept/lasagna-master/.meta/exemplar.cpp @@ -29,7 +29,7 @@ void addSecretIngredient(std::vector& myList, } std::vector scaleRecipe(const std::vector& quantities, - int portions) { + int portions) { std::vector result(quantities); for (auto& quantity : result) { quantity *= portions / 2.0; diff --git a/exercises/concept/lasagna-master/.meta/exemplar.h b/exercises/concept/lasagna-master/.meta/exemplar.h index 9bc99488c..95c2d3651 100644 --- a/exercises/concept/lasagna-master/.meta/exemplar.h +++ b/exercises/concept/lasagna-master/.meta/exemplar.h @@ -1,16 +1,22 @@ #pragma once -#include #include +#include namespace lasagna_master { -struct amount { int noodles; double sauce; }; +struct amount { + int noodles; + double sauce; +}; int preparationTime(const std::vector& layers, int prepTime = 2); amount quantities(const std::vector& layers); -void addSecretIngredient(std::vector& myList, const std::vector& friendsList); -void addSecretIngredient(std::vector& myList, const std::string& secretIngredient); -std::vector scaleRecipe(const std::vector& quantities, int portions); +void addSecretIngredient(std::vector& myList, + const std::vector& friendsList); +void addSecretIngredient(std::vector& myList, + const std::string& secretIngredient); +std::vector scaleRecipe(const std::vector& quantities, + int portions); } // namespace lasagna_master diff --git a/exercises/concept/lasagna-master/lasagna_master.cpp b/exercises/concept/lasagna-master/lasagna_master.cpp index f855bfbb3..ad84fed65 100644 --- a/exercises/concept/lasagna-master/lasagna_master.cpp +++ b/exercises/concept/lasagna-master/lasagna_master.cpp @@ -1,6 +1,3 @@ #include "lasagna_master.h" -namespace lasagna_master { - - -} // namespace lasagna_master +namespace lasagna_master {} // namespace lasagna_master diff --git a/exercises/concept/lasagna-master/lasagna_master_test.cpp b/exercises/concept/lasagna-master/lasagna_master_test.cpp index 66ae15fe6..466b6229b 100644 --- a/exercises/concept/lasagna-master/lasagna_master_test.cpp +++ b/exercises/concept/lasagna-master/lasagna_master_test.cpp @@ -11,26 +11,21 @@ using namespace lasagna_master; // As long as we have catch2 v2 and v3 in parallel, we can't use either // of their comparison marcors for floating point comparisons. -#define REQUIRE_VECTOR_APROX_EQUAL(vec1, vec2, margin) \ - REQUIRE(vec1.size() == vec2.size()); \ - for (size_t i = 0; i < vec1.size(); i++) { \ - REQUIRE( std::abs(vec1.at(i) - vec2.at(i)) < margin); \ - } - -TEST_CASE("preparationTime: Preparation time for many layers with custom average time", "[task_1]") { +#define REQUIRE_VECTOR_APROX_EQUAL(vec1, vec2, margin) \ + REQUIRE(vec1.size() == vec2.size()); \ + for (size_t i = 0; i < vec1.size(); i++) { \ + REQUIRE(std::abs(vec1.at(i) - vec2.at(i)) < margin); \ + } + +TEST_CASE( + // clang-format off + "preparationTime: Preparation time for many layers with custom average time", + // clang-format on + "[task_1]") { std::vector layers{ - "sauce", - "noodles", - "béchamel", - "meat", - "mozzarella", - "noodles", - "ricotta", - "eggplant", - "béchamel", - "noodles", - "sauce", - "mozzarella", + "sauce", "noodles", "béchamel", "meat", + "mozzarella", "noodles", "ricotta", "eggplant", + "béchamel", "noodles", "sauce", "mozzarella", }; int time{1}; int expected{12}; @@ -59,7 +54,7 @@ TEST_CASE("preparationTime: Preparation time for default case", "[task_1]") { } TEST_CASE("quantities: few layers", "[task_2]") { - std::vector layers {"noodles", "sauce", "noodles"}; + std::vector layers{"noodles", "sauce", "noodles"}; int expNoodles{100}; double expSauce{0.2}; amount amount = quantities(layers); @@ -68,19 +63,10 @@ TEST_CASE("quantities: few layers", "[task_2]") { } TEST_CASE("quantities: many layers", "[task_2]") { - std::vector layers{ - "sauce", - "noodles", - "béchamel", - "meat", - "mozzarella", - "noodles", - "ricotta", - "eggplant", - "béchamel", - "noodles", - "sauce", - "mozzarella"}; + std::vector layers{"sauce", "noodles", "béchamel", + "meat", "mozzarella", "noodles", + "ricotta", "eggplant", "béchamel", + "noodles", "sauce", "mozzarella"}; int expNoodles{150}; double expSauce{0.4}; amount amount = quantities(layers); @@ -89,12 +75,8 @@ TEST_CASE("quantities: many layers", "[task_2]") { } TEST_CASE("quantities: no noodles", "[task_2]") { - std::vector layers{ - "sauce", - "meat", - "mozzarella", - "sauce", - "mozzarella"}; + std::vector layers{"sauce", "meat", "mozzarella", "sauce", + "mozzarella"}; int expNoodles{0}; double expSauce{0.4}; amount amount = quantities(layers); @@ -103,12 +85,8 @@ TEST_CASE("quantities: no noodles", "[task_2]") { } TEST_CASE("quantities: no sauce", "[task_2]") { - std::vector layers{ - "noodles", - "meat", - "mozzarella", - "noodles", - "mozzarella"}; + std::vector layers{"noodles", "meat", "mozzarella", "noodles", + "mozzarella"}; int expNoodles{100}; double expSauce{0.0}; amount amount = quantities(layers); @@ -117,9 +95,12 @@ TEST_CASE("quantities: no sauce", "[task_2]") { } TEST_CASE("Adds secret vector ingredient", "[task_3]") { - const std::vector friendsList{"sauce", "noodles", "béchamel", "marjoram"}; - std::vector myList{"sauce", "noodles", "meat", "tomatoes", "?"}; - std::vector expected{"sauce", "noodles", "meat", "tomatoes", "marjoram"}; + const std::vector friendsList{"sauce", "noodles", "béchamel", + "marjoram"}; + std::vector myList{"sauce", "noodles", "meat", "tomatoes", + "?"}; + std::vector expected{"sauce", "noodles", "meat", "tomatoes", + "marjoram"}; addSecretIngredient(myList, friendsList); REQUIRE(myList == expected); } @@ -149,7 +130,7 @@ TEST_CASE("scaleRecipe: scales down correctly", "[task_4]") { } TEST_CASE("scaleRecipe: empty recipe", "[task_4]") { - const std::vector input{}; + const std::vector input{}; int portions{100}; std::vector expected{}; std::vector scaled{scaleRecipe(input, portions)}; @@ -158,8 +139,10 @@ TEST_CASE("scaleRecipe: empty recipe", "[task_4]") { TEST_CASE("Adds secret string ingredient", "[task_5]") { const std::string auntiesSecret{"mirkwood mushrooms"}; - std::vector myList{"sauce", "noodles", "meat", "tomatoes", "?"}; - std::vector expected{"sauce", "noodles", "meat", "tomatoes", "mirkwood mushrooms"}; + std::vector myList{"sauce", "noodles", "meat", "tomatoes", + "?"}; + std::vector expected{"sauce", "noodles", "meat", "tomatoes", + "mirkwood mushrooms"}; addSecretIngredient(myList, auntiesSecret); REQUIRE(myList == expected); } diff --git a/exercises/concept/last-will/.meta/exemplar.cpp b/exercises/concept/last-will/.meta/exemplar.cpp index 44abf98e4..8031c0089 100644 --- a/exercises/concept/last-will/.meta/exemplar.cpp +++ b/exercises/concept/last-will/.meta/exemplar.cpp @@ -2,54 +2,59 @@ // Secret knowledge of the Zhang family: namespace zhang { - int bank_number_part(int secret_modifier) { - int zhang_part{8'541}; - return (zhang_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 512;} - } - namespace blue { - int code_fragment() {return 677;} - } +int bank_number_part(int secret_modifier) { + 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}; - return (khan_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 148;} - } - namespace blue { - int code_fragment() {return 875;} - } +int bank_number_part(int secret_modifier) { + 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}; - return (garcia_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 118;} - } - namespace blue { - int code_fragment() {return 923;} - } +int bank_number_part(int secret_modifier) { + 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 namespace estate_executor { - int assemble_account_number(int secret_modifier) { - return zhang::bank_number_part(secret_modifier) + khan::bank_number_part(secret_modifier) + garcia::bank_number_part(secret_modifier); - } +int assemble_account_number(int secret_modifier) { + return zhang::bank_number_part(secret_modifier) + + khan::bank_number_part(secret_modifier) + + garcia::bank_number_part(secret_modifier); +} - int assemble_code() { - return ( zhang::red::code_fragment() + garcia::red::code_fragment() + khan::red::code_fragment() ) * ( zhang::blue::code_fragment() + garcia::blue::code_fragment() + khan::blue::code_fragment() ); - } -} \ No newline at end of file +int assemble_code() { + return (zhang::red::code_fragment() + garcia::red::code_fragment() + + khan::red::code_fragment()) * + (zhang::blue::code_fragment() + garcia::blue::code_fragment() + + khan::blue::code_fragment()); +} +} // namespace estate_executor \ No newline at end of file diff --git a/exercises/concept/last-will/last_will.cpp b/exercises/concept/last-will/last_will.cpp index ad52cda48..d1321286d 100644 --- a/exercises/concept/last-will/last_will.cpp +++ b/exercises/concept/last-will/last_will.cpp @@ -2,44 +2,44 @@ // Secret knowledge of the Zhang family: namespace zhang { - int bank_number_part(int secret_modifier) { - int zhang_part{8'541}; - return (zhang_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 512;} - } - namespace blue { - int code_fragment() {return 677;} - } +int bank_number_part(int secret_modifier) { + 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}; - return (khan_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 148;} - } - namespace blue { - int code_fragment() {return 875;} - } +int bank_number_part(int secret_modifier) { + 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}; - return (garcia_part*secret_modifier) % 10000; - } - namespace red { - int code_fragment() {return 118;} - } - namespace blue { - int code_fragment() {return 923;} - } +int bank_number_part(int secret_modifier) { + 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 \ No newline at end of file diff --git a/exercises/concept/last-will/last_will_test.cpp b/exercises/concept/last-will/last_will_test.cpp index bd69bbc39..0b4ddda7f 100644 --- a/exercises/concept/last-will/last_will_test.cpp +++ b/exercises/concept/last-will/last_will_test.cpp @@ -1,8 +1,8 @@ // Trick to let the code compile, even if the function has not been implemented: namespace estate_executor { - int assemble_account_number(int) __attribute__((weak)); - int assemble_code() __attribute__((weak)); -} +int assemble_account_number(int) __attribute__((weak)); +int assemble_code() __attribute__((weak)); +} // namespace estate_executor #include "last_will.cpp" #ifdef EXERCISM_TEST_SUITE @@ -14,9 +14,9 @@ namespace estate_executor { using namespace std; TEST_CASE("Family secrets have not been altered", "[task_1]") { - // We cannot test the existence of a namespace in the compiled + // We cannot test the existence of a namespace in the compiled // Code. - // This test merely checks if the numbers in the file have + // This test merely checks if the numbers in the file have // been changed. They have to be correct for the test to work. REQUIRE(zhang::bank_number_part(1) == 8541); @@ -35,7 +35,8 @@ TEST_CASE("Family secrets have not been altered", "[task_1]") { REQUIRE(garcia::blue::code_fragment() == 923); } -TEST_CASE("Account number assembly function exists in correct namespace", "[task_2]") { +TEST_CASE("Account number assembly function exists in correct namespace", + "[task_2]") { REQUIRE_NOTHROW(estate_executor::assemble_account_number(0)); } @@ -45,11 +46,14 @@ TEST_CASE("Account number assembly works correctly", "[task_2]") { int account_with_secret_1{16706}; int account_with_secret_23{14238}; - REQUIRE(estate_executor::assemble_account_number(1) == account_with_secret_1); - REQUIRE(estate_executor::assemble_account_number(23) == account_with_secret_23); + REQUIRE(estate_executor::assemble_account_number(1) == + account_with_secret_1); + REQUIRE(estate_executor::assemble_account_number(23) == + account_with_secret_23); } -TEST_CASE("Code fragment number assembly function exists in correct namespace", "[task_3]") { +TEST_CASE("Code fragment number assembly function exists in correct namespace", + "[task_3]") { REQUIRE_NOTHROW(estate_executor::assemble_code()); } diff --git a/exercises/concept/log-levels/.meta/exemplar.cpp b/exercises/concept/log-levels/.meta/exemplar.cpp index 6210b49a2..073cd4161 100644 --- a/exercises/concept/log-levels/.meta/exemplar.cpp +++ b/exercises/concept/log-levels/.meta/exemplar.cpp @@ -1,15 +1,15 @@ #include namespace log_line { - std::string message(const std::string& line) { - return line.substr(line.find(':') + 2); - } +std::string message(const std::string& line) { + return line.substr(line.find(':') + 2); +} - std::string log_level(const std::string& line) { - return line.substr(1, line.find(']') - 1); - } +std::string log_level(const std::string& line) { + return line.substr(1, line.find(']') - 1); +} - std::string reformat(const std::string& line) { - return message(line) + " (" + log_level(line) + ')'; - } -} // namespace log_line +std::string reformat(const std::string& line) { + return message(line) + " (" + log_level(line) + ')'; +} +} // namespace log_line diff --git a/exercises/concept/log-levels/log_levels.cpp b/exercises/concept/log-levels/log_levels.cpp index 92d9531b4..44b8502c7 100644 --- a/exercises/concept/log-levels/log_levels.cpp +++ b/exercises/concept/log-levels/log_levels.cpp @@ -1,15 +1,15 @@ #include namespace log_line { - std::string message(std::string line) { - // return the message - } +std::string message(std::string line) { + // return the message +} - std::string log_level(std::string line) { - // return the log level - } +std::string log_level(std::string line) { + // return the log level +} - std::string reformat(std::string line) { - // return the reformatted message - } +std::string reformat(std::string line) { + // return the reformatted message } +} // namespace log_line diff --git a/exercises/concept/log-levels/log_levels_test.cpp b/exercises/concept/log-levels/log_levels_test.cpp index 24e06907c..4f39bc676 100644 --- a/exercises/concept/log-levels/log_levels_test.cpp +++ b/exercises/concept/log-levels/log_levels_test.cpp @@ -7,8 +7,7 @@ using namespace std; -TEST_CASE("Error message", "[task_1]") -{ +TEST_CASE("Error message", "[task_1]") { const string actual = log_line::message("[ERROR]: Stack overflow"); const string expected{"Stack overflow"}; @@ -17,8 +16,7 @@ TEST_CASE("Error message", "[task_1]") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Warning message", "[task_1]") -{ +TEST_CASE("Warning message", "[task_1]") { const string actual = log_line::message("[WARNING]: Disk almost full"); const string expected{"Disk almost full"}; @@ -26,8 +24,7 @@ TEST_CASE("Warning message", "[task_1]") REQUIRE(actual == expected); } -TEST_CASE("Info message", "[task_1]") -{ +TEST_CASE("Info message", "[task_1]") { const string actual = log_line::message("[INFO]: File moved"); const string expected{"File moved"}; @@ -35,8 +32,7 @@ TEST_CASE("Info message", "[task_1]") REQUIRE(actual == expected); } -TEST_CASE("Error log level", "[task_2]") -{ +TEST_CASE("Error log level", "[task_2]") { const string actual = log_line::log_level("[ERROR]: Disk full"); const string expected{"ERROR"}; @@ -44,8 +40,7 @@ TEST_CASE("Error log level", "[task_2]") REQUIRE(actual == expected); } -TEST_CASE("Warning log level", "[task_2]") -{ +TEST_CASE("Warning log level", "[task_2]") { const string actual = log_line::log_level("[WARNING]: Unsafe password"); const string expected{"WARNING"}; @@ -53,8 +48,7 @@ TEST_CASE("Warning log level", "[task_2]") REQUIRE(actual == expected); } -TEST_CASE("Info log level", "[task_2]") -{ +TEST_CASE("Info log level", "[task_2]") { const string actual = log_line::log_level("[INFO]: Timezone changed"); const string expected{"INFO"}; @@ -62,8 +56,7 @@ TEST_CASE("Info log level", "[task_2]") REQUIRE(actual == expected); } -TEST_CASE("Error reformat", "[task_3]") -{ +TEST_CASE("Error reformat", "[task_3]") { const string actual = log_line::reformat("[ERROR]: Segmentation fault"); const string expected{"Segmentation fault (ERROR)"}; @@ -71,17 +64,16 @@ TEST_CASE("Error reformat", "[task_3]") REQUIRE(actual == expected); } -TEST_CASE("Warning reformat", "[task_3]") -{ - const string actual = log_line::reformat("[WARNING]: Decreased performance"); +TEST_CASE("Warning reformat", "[task_3]") { + const string actual = + log_line::reformat("[WARNING]: Decreased performance"); const string expected{"Decreased performance (WARNING)"}; REQUIRE(actual == expected); } -TEST_CASE("Info reformat", "[task_3]") -{ +TEST_CASE("Info reformat", "[task_3]") { const string actual = log_line::reformat("[INFO]: Disk defragmented"); const string expected{"Disk defragmented (INFO)"}; diff --git a/exercises/concept/making-the-grade/.meta/exemplar.cpp b/exercises/concept/making-the-grade/.meta/exemplar.cpp index 2d06eda4c..42ba00817 100644 --- a/exercises/concept/making-the-grade/.meta/exemplar.cpp +++ b/exercises/concept/making-the-grade/.meta/exemplar.cpp @@ -5,60 +5,64 @@ // Round down all provided student scores. std::vector round_down_scores(std::vector student_scores) { std::vector rounded{}; - for(int i{}; i < student_scores.size(); ++i) + for (int i{}; i < student_scores.size(); ++i) rounded.emplace_back(student_scores.at(i)); return rounded; } - // Count the number of failing students out of the group provided. int count_failed_students(std::vector student_scores) { int counter{}; - for(int i{}; i < student_scores.size(); ++i) { - if (student_scores.at(i) < 41) - ++counter; + for (int i{}; i < student_scores.size(); ++i) { + if (student_scores.at(i) < 41) ++counter; } return counter; } -// Determine how many of the provided student scores were 'the best' based on the provided threshold. -std::vector above_threshold(std::vector student_scores, int threshold) { +// Determine how many of the provided student scores were 'the best' based on +// the provided threshold. +std::vector above_threshold(std::vector student_scores, + int threshold) { std::vector above{}; - for(int i{}; i < student_scores.size(); ++i) { + for (int i{}; i < student_scores.size(); ++i) { if (student_scores.at(i) >= threshold) above.emplace_back(student_scores.at(i)); - } - + } + return above; } // Create a list of grade thresholds based on the provided highest grade. std::array letter_grades(int highest_score) { std::array grades{}; - for(int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4}; - i < 4; ++i) { + for (int i{}, lower_threshold{41}, step_size{(highest_score - 40) / 4}; + i < 4; ++i) { grades.at(i) = lower_threshold + step_size * i; } return grades; } // Organize the student's rank, name, and grade information in ascending order. -std::vector student_ranking(std::vector student_scores, std::vector student_names) { +std::vector student_ranking( + std::vector student_scores, std::vector student_names) { std::vector ranking{}; - for(int i{}; i < student_scores.size(); ++i) { - ranking.emplace_back(std::to_string(i + 1) + ". " + student_names.at(i) + ": " + std::to_string(student_scores.at(i))); - } - + for (int i{}; i < student_scores.size(); ++i) { + ranking.emplace_back(std::to_string(i + 1) + ". " + + student_names.at(i) + ": " + + std::to_string(student_scores.at(i))); + } + return ranking; } -// Create a string that contains the name of the first student to make a perfect score on the exam. -std::string perfect_score(std::vector student_scores, std::vector student_names) { +// Create a string that contains the name of the first student to make a perfect +// score on the exam. +std::string perfect_score(std::vector student_scores, + std::vector student_names) { std::vector ranking{}; - for(int i{}; i < student_scores.size(); ++i) { - if (student_scores.at(i) == 100) - return student_names.at(i); - } - + for (int i{}; i < student_scores.size(); ++i) { + if (student_scores.at(i) == 100) return student_names.at(i); + } + return ""; } \ No newline at end of file diff --git a/exercises/concept/making-the-grade/making_the_grade.cpp b/exercises/concept/making-the-grade/making_the_grade.cpp index 6684d59bb..413b3fbdd 100644 --- a/exercises/concept/making-the-grade/making_the_grade.cpp +++ b/exercises/concept/making-the-grade/making_the_grade.cpp @@ -8,15 +8,16 @@ std::vector round_down_scores(std::vector student_scores) { return {}; } - // Count the number of failing students out of the group provided. int count_failed_students(std::vector student_scores) { // TODO: Implement count_failed_students return 0; } -// Determine how many of the provided student scores were 'the best' based on the provided threshold. -std::vector above_threshold(std::vector student_scores, int threshold) { +// Determine how many of the provided student scores were 'the best' based on +// the provided threshold. +std::vector above_threshold(std::vector student_scores, + int threshold) { // TODO: Implement above_threshold return {}; } @@ -28,13 +29,16 @@ std::array letter_grades(int highest_score) { } // Organize the student's rank, name, and grade information in ascending order. -std::vector student_ranking(std::vector student_scores, std::vector student_names) { +std::vector student_ranking( + std::vector student_scores, std::vector student_names) { // TODO: Implement student_ranking return {}; } -// Create a string that contains the name of the first student to make a perfect score on the exam. -std::string perfect_score(std::vector student_scores, std::vector student_names) { +// Create a string that contains the name of the first student to make a perfect +// score on the exam. +std::string perfect_score(std::vector student_scores, + std::vector student_names) { // TODO: Implement perfect_score return ""; } diff --git a/exercises/concept/making-the-grade/making_the_grade_test.cpp b/exercises/concept/making-the-grade/making_the_grade_test.cpp index a045855e8..212cbc0b3 100644 --- a/exercises/concept/making-the-grade/making_the_grade_test.cpp +++ b/exercises/concept/making-the-grade/making_the_grade_test.cpp @@ -118,9 +118,11 @@ TEST_CASE("Rank one student", "[task_5]") { TEST_CASE("Rank several student", "[task_5]") { vector grades{100, 98, 92, 86, 70, 68, 67, 60}; - vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; - vector expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92", "4. Yoshi: 86", - "5. Kora: 70", "6. Bern: 68", "7. Jan: 67", "8. Rose: 60"}; + vector names{"Rui", "Betty", "Joci", "Yoshi", + "Kora", "Bern", "Jan", "Rose"}; + vector expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92", + "4. Yoshi: 86", "5. Kora: 70", "6. Bern: 68", + "7. Jan: 67", "8. Rose: 60"}; vector actual = student_ranking(grades, names); REQUIRE(expected == actual); @@ -128,7 +130,8 @@ TEST_CASE("Rank several student", "[task_5]") { TEST_CASE("No perfect score", "[task_6]") { vector grades{11, 34, 92, 23, 70, 76, 67, 60}; - vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; + vector names{"Rui", "Betty", "Joci", "Yoshi", + "Kora", "Bern", "Jan", "Rose"}; string expected{""}; string actual = perfect_score(grades, names); @@ -137,7 +140,8 @@ TEST_CASE("No perfect score", "[task_6]") { TEST_CASE("One perfect score", "[task_6]") { vector grades{11, 34, 92, 23, 70, 76, 67, 100}; - vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; + vector names{"Rui", "Betty", "Joci", "Yoshi", + "Kora", "Bern", "Jan", "Rose"}; string expected{"Rose"}; string actual = perfect_score(grades, names); @@ -146,7 +150,8 @@ TEST_CASE("One perfect score", "[task_6]") { TEST_CASE("Several perfect scores", "[task_6]") { vector grades{11, 100, 92, 23, 70, 100, 67, 100}; - vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; + vector names{"Rui", "Betty", "Joci", "Yoshi", + "Kora", "Bern", "Jan", "Rose"}; string expected{"Betty"}; string actual = perfect_score(grades, names); diff --git a/exercises/concept/pacman-rules/pacman_rules_test.cpp b/exercises/concept/pacman-rules/pacman_rules_test.cpp index 549dc5cd7..70314a9cd 100644 --- a/exercises/concept/pacman-rules/pacman_rules_test.cpp +++ b/exercises/concept/pacman-rules/pacman_rules_test.cpp @@ -5,59 +5,65 @@ #include "test/catch.hpp" #endif - -TEST_CASE( "ghost gets eaten", "[task_1]") { - REQUIRE( can_eat_ghost(true, true)); +TEST_CASE("ghost gets eaten", "[task_1]") { + REQUIRE(can_eat_ghost(true, true)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE( "ghost does not get eaten because no power pellet active", "[task_1]") { - REQUIRE_FALSE( can_eat_ghost(false, true)); +TEST_CASE("ghost does not get eaten because no power pellet active", + "[task_1]") { + REQUIRE_FALSE(can_eat_ghost(false, true)); } -TEST_CASE( "ghost does not get eaten because not touching ghost", "[task_1]") { - REQUIRE_FALSE( can_eat_ghost(true, false)); +TEST_CASE("ghost does not get eaten because not touching ghost", "[task_1]") { + REQUIRE_FALSE(can_eat_ghost(true, false)); } -TEST_CASE( "ghost does not get eaten because no power pellet is active, even if not touching ghost", "[task_1]") { - REQUIRE_FALSE( can_eat_ghost(false, false)); -} - -TEST_CASE("score when eating dot", "[task_2]") { - REQUIRE( scored(false, true)); +TEST_CASE( + // clang-format off + "ghost does not get eaten because no power pellet is active, even if not touching ghost", + // clang-format on + "[task_1]") { + REQUIRE_FALSE(can_eat_ghost(false, false)); } +TEST_CASE("score when eating dot", "[task_2]") { REQUIRE(scored(false, true)); } + TEST_CASE("score when eating power pellet", "[task_2]") { - REQUIRE( scored(true, false)); + REQUIRE(scored(true, false)); } TEST_CASE("no score when nothing eaten", "[task_2]") { - REQUIRE_FALSE( scored(false, false)); + REQUIRE_FALSE(scored(false, false)); } - -TEST_CASE("lose if touching a ghost without a power pellet active", "[task_3]") { - REQUIRE( lost(false, true)); + +TEST_CASE("lose if touching a ghost without a power pellet active", + "[task_3]") { + REQUIRE(lost(false, true)); } -TEST_CASE("don't lose if touching a ghost with a power pellet active", "[task_3]") { - REQUIRE_FALSE( lost(true, true)); +TEST_CASE("don't lose if touching a ghost with a power pellet active", + "[task_3]") { + REQUIRE_FALSE(lost(true, true)); } TEST_CASE("don't lose if not touching a ghost", "[task_3]") { - REQUIRE_FALSE( lost(true, false)); + REQUIRE_FALSE(lost(true, false)); } -TEST_CASE( "win if all dots eaten", "[task_4]") { - REQUIRE( won(true, false, false)); +TEST_CASE("win if all dots eaten", "[task_4]") { + REQUIRE(won(true, false, false)); } -TEST_CASE( "don't win if all dots eaten, but touching a ghost", "[task_4]") { - REQUIRE_FALSE( won(true, false, true)); +TEST_CASE("don't win if all dots eaten, but touching a ghost", "[task_4]") { + REQUIRE_FALSE(won(true, false, true)); } -TEST_CASE( "win if all dots eaten and touching a ghost with a power pellet active", "[task_4]") { - REQUIRE( won(true, true, true)); +TEST_CASE( + "win if all dots eaten and touching a ghost with a power pellet active", + "[task_4]") { + REQUIRE(won(true, true, true)); } #endif diff --git a/exercises/concept/troll-the-trolls/troll_the_trolls.cpp b/exercises/concept/troll-the-trolls/troll_the_trolls.cpp index aa8a9e0f4..1ef38f9d6 100644 --- a/exercises/concept/troll-the-trolls/troll_the_trolls.cpp +++ b/exercises/concept/troll-the-trolls/troll_the_trolls.cpp @@ -22,5 +22,4 @@ namespace hellmath { // `AccountStatus` arguments and returns `true`, if and only if the first // account has a strictly higher priority than the second. - } // namespace hellmath \ No newline at end of file diff --git a/exercises/concept/vehicle-purchase/.meta/exemplar.cpp b/exercises/concept/vehicle-purchase/.meta/exemplar.cpp index 92e58bf3a..649671308 100644 --- a/exercises/concept/vehicle-purchase/.meta/exemplar.cpp +++ b/exercises/concept/vehicle-purchase/.meta/exemplar.cpp @@ -2,29 +2,32 @@ 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){ - return (kind == "car" || kind == "truck"); - } +// 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) { + return (kind == "car" || kind == "truck"); +} - // 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 selection{option1}; - if(option1 > option2) { - selection = option2; - } - return selection + " is clearly the better choice."; +// 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 selection{option1}; + if (option1 > option2) { + selection = option2; } + return selection + " is clearly the better choice."; +} - // calculate_resell_price calculates how much a vehicle can resell for at a certain age. - double calculate_resell_price(double original_price, double age) { - double discount{0.7}; - if(age < 3) { - discount = 0.8; - } else if (age >= 10) { - discount = 0.5; - } - return original_price * discount; +// calculate_resell_price calculates how much a vehicle can resell for at a +// certain age. +double calculate_resell_price(double original_price, double age) { + double discount{0.7}; + if (age < 3) { + discount = 0.8; + } else if (age >= 10) { + discount = 0.5; } + return original_price * discount; +} } // namespace vehicle_purchase \ No newline at end of file diff --git a/exercises/concept/vehicle-purchase/.meta/exemplar.h b/exercises/concept/vehicle-purchase/.meta/exemplar.h index c9f0b1482..d35347dcf 100644 --- a/exercises/concept/vehicle-purchase/.meta/exemplar.h +++ b/exercises/concept/vehicle-purchase/.meta/exemplar.h @@ -4,8 +4,8 @@ namespace vehicle_purchase { - bool needs_license(std::string kind); - std::string choose_vehicle(std::string option1, std::string option2); - double calculate_resell_price(double original_price, double age); +bool needs_license(std::string kind); +std::string choose_vehicle(std::string option1, std::string option2); +double calculate_resell_price(double original_price, double age); } // namespace vehicle_purchase diff --git a/exercises/concept/vehicle-purchase/vehicle_purchase.cpp b/exercises/concept/vehicle-purchase/vehicle_purchase.cpp index 38e97a7fc..b392d9bd3 100644 --- a/exercises/concept/vehicle-purchase/vehicle_purchase.cpp +++ b/exercises/concept/vehicle-purchase/vehicle_purchase.cpp @@ -2,22 +2,25 @@ 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){ - // TODO: Return true if you need a license for that kind of vehicle. - return false; - } +// 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) { + // TODO: Return true if you need a license for that kind of vehicle. + return false; +} - // 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) { - // TODO: Return the final decision in a sentence. - return "not yet implemented"; - } +// 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) { + // TODO: Return the final decision in a sentence. + return "not yet implemented"; +} - // calculate_resell_price calculates how much a vehicle can resell for at a certain age. - double calculate_resell_price(double original_price, double age) { - // TODO: Return the age-corrected resell price. - return 0.0; - } +// calculate_resell_price calculates how much a vehicle can resell for at a +// certain age. +double calculate_resell_price(double original_price, double age) { + // TODO: Return the age-corrected resell price. + return 0.0; +} } // namespace vehicle_purchase \ No newline at end of file diff --git a/exercises/concept/vehicle-purchase/vehicle_purchase.h b/exercises/concept/vehicle-purchase/vehicle_purchase.h index c9f0b1482..d35347dcf 100644 --- a/exercises/concept/vehicle-purchase/vehicle_purchase.h +++ b/exercises/concept/vehicle-purchase/vehicle_purchase.h @@ -4,8 +4,8 @@ namespace vehicle_purchase { - bool needs_license(std::string kind); - std::string choose_vehicle(std::string option1, std::string option2); - double calculate_resell_price(double original_price, double age); +bool needs_license(std::string kind); +std::string choose_vehicle(std::string option1, std::string option2); +double calculate_resell_price(double original_price, double age); } // namespace vehicle_purchase diff --git a/exercises/concept/vehicle-purchase/vehicle_purchase_test.cpp b/exercises/concept/vehicle-purchase/vehicle_purchase_test.cpp index 8d12a8848..5d867fcb4 100644 --- a/exercises/concept/vehicle-purchase/vehicle_purchase_test.cpp +++ b/exercises/concept/vehicle-purchase/vehicle_purchase_test.cpp @@ -100,7 +100,8 @@ TEST_CASE("float price is reduced to 70% for age 8,", "[task_3]") { double original_price{39000.000001}; double age{8}; double expected{27300.0000007}; - REQUIRE_THAT(vehicle_purchase::calculate_resell_price(original_price, age), Catch::Matchers::WithinRel(expected, 0.001)); + REQUIRE_THAT(vehicle_purchase::calculate_resell_price(original_price, age), + Catch::Matchers::WithinRel(expected, 0.001)); } #endif diff --git a/exercises/practice/acronym/.meta/example.cpp b/exercises/practice/acronym/.meta/example.cpp index 0b6f199a7..c90f23daa 100644 --- a/exercises/practice/acronym/.meta/example.cpp +++ b/exercises/practice/acronym/.meta/example.cpp @@ -1,4 +1,5 @@ #include + #include "acronym.h" using std::string; diff --git a/exercises/practice/acronym/acronym.cpp b/exercises/practice/acronym/acronym.cpp index e7a9b59af..bec3d7906 100644 --- a/exercises/practice/acronym/acronym.cpp +++ b/exercises/practice/acronym/acronym.cpp @@ -1,5 +1,3 @@ #include "acronym.h" -namespace acronym { - -} // namespace acronym +namespace acronym {} // namespace acronym diff --git a/exercises/practice/acronym/acronym.h b/exercises/practice/acronym/acronym.h index 2d6c4cfeb..a5143d263 100644 --- a/exercises/practice/acronym/acronym.h +++ b/exercises/practice/acronym/acronym.h @@ -1,8 +1,6 @@ #if !defined(ACRONYM_H) #define ACRONYM_H -namespace acronym { +namespace acronym {} // namespace acronym -} // namespace acronym - -#endif // ACRONYM_H \ No newline at end of file +#endif // ACRONYM_H \ No newline at end of file diff --git a/exercises/practice/acronym/acronym_test.cpp b/exercises/practice/acronym/acronym_test.cpp index d20aba382..dcae8a255 100644 --- a/exercises/practice/acronym/acronym_test.cpp +++ b/exercises/practice/acronym/acronym_test.cpp @@ -7,8 +7,7 @@ using namespace std; -TEST_CASE("basic") -{ +TEST_CASE("basic") { const string actual = acronym::acronym("Portable Network Graphics"); const string expected{"PNG"}; @@ -17,8 +16,7 @@ TEST_CASE("basic") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("lowercase_words") -{ +TEST_CASE("lowercase_words") { const string actual = acronym::acronym("Ruby on Rails"); const string expected{"ROR"}; @@ -26,8 +24,7 @@ TEST_CASE("lowercase_words") REQUIRE(expected == actual); } -TEST_CASE("punctuation") -{ +TEST_CASE("punctuation") { const string actual = acronym::acronym("First In, First Out"); const string expected{"FIFO"}; @@ -35,8 +32,7 @@ TEST_CASE("punctuation") REQUIRE(expected == actual); } -TEST_CASE("all_caps_word") -{ +TEST_CASE("all_caps_word") { const string actual = acronym::acronym("GNU Image Manipulation Program"); const string expected{"GIMP"}; @@ -44,35 +40,35 @@ TEST_CASE("all_caps_word") REQUIRE(expected == actual); } -TEST_CASE("punctuation_without_whitespace") -{ - const string actual = acronym::acronym("Complementary metal-oxide semiconductor"); +TEST_CASE("punctuation_without_whitespace") { + const string actual = + acronym::acronym("Complementary metal-oxide semiconductor"); const string expected{"CMOS"}; REQUIRE(expected == actual); } -TEST_CASE("very_long_abbreviation") -{ - const string actual = acronym::acronym("Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"); +TEST_CASE("very_long_abbreviation") { + const string actual = acronym::acronym( + "Rolling On The Floor Laughing So Hard That My Dogs Came Over And " + "Licked Me"); const string expected{"ROTFLSHTMDCOALM"}; REQUIRE(expected == actual); } -TEST_CASE("consecutive_delimiters") -{ - const string actual = acronym::acronym("Something - I made up from thin air"); +TEST_CASE("consecutive_delimiters") { + const string actual = + acronym::acronym("Something - I made up from thin air"); const string expected{"SIMUFTA"}; REQUIRE(expected == actual); } -TEST_CASE("apostrophes") -{ +TEST_CASE("apostrophes") { const string actual = acronym::acronym("Halley's Comet"); const string expected{"HC"}; @@ -80,8 +76,7 @@ TEST_CASE("apostrophes") REQUIRE(expected == actual); } -TEST_CASE("underscore_emphasis") -{ +TEST_CASE("underscore_emphasis") { const string actual = acronym::acronym("The Road _Not_ Taken"); const string expected{"TRNT"}; diff --git a/exercises/practice/all-your-base/.meta/example.cpp b/exercises/practice/all-your-base/.meta/example.cpp index 7b871824b..665cd2ce6 100644 --- a/exercises/practice/all-your-base/.meta/example.cpp +++ b/exercises/practice/all-your-base/.meta/example.cpp @@ -1,6 +1,7 @@ -#include "all_your_base.h" -#include #include +#include + +#include "all_your_base.h" namespace all_your_base { @@ -11,11 +12,9 @@ std::vector convert(unsigned int input_base, unsigned int value = 0; if (input_base <= 1 || output_base <= 1) throw std::invalid_argument("Invalid base"); - if (input_digits.empty()) - return {}; + if (input_digits.empty()) return {}; for (unsigned int d : input_digits) { - if (d >= input_base) - throw std::invalid_argument("Invalid number"); + if (d >= input_base) throw std::invalid_argument("Invalid number"); value = value * input_base + d; } while (value != 0) { @@ -26,4 +25,4 @@ std::vector convert(unsigned int input_base, return b; } -} +} // namespace all_your_base diff --git a/exercises/practice/all-your-base/all_your_base.cpp b/exercises/practice/all-your-base/all_your_base.cpp index 1e22a9ff5..86eb7d587 100644 --- a/exercises/practice/all-your-base/all_your_base.cpp +++ b/exercises/practice/all-your-base/all_your_base.cpp @@ -1,5 +1,3 @@ #include "all_your_base.h" -namespace all_your_base { - -} // namespace all_your_base +namespace all_your_base {} // namespace all_your_base diff --git a/exercises/practice/all-your-base/all_your_base.h b/exercises/practice/all-your-base/all_your_base.h index b1f5c56ee..898c54486 100644 --- a/exercises/practice/all-your-base/all_your_base.h +++ b/exercises/practice/all-your-base/all_your_base.h @@ -1,8 +1,6 @@ #if !defined(ALL_YOUR_BASE_H) #define ALL_YOUR_BASE_H -namespace all_your_base { +namespace all_your_base {} // namespace all_your_base -} // namespace all_your_base - -#endif // ALL_YOUR_BASE_H \ No newline at end of file +#endif // ALL_YOUR_BASE_H \ No newline at end of file diff --git a/exercises/practice/all-your-base/all_your_base_test.cpp b/exercises/practice/all-your-base/all_your_base_test.cpp index 356d5dd69..cd08fde97 100644 --- a/exercises/practice/all-your-base/all_your_base_test.cpp +++ b/exercises/practice/all-your-base/all_your_base_test.cpp @@ -7,7 +7,7 @@ using namespace std; -//all-your-base exercise test case data version 2.3.0 +// all-your-base exercise test case data version 2.3.0 TEST_CASE("single_bit_one_to_decimal") { vector in_digits{1}; @@ -109,31 +109,36 @@ TEST_CASE("leading_zeros") { TEST_CASE("first_base_is_one") { vector in_digits{}; - REQUIRE_THROWS_AS(all_your_base::convert(1, in_digits, 10), std::invalid_argument); + REQUIRE_THROWS_AS(all_your_base::convert(1, in_digits, 10), + std::invalid_argument); } TEST_CASE("first_base_is_zero") { vector in_digits{}; - REQUIRE_THROWS_AS(all_your_base::convert(0, in_digits, 10), std::invalid_argument); + REQUIRE_THROWS_AS(all_your_base::convert(0, in_digits, 10), + std::invalid_argument); } TEST_CASE("invalid_positive_digit") { vector in_digits{1, 2, 1, 0, 1, 0}; - REQUIRE_THROWS_AS(all_your_base::convert(2, in_digits, 10), std::invalid_argument); + REQUIRE_THROWS_AS(all_your_base::convert(2, in_digits, 10), + std::invalid_argument); } TEST_CASE("second_base_is_one") { vector in_digits{1, 0, 1, 0, 1, 0}; - REQUIRE_THROWS_AS(all_your_base::convert(2, in_digits, 1), std::invalid_argument); + REQUIRE_THROWS_AS(all_your_base::convert(2, in_digits, 1), + std::invalid_argument); } TEST_CASE("second_base_is_zero") { vector in_digits{7}; - REQUIRE_THROWS_AS(all_your_base::convert(10, in_digits, 0), std::invalid_argument); + REQUIRE_THROWS_AS(all_your_base::convert(10, in_digits, 0), + std::invalid_argument); } #endif diff --git a/exercises/practice/allergies/.meta/example.cpp b/exercises/practice/allergies/.meta/example.cpp index 733ce5162..5bc5f205d 100644 --- a/exercises/practice/allergies/.meta/example.cpp +++ b/exercises/practice/allergies/.meta/example.cpp @@ -1,30 +1,27 @@ -#include "allergies.h" - -#include +#include #include +#include #include -#include -namespace allergies -{ +#include "allergies.h" + +namespace allergies { -allergy_test::allergy_test(unsigned int test_result) : result(test_result){} +allergy_test::allergy_test(unsigned int test_result) : result(test_result) {} -bool allergy_test::is_allergic_to(std::string const& allergen) const -{ +bool allergy_test::is_allergic_to(std::string const& allergen) const { unsigned int allergen_value = allergies::ALLERGENS.at(allergen); return (result & allergen_value) == allergen_value; } -std::unordered_set allergy_test::get_allergies() const -{ - std::unordered_set allergies; - - for(auto const& entry : allergies::ALLERGENS) - if((result & entry.second) == entry.second) +std::unordered_set allergy_test::get_allergies() const { + std::unordered_set allergies; + + for (auto const& entry : allergies::ALLERGENS) + if ((result & entry.second) == entry.second) allergies.insert(entry.first); return allergies; } -} +} // namespace allergies diff --git a/exercises/practice/allergies/.meta/example.h b/exercises/practice/allergies/.meta/example.h index 921746981..cb03d6eaf 100644 --- a/exercises/practice/allergies/.meta/example.h +++ b/exercises/practice/allergies/.meta/example.h @@ -1,36 +1,27 @@ #if !defined(ALLERGIES_H) #define ALLERGIES_H -#include #include +#include #include -namespace allergies -{ - -std::map const ALLERGENS { - {"eggs", 1}, - {"peanuts", 2}, - {"shellfish", 4}, - {"strawberries", 8}, - {"tomatoes", 16}, - {"chocolate", 32}, - {"pollen", 64}, - {"cats", 128} -}; +namespace allergies { + +std::map const ALLERGENS{ + {"eggs", 1}, {"peanuts", 2}, {"shellfish", 4}, {"strawberries", 8}, + {"tomatoes", 16}, {"chocolate", 32}, {"pollen", 64}, {"cats", 128}}; -class allergy_test -{ -public: +class allergy_test { + public: allergy_test(unsigned int test_result); bool is_allergic_to(std::string const& allergen) const; std::unordered_set get_allergies() const; -private: + private: unsigned int const result; }; -} +} // namespace allergies #endif diff --git a/exercises/practice/allergies/allergies.cpp b/exercises/practice/allergies/allergies.cpp index a3771e741..72f840bde 100644 --- a/exercises/practice/allergies/allergies.cpp +++ b/exercises/practice/allergies/allergies.cpp @@ -1,5 +1,3 @@ #include "allergies.h" -namespace allergies { - -} // namespace allergies +namespace allergies {} // namespace allergies diff --git a/exercises/practice/allergies/allergies.h b/exercises/practice/allergies/allergies.h index e418783de..9993a240e 100644 --- a/exercises/practice/allergies/allergies.h +++ b/exercises/practice/allergies/allergies.h @@ -1,8 +1,6 @@ #if !defined(ALLERGIES_H) #define ALLERGIES_H -namespace allergies { +namespace allergies {} // namespace allergies -} // namespace allergies - -#endif // ALLERGIES_H \ No newline at end of file +#endif // ALLERGIES_H \ No newline at end of file diff --git a/exercises/practice/allergies/allergies_test.cpp b/exercises/practice/allergies/allergies_test.cpp index 0049a9c47..29fc3d4ca 100644 --- a/exercises/practice/allergies/allergies_test.cpp +++ b/exercises/practice/allergies/allergies_test.cpp @@ -5,216 +5,286 @@ #include "test/catch.hpp" #endif -TEST_CASE("testing for eggs allergy -> not allergic to anything", "[17fc7296-2440-4ac4-ad7b-d07c321bc5a0]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("eggs")); +TEST_CASE("testing for eggs allergy -> not allergic to anything", + "[17fc7296-2440-4ac4-ad7b-d07c321bc5a0]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("eggs")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("testing for eggs allergy -> allergic only to eggs", "[07ced27b-1da5-4c2e-8ae2-cb2791437546]") { - REQUIRE(true == allergies::allergy_test(1).is_allergic_to("eggs")); +TEST_CASE("testing for eggs allergy -> allergic only to eggs", + "[07ced27b-1da5-4c2e-8ae2-cb2791437546]") { + REQUIRE(true == allergies::allergy_test(1).is_allergic_to("eggs")); } -TEST_CASE("testing for eggs allergy -> allergic to eggs and something else", "[5035b954-b6fa-4b9b-a487-dae69d8c5f96]") { - REQUIRE(true == allergies::allergy_test(3).is_allergic_to("eggs")); +TEST_CASE("testing for eggs allergy -> allergic to eggs and something else", + "[5035b954-b6fa-4b9b-a487-dae69d8c5f96]") { + REQUIRE(true == allergies::allergy_test(3).is_allergic_to("eggs")); } -TEST_CASE("testing for eggs allergy -> allergic to something, but not eggs", "[64a6a83a-5723-4b5b-a896-663307403310]") { - REQUIRE(false == allergies::allergy_test(2).is_allergic_to("eggs")); +TEST_CASE("testing for eggs allergy -> allergic to something, but not eggs", + "[64a6a83a-5723-4b5b-a896-663307403310]") { + REQUIRE(false == allergies::allergy_test(2).is_allergic_to("eggs")); } -TEST_CASE("testing for eggs allergy -> allergic to everything", "[90c8f484-456b-41c4-82ba-2d08d93231c6]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("eggs")); +TEST_CASE("testing for eggs allergy -> allergic to everything", + "[90c8f484-456b-41c4-82ba-2d08d93231c6]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("eggs")); } -TEST_CASE("testing for peanuts allergy -> not allergic to anything", "[d266a59a-fccc-413b-ac53-d57cb1f0db9d]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("peanuts")); +TEST_CASE("testing for peanuts allergy -> not allergic to anything", + "[d266a59a-fccc-413b-ac53-d57cb1f0db9d]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("peanuts")); } -TEST_CASE("testing for peanuts allergy -> allergic only to peanuts", "[ea210a98-860d-46b2-a5bf-50d8995b3f2a]") { - REQUIRE(true == allergies::allergy_test(2).is_allergic_to("peanuts")); +TEST_CASE("testing for peanuts allergy -> allergic only to peanuts", + "[ea210a98-860d-46b2-a5bf-50d8995b3f2a]") { + REQUIRE(true == allergies::allergy_test(2).is_allergic_to("peanuts")); } -TEST_CASE("testing for peanuts allergy -> allergic to peanuts and something else", "[eac69ae9-8d14-4291-ac4b-7fd2c73d3a5b]") { - REQUIRE(true == allergies::allergy_test(7).is_allergic_to("peanuts")); +TEST_CASE( + "testing for peanuts allergy -> allergic to peanuts and something else", + "[eac69ae9-8d14-4291-ac4b-7fd2c73d3a5b]") { + REQUIRE(true == allergies::allergy_test(7).is_allergic_to("peanuts")); } -TEST_CASE("testing for peanuts allergy -> allergic to something, but not peanuts", "[9152058c-ce39-4b16-9b1d-283ec6d25085]") { - REQUIRE(false == allergies::allergy_test(5).is_allergic_to("peanuts")); +TEST_CASE( + "testing for peanuts allergy -> allergic to something, but not peanuts", + "[9152058c-ce39-4b16-9b1d-283ec6d25085]") { + REQUIRE(false == allergies::allergy_test(5).is_allergic_to("peanuts")); } -TEST_CASE("testing for peanuts allergy -> allergic to everything", "[d2d71fd8-63d5-40f9-a627-fbdaf88caeab]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("peanuts")); +TEST_CASE("testing for peanuts allergy -> allergic to everything", + "[d2d71fd8-63d5-40f9-a627-fbdaf88caeab]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("peanuts")); } -TEST_CASE("testing for shellfish allergy -> not allergic to anything", "[b948b0a1-cbf7-4b28-a244-73ff56687c80]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("shellfish")); +TEST_CASE("testing for shellfish allergy -> not allergic to anything", + "[b948b0a1-cbf7-4b28-a244-73ff56687c80]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("shellfish")); } -TEST_CASE("testing for shellfish allergy -> allergic only to shellfish", "[9ce9a6f3-53e9-4923-85e0-73019047c567]") { - REQUIRE(true == allergies::allergy_test(4).is_allergic_to("shellfish")); +TEST_CASE("testing for shellfish allergy -> allergic only to shellfish", + "[9ce9a6f3-53e9-4923-85e0-73019047c567]") { + REQUIRE(true == allergies::allergy_test(4).is_allergic_to("shellfish")); } -TEST_CASE("testing for shellfish allergy -> allergic to shellfish and something else", "[b272fca5-57ba-4b00-bd0c-43a737ab2131]") { - REQUIRE(true == allergies::allergy_test(14).is_allergic_to("shellfish")); +TEST_CASE( + "testing for shellfish allergy -> allergic to shellfish and something else", + "[b272fca5-57ba-4b00-bd0c-43a737ab2131]") { + REQUIRE(true == allergies::allergy_test(14).is_allergic_to("shellfish")); } -TEST_CASE("testing for shellfish allergy -> allergic to something, but not shellfish", "[21ef8e17-c227-494e-8e78-470a1c59c3d8]") { - REQUIRE(false == allergies::allergy_test(10).is_allergic_to("shellfish")); +TEST_CASE( + "testing for shellfish allergy -> allergic to something, but not shellfish", + "[21ef8e17-c227-494e-8e78-470a1c59c3d8]") { + REQUIRE(false == allergies::allergy_test(10).is_allergic_to("shellfish")); } -TEST_CASE("testing for shellfish allergy -> allergic to everything", "[cc789c19-2b5e-4c67-b146-625dc8cfa34e]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("shellfish")); +TEST_CASE("testing for shellfish allergy -> allergic to everything", + "[cc789c19-2b5e-4c67-b146-625dc8cfa34e]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("shellfish")); } -TEST_CASE("testing for strawberries allergy -> not allergic to anything", "[651bde0a-2a74-46c4-ab55-02a0906ca2f5]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("strawberries")); +TEST_CASE("testing for strawberries allergy -> not allergic to anything", + "[651bde0a-2a74-46c4-ab55-02a0906ca2f5]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("strawberries")); } -TEST_CASE("testing for strawberries allergy -> allergic only to strawberries", "[b649a750-9703-4f5f-b7f7-91da2c160ece]") { - REQUIRE(true == allergies::allergy_test(8).is_allergic_to("strawberries")); +TEST_CASE("testing for strawberries allergy -> allergic only to strawberries", + "[b649a750-9703-4f5f-b7f7-91da2c160ece]") { + REQUIRE(true == allergies::allergy_test(8).is_allergic_to("strawberries")); } -TEST_CASE("testing for strawberries allergy -> allergic to strawberries and something else", "[50f5f8f3-3bac-47e6-8dba-2d94470a4bc6]") { - REQUIRE(true == allergies::allergy_test(28).is_allergic_to("strawberries")); +TEST_CASE( + // clang-format off + "testing for strawberries allergy -> allergic to strawberries and something else", + // clang-format on + "[50f5f8f3-3bac-47e6-8dba-2d94470a4bc6]") { + REQUIRE(true == allergies::allergy_test(28).is_allergic_to("strawberries")); } -TEST_CASE("testing for strawberries allergy -> allergic to something, but not strawberries", "[23dd6952-88c9-48d7-a7d5-5d0343deb18d]") { - REQUIRE(false == allergies::allergy_test(20).is_allergic_to("strawberries")); +TEST_CASE( + // clang-format off + "testing for strawberries allergy -> allergic to something, but not strawberries", + // clang-format on + "[23dd6952-88c9-48d7-a7d5-5d0343deb18d]") { + REQUIRE(false == + allergies::allergy_test(20).is_allergic_to("strawberries")); } -TEST_CASE("testing for strawberries allergy -> allergic to everything", "[74afaae2-13b6-43a2-837a-286cd42e7d7e]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("strawberries")); +TEST_CASE("testing for strawberries allergy -> allergic to everything", + "[74afaae2-13b6-43a2-837a-286cd42e7d7e]") { + REQUIRE(true == + allergies::allergy_test(255).is_allergic_to("strawberries")); } -TEST_CASE("testing for tomatoes allergy -> not allergic to anything", "[c49a91ef-6252-415e-907e-a9d26ef61723]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("tomatoes")); +TEST_CASE("testing for tomatoes allergy -> not allergic to anything", + "[c49a91ef-6252-415e-907e-a9d26ef61723]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("tomatoes")); } -TEST_CASE("testing for tomatoes allergy -> allergic only to tomatoes", "[b69c5131-b7d0-41ad-a32c-e1b2cc632df8]") { - REQUIRE(true == allergies::allergy_test(16).is_allergic_to("tomatoes")); +TEST_CASE("testing for tomatoes allergy -> allergic only to tomatoes", + "[b69c5131-b7d0-41ad-a32c-e1b2cc632df8]") { + REQUIRE(true == allergies::allergy_test(16).is_allergic_to("tomatoes")); } -TEST_CASE("testing for tomatoes allergy -> allergic to tomatoes and something else", "[1ca50eb1-f042-4ccf-9050-341521b929ec]") { - REQUIRE(true == allergies::allergy_test(56).is_allergic_to("tomatoes")); +TEST_CASE( + "testing for tomatoes allergy -> allergic to tomatoes and something else", + "[1ca50eb1-f042-4ccf-9050-341521b929ec]") { + REQUIRE(true == allergies::allergy_test(56).is_allergic_to("tomatoes")); } -TEST_CASE("testing for tomatoes allergy -> allergic to something, but not tomatoes", "[e9846baa-456b-4eff-8025-034b9f77bd8e]") { - REQUIRE(false == allergies::allergy_test(40).is_allergic_to("tomatoes")); +TEST_CASE( + "testing for tomatoes allergy -> allergic to something, but not tomatoes", + "[e9846baa-456b-4eff-8025-034b9f77bd8e]") { + REQUIRE(false == allergies::allergy_test(40).is_allergic_to("tomatoes")); } -TEST_CASE("testing for tomatoes allergy -> allergic to everything", "[b2414f01-f3ad-4965-8391-e65f54dad35f]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("tomatoes")); +TEST_CASE("testing for tomatoes allergy -> allergic to everything", + "[b2414f01-f3ad-4965-8391-e65f54dad35f]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("tomatoes")); } -TEST_CASE("testing for chocolate allergy -> not allergic to anything", "[978467ab-bda4-49f7-b004-1d011ead947c]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("chocolate")); +TEST_CASE("testing for chocolate allergy -> not allergic to anything", + "[978467ab-bda4-49f7-b004-1d011ead947c]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("chocolate")); } -TEST_CASE("testing for chocolate allergy -> allergic only to chocolate", "[59cf4e49-06ea-4139-a2c1-d7aad28f8cbc]") { - REQUIRE(true == allergies::allergy_test(32).is_allergic_to("chocolate")); +TEST_CASE("testing for chocolate allergy -> allergic only to chocolate", + "[59cf4e49-06ea-4139-a2c1-d7aad28f8cbc]") { + REQUIRE(true == allergies::allergy_test(32).is_allergic_to("chocolate")); } -TEST_CASE("testing for chocolate allergy -> allergic to chocolate and something else", "[b0a7c07b-2db7-4f73-a180-565e07040ef1]") { - REQUIRE(true == allergies::allergy_test(112).is_allergic_to("chocolate")); +TEST_CASE( + "testing for chocolate allergy -> allergic to chocolate and something else", + "[b0a7c07b-2db7-4f73-a180-565e07040ef1]") { + REQUIRE(true == allergies::allergy_test(112).is_allergic_to("chocolate")); } -TEST_CASE("testing for chocolate allergy -> allergic to something, but not chocolate", "[f5506893-f1ae-482a-b516-7532ba5ca9d2]") { - REQUIRE(false == allergies::allergy_test(80).is_allergic_to("chocolate")); +TEST_CASE( + "testing for chocolate allergy -> allergic to something, but not chocolate", + "[f5506893-f1ae-482a-b516-7532ba5ca9d2]") { + REQUIRE(false == allergies::allergy_test(80).is_allergic_to("chocolate")); } -TEST_CASE("testing for chocolate allergy -> allergic to everything", "[02debb3d-d7e2-4376-a26b-3c974b6595c6]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("chocolate")); +TEST_CASE("testing for chocolate allergy -> allergic to everything", + "[02debb3d-d7e2-4376-a26b-3c974b6595c6]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("chocolate")); } -TEST_CASE("testing for pollen allergy -> not allergic to anything", "[17f4a42b-c91e-41b8-8a76-4797886c2d96]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("pollen")); +TEST_CASE("testing for pollen allergy -> not allergic to anything", + "[17f4a42b-c91e-41b8-8a76-4797886c2d96]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("pollen")); } -TEST_CASE("testing for pollen allergy -> allergic only to pollen", "[7696eba7-1837-4488-882a-14b7b4e3e399]") { - REQUIRE(true == allergies::allergy_test(64).is_allergic_to("pollen")); +TEST_CASE("testing for pollen allergy -> allergic only to pollen", + "[7696eba7-1837-4488-882a-14b7b4e3e399]") { + REQUIRE(true == allergies::allergy_test(64).is_allergic_to("pollen")); } -TEST_CASE("testing for pollen allergy -> allergic to pollen and something else", "[9a49aec5-fa1f-405d-889e-4dfc420db2b6]") { - REQUIRE(true == allergies::allergy_test(224).is_allergic_to("pollen")); +TEST_CASE("testing for pollen allergy -> allergic to pollen and something else", + "[9a49aec5-fa1f-405d-889e-4dfc420db2b6]") { + REQUIRE(true == allergies::allergy_test(224).is_allergic_to("pollen")); } -TEST_CASE("testing for pollen allergy -> allergic to something, but not pollen", "[3cb8e79f-d108-4712-b620-aa146b1954a9]") { - REQUIRE(false == allergies::allergy_test(160).is_allergic_to("pollen")); +TEST_CASE("testing for pollen allergy -> allergic to something, but not pollen", + "[3cb8e79f-d108-4712-b620-aa146b1954a9]") { + REQUIRE(false == allergies::allergy_test(160).is_allergic_to("pollen")); } -TEST_CASE("testing for pollen allergy -> allergic to everything", "[1dc3fe57-7c68-4043-9d51-5457128744b2]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("pollen")); +TEST_CASE("testing for pollen allergy -> allergic to everything", + "[1dc3fe57-7c68-4043-9d51-5457128744b2]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("pollen")); } -TEST_CASE("testing for cats allergy -> not allergic to anything", "[d3f523d6-3d50-419b-a222-d4dfd62ce314]") { - REQUIRE(false == allergies::allergy_test(0).is_allergic_to("cats")); +TEST_CASE("testing for cats allergy -> not allergic to anything", + "[d3f523d6-3d50-419b-a222-d4dfd62ce314]") { + REQUIRE(false == allergies::allergy_test(0).is_allergic_to("cats")); } -TEST_CASE("testing for cats allergy -> allergic only to cats", "[eba541c3-c886-42d3-baef-c048cb7fcd8f]") { - REQUIRE(true == allergies::allergy_test(128).is_allergic_to("cats")); +TEST_CASE("testing for cats allergy -> allergic only to cats", + "[eba541c3-c886-42d3-baef-c048cb7fcd8f]") { + REQUIRE(true == allergies::allergy_test(128).is_allergic_to("cats")); } -TEST_CASE("testing for cats allergy -> allergic to cats and something else", "[ba718376-26e0-40b7-bbbe-060287637ea5]") { - REQUIRE(true == allergies::allergy_test(192).is_allergic_to("cats")); +TEST_CASE("testing for cats allergy -> allergic to cats and something else", + "[ba718376-26e0-40b7-bbbe-060287637ea5]") { + REQUIRE(true == allergies::allergy_test(192).is_allergic_to("cats")); } -TEST_CASE("testing for cats allergy -> allergic to something, but not cats", "[3c6dbf4a-5277-436f-8b88-15a206f2d6c4]") { - REQUIRE(false == allergies::allergy_test(64).is_allergic_to("cats")); +TEST_CASE("testing for cats allergy -> allergic to something, but not cats", + "[3c6dbf4a-5277-436f-8b88-15a206f2d6c4]") { + REQUIRE(false == allergies::allergy_test(64).is_allergic_to("cats")); } -TEST_CASE("testing for cats allergy -> allergic to everything", "[1faabb05-2b98-4995-9046-d83e4a48a7c1]") { - REQUIRE(true == allergies::allergy_test(255).is_allergic_to("cats")); +TEST_CASE("testing for cats allergy -> allergic to everything", + "[1faabb05-2b98-4995-9046-d83e4a48a7c1]") { + REQUIRE(true == allergies::allergy_test(255).is_allergic_to("cats")); } -TEST_CASE("list when: -> no allergies", "[f9c1b8e7-7dc5-4887-aa93-cebdcc29dd8f]") { - std::unordered_set expected ={}; - REQUIRE(expected == allergies::allergy_test(0).get_allergies()); +TEST_CASE("list when: -> no allergies", + "[f9c1b8e7-7dc5-4887-aa93-cebdcc29dd8f]") { + std::unordered_set expected = {}; + REQUIRE(expected == allergies::allergy_test(0).get_allergies()); } TEST_CASE("list when: -> just eggs", "[9e1a4364-09a6-4d94-990f-541a94a4c1e8]") { - std::unordered_set expected ={"eggs"}; - REQUIRE(expected == allergies::allergy_test(1).get_allergies()); + std::unordered_set expected = {"eggs"}; + REQUIRE(expected == allergies::allergy_test(1).get_allergies()); } -TEST_CASE("list when: -> just peanuts", "[8851c973-805e-4283-9e01-d0c0da0e4695]") { - std::unordered_set expected ={"peanuts"}; - REQUIRE(expected == allergies::allergy_test(2).get_allergies()); +TEST_CASE("list when: -> just peanuts", + "[8851c973-805e-4283-9e01-d0c0da0e4695]") { + std::unordered_set expected = {"peanuts"}; + REQUIRE(expected == allergies::allergy_test(2).get_allergies()); } -TEST_CASE("list when: -> just strawberries", "[2c8943cb-005e-435f-ae11-3e8fb558ea98]") { - std::unordered_set expected ={"strawberries"}; - REQUIRE(expected == allergies::allergy_test(8).get_allergies()); +TEST_CASE("list when: -> just strawberries", + "[2c8943cb-005e-435f-ae11-3e8fb558ea98]") { + std::unordered_set expected = {"strawberries"}; + REQUIRE(expected == allergies::allergy_test(8).get_allergies()); } -TEST_CASE("list when: -> eggs and peanuts", "[6fa95d26-044c-48a9-8a7b-9ee46ec32c5c]") { - std::unordered_set expected ={"eggs", "peanuts"}; - REQUIRE(expected == allergies::allergy_test(3).get_allergies()); +TEST_CASE("list when: -> eggs and peanuts", + "[6fa95d26-044c-48a9-8a7b-9ee46ec32c5c]") { + std::unordered_set expected = {"eggs", "peanuts"}; + REQUIRE(expected == allergies::allergy_test(3).get_allergies()); } -TEST_CASE("list when: -> more than eggs but not peanuts", "[19890e22-f63f-4c5c-a9fb-fb6eacddfe8e]") { - std::unordered_set expected ={"eggs", "shellfish"}; - REQUIRE(expected == allergies::allergy_test(5).get_allergies()); +TEST_CASE("list when: -> more than eggs but not peanuts", + "[19890e22-f63f-4c5c-a9fb-fb6eacddfe8e]") { + std::unordered_set expected = {"eggs", "shellfish"}; + REQUIRE(expected == allergies::allergy_test(5).get_allergies()); } -TEST_CASE("list when: -> lots of stuff", "[4b68f470-067c-44e4-889f-c9fe28917d2f]") { - std::unordered_set expected ={"strawberries", "tomatoes", "chocolate", "pollen", "cats"}; - REQUIRE(expected == allergies::allergy_test(248).get_allergies()); +TEST_CASE("list when: -> lots of stuff", + "[4b68f470-067c-44e4-889f-c9fe28917d2f]") { + std::unordered_set expected = {"strawberries", "tomatoes", + "chocolate", "pollen", "cats"}; + REQUIRE(expected == allergies::allergy_test(248).get_allergies()); } -TEST_CASE("list when: -> everything", "[0881b7c5-9efa-4530-91bd-68370d054bc7]") { - std::unordered_set expected ={"eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"}; - REQUIRE(expected == allergies::allergy_test(255).get_allergies()); +TEST_CASE("list when: -> everything", + "[0881b7c5-9efa-4530-91bd-68370d054bc7]") { + std::unordered_set expected = { + "eggs", "peanuts", "shellfish", "strawberries", + "tomatoes", "chocolate", "pollen", "cats"}; + REQUIRE(expected == allergies::allergy_test(255).get_allergies()); } -TEST_CASE("list when: -> no allergen score parts", "[12ce86de-b347-42a0-ab7c-2e0570f0c65b]") { - std::unordered_set expected ={"eggs", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"}; - REQUIRE(expected == allergies::allergy_test(509).get_allergies()); +TEST_CASE("list when: -> no allergen score parts", + "[12ce86de-b347-42a0-ab7c-2e0570f0c65b]") { + std::unordered_set expected = { + "eggs", "shellfish", "strawberries", "tomatoes", + "chocolate", "pollen", "cats"}; + REQUIRE(expected == allergies::allergy_test(509).get_allergies()); } -TEST_CASE("list when: -> no allergen score parts without highest valid score", "[93c2df3e-4f55-4fed-8116-7513092819cd]") { - std::unordered_set expected ={"eggs"}; - REQUIRE(expected == allergies::allergy_test(257).get_allergies()); +TEST_CASE("list when: -> no allergen score parts without highest valid score", + "[93c2df3e-4f55-4fed-8116-7513092819cd]") { + std::unordered_set expected = {"eggs"}; + REQUIRE(expected == allergies::allergy_test(257).get_allergies()); } #endif diff --git a/exercises/practice/anagram/.meta/example.cpp b/exercises/practice/anagram/.meta/example.cpp index 426a7481c..a18aff962 100644 --- a/exercises/practice/anagram/.meta/example.cpp +++ b/exercises/practice/anagram/.meta/example.cpp @@ -1,50 +1,43 @@ -#include "anagram.h" #include #include +#include "anagram.h" + using namespace std; -namespace -{ +namespace { -string to_lower_copy(string const& s) -{ +string to_lower_copy(string const& s) { string cpy(s); - for (auto& c: cpy) { + for (auto& c : cpy) { c = tolower(c); } return cpy; } -string make_key(string const& s) -{ +string make_key(string const& s) { string key{to_lower_copy(s)}; sort(key.begin(), key.end()); return key; } -} +} // namespace -namespace anagram -{ +namespace anagram { anagram::anagram(string const& subject) - : subject_(subject), - key_(make_key(subject)) -{ -} + : subject_(subject), key_(make_key(subject)) {} -vector anagram::matches(vector const& matches) -{ +vector anagram::matches(vector const& matches) { vector result; for (string const& s : matches) { - if (s.length() == key_.length() - && to_lower_copy(s) != to_lower_copy(subject_) - && make_key(s) == key_) { + if (s.length() == key_.length() && + to_lower_copy(s) != to_lower_copy(subject_) && + make_key(s) == key_) { result.push_back(s); } } return result; } -} +} // namespace anagram diff --git a/exercises/practice/anagram/.meta/example.h b/exercises/practice/anagram/.meta/example.h index cb1f8aa87..a6c63b643 100644 --- a/exercises/practice/anagram/.meta/example.h +++ b/exercises/practice/anagram/.meta/example.h @@ -4,21 +4,19 @@ #include #include -namespace anagram -{ +namespace anagram { -class anagram -{ -public: +class anagram { + public: anagram(std::string const& subject); std::vector matches(std::vector const& matches); -private: + private: std::string const subject_; std::string const key_; }; -} +} // namespace anagram #endif diff --git a/exercises/practice/anagram/anagram.cpp b/exercises/practice/anagram/anagram.cpp index 2aa9f1595..053755f64 100644 --- a/exercises/practice/anagram/anagram.cpp +++ b/exercises/practice/anagram/anagram.cpp @@ -1,5 +1,3 @@ #include "anagram.h" -namespace anagram { - -} // namespace anagram +namespace anagram {} // namespace anagram diff --git a/exercises/practice/anagram/anagram.h b/exercises/practice/anagram/anagram.h index f44775b8c..7ed679e29 100644 --- a/exercises/practice/anagram/anagram.h +++ b/exercises/practice/anagram/anagram.h @@ -1,8 +1,6 @@ #if !defined(ANAGRAM_H) #define ANAGRAM_H -namespace anagram { +namespace anagram {} // namespace anagram -} // namespace anagram - -#endif // ANAGRAM_H \ No newline at end of file +#endif // ANAGRAM_H \ No newline at end of file diff --git a/exercises/practice/anagram/anagram_test.cpp b/exercises/practice/anagram/anagram_test.cpp index b23f5da12..9a94fcc26 100644 --- a/exercises/practice/anagram/anagram_test.cpp +++ b/exercises/practice/anagram/anagram_test.cpp @@ -9,8 +9,7 @@ using namespace std; // Anagram exercise test case data version 1.5.0 -TEST_CASE("no_matches") -{ +TEST_CASE("no_matches") { // 'anagram::anagram' defines a class anagram::anagram subject = anagram::anagram("diaper"); auto matches = subject.matches({"hello", "world", "zombies", "pants"}); @@ -20,8 +19,8 @@ TEST_CASE("no_matches") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("detects_two_anagrams", "[findAnagrams][03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]") -{ +TEST_CASE("detects_two_anagrams", + "[findAnagrams][03eb9bbe-8906-4ea0-84fa-ffe711b52c8b]") { auto subject = anagram::anagram("solemn"); auto matches = subject.matches({"lemons", "cherry", "melons"}); vector expected{"lemons", "melons"}; @@ -29,8 +28,8 @@ TEST_CASE("detects_two_anagrams", "[findAnagrams][03eb9bbe-8906-4ea0-84fa-ffe711 REQUIRE(expected == matches); } -TEST_CASE("does_not_detect_anagram_subsets", "[findAnagrams][a27558ee-9ba0-4552-96b1-ecf665b06556]") -{ +TEST_CASE("does_not_detect_anagram_subsets", + "[findAnagrams][a27558ee-9ba0-4552-96b1-ecf665b06556]") { auto subject = anagram::anagram("good"); auto matches = subject.matches({"dog", "goody"}); vector expected; @@ -38,8 +37,8 @@ TEST_CASE("does_not_detect_anagram_subsets", "[findAnagrams][a27558ee-9ba0-4552- REQUIRE(expected == matches); } -TEST_CASE("detects_anagram", "[findAnagrams][64cd4584-fc15-4781-b633-3d814c4941a4]") -{ +TEST_CASE("detects_anagram", + "[findAnagrams][64cd4584-fc15-4781-b633-3d814c4941a4]") { auto subject = anagram::anagram("listen"); auto matches = subject.matches({"enlists", "google", "inlets", "banana"}); vector expected{"inlets"}; @@ -47,24 +46,18 @@ TEST_CASE("detects_anagram", "[findAnagrams][64cd4584-fc15-4781-b633-3d814c4941a REQUIRE(expected == matches); } -TEST_CASE("detects_three_anagrams", "[findAnagrams][99c91beb-838f-4ccd-b123-935139917283]") -{ +TEST_CASE("detects_three_anagrams", + "[findAnagrams][99c91beb-838f-4ccd-b123-935139917283]") { auto subject = anagram::anagram("allergy"); - auto matches = subject.matches({ - "gallery", - "ballerina", - "regally", - "clergy", - "largely", - "leading" - }); + auto matches = subject.matches( + {"gallery", "ballerina", "regally", "clergy", "largely", "leading"}); vector expected{"gallery", "regally", "largely"}; REQUIRE(expected == matches); } -TEST_CASE("detects_multiple_anagrams_with_different_case", "[findAnagrams][78487770-e258-4e1f-a646-8ece10950d90]") -{ +TEST_CASE("detects_multiple_anagrams_with_different_case", + "[findAnagrams][78487770-e258-4e1f-a646-8ece10950d90]") { auto subject = anagram::anagram("nose"); auto matches = subject.matches({"Eons", "ONES"}); vector expected{"Eons", "ONES"}; @@ -72,8 +65,8 @@ TEST_CASE("detects_multiple_anagrams_with_different_case", "[findAnagrams][78487 REQUIRE(expected == matches); } -TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum", "[findAnagrams][1d0ab8aa-362f-49b7-9902-3d0c668d557b]") -{ +TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum", + "[findAnagrams][1d0ab8aa-362f-49b7-9902-3d0c668d557b]") { auto subject = anagram::anagram("mass"); auto matches = subject.matches({"last"}); vector expected; @@ -81,8 +74,8 @@ TEST_CASE("does_not_detect_non_anagrams_with_identical_checksum", "[findAnagrams REQUIRE(expected == matches); } -TEST_CASE("detects_anagrams_case_insensitively", "[findAnagrams][9e632c0b-c0b1-4804-8cc1-e295dea6d8a8]") -{ +TEST_CASE("detects_anagrams_case_insensitively", + "[findAnagrams][9e632c0b-c0b1-4804-8cc1-e295dea6d8a8]") { auto subject = anagram::anagram("Orchestra"); auto matches = subject.matches({"cashregister", "Carthorse", "radishes"}); vector expected{"Carthorse"}; @@ -90,8 +83,8 @@ TEST_CASE("detects_anagrams_case_insensitively", "[findAnagrams][9e632c0b-c0b1-4 REQUIRE(expected == matches); } -TEST_CASE("detects_anagrams_using_case_insensitive_subject", "[findAnagrams][b248e49f-0905-48d2-9c8d-bd02d8c3e392]") -{ +TEST_CASE("detects_anagrams_using_case_insensitive_subject", + "[findAnagrams][b248e49f-0905-48d2-9c8d-bd02d8c3e392]") { auto subject = anagram::anagram("Orchestra"); auto matches = subject.matches({"cashregister", "carthorse", "radishes"}); vector expected{"carthorse"}; @@ -99,8 +92,8 @@ TEST_CASE("detects_anagrams_using_case_insensitive_subject", "[findAnagrams][b24 REQUIRE(expected == matches); } -TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches", "[findAnagrams][f367325c-78ec-411c-be76-e79047f4bd54]") -{ +TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches", + "[findAnagrams][f367325c-78ec-411c-be76-e79047f4bd54]") { auto subject = anagram::anagram("orchestra"); auto matches = subject.matches({"cashregister", "Carthorse", "radishes"}); vector expected{"Carthorse"}; @@ -108,8 +101,8 @@ TEST_CASE("detects_anagrams_using_case_insensitive_possible_matches", "[findAnag REQUIRE(expected == matches); } -TEST_CASE("does_not_detect_an_anagram_if_the_original_word_is_repeated", "[findAnagrams][630abb71-a94e-4715-8395-179ec1df9f91]") -{ +TEST_CASE("does_not_detect_an_anagram_if_the_original_word_is_repeated", + "[findAnagrams][630abb71-a94e-4715-8395-179ec1df9f91]") { auto subject = anagram::anagram("go"); auto matches = subject.matches({"goGoGO"}); vector expected; @@ -117,8 +110,8 @@ TEST_CASE("does_not_detect_an_anagram_if_the_original_word_is_repeated", "[findA REQUIRE(expected == matches); } -TEST_CASE("anagrams_must_use_all_letters_exactly_once", "[findAnagrams][9878a1c9-d6ea-4235-ae51-3ea2befd6842]") -{ +TEST_CASE("anagrams_must_use_all_letters_exactly_once", + "[findAnagrams][9878a1c9-d6ea-4235-ae51-3ea2befd6842]") { auto subject = anagram::anagram("tapper"); auto matches = subject.matches({"patter"}); vector expected; @@ -126,8 +119,8 @@ TEST_CASE("anagrams_must_use_all_letters_exactly_once", "[findAnagrams][9878a1c9 REQUIRE(expected == matches); } -TEST_CASE("words_are_not_anagrams_of_themselves", "[findAnagrams][68934ed0-010b-4ef9-857a-20c9012d1ebf]") -{ +TEST_CASE("words_are_not_anagrams_of_themselves", + "[findAnagrams][68934ed0-010b-4ef9-857a-20c9012d1ebf]") { auto subject = anagram::anagram("BANANA"); auto matches = subject.matches({"BANANA"}); vector expected; @@ -135,8 +128,11 @@ TEST_CASE("words_are_not_anagrams_of_themselves", "[findAnagrams][68934ed0-010b- REQUIRE(expected == matches); } -TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different", "[findAnagrams][589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]") -{ +TEST_CASE( + // clang-format off + "words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different", + // clang-format on + "[findAnagrams][589384f3-4c8a-4e7d-9edc-51c3e5f0c90e]") { auto subject = anagram::anagram("BANANA"); auto matches = subject.matches({"Banana"}); vector expected; @@ -144,8 +140,11 @@ TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially REQUIRE(expected == matches); } -TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different", "[findAnagrams][ba53e423-7e02-41ee-9ae2-71f91e6d18e6]") -{ +TEST_CASE( + // clang-format off + "words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different", + // clang-format on + "[findAnagrams][ba53e423-7e02-41ee-9ae2-71f91e6d18e6]") { auto subject = anagram::anagram("BANANA"); auto matches = subject.matches({"banana"}); vector expected; @@ -153,8 +152,8 @@ TEST_CASE("words_are_not_anagrams_of_themselves_even_if_letter_case_is_completel REQUIRE(expected == matches); } -TEST_CASE("words_other_than_themselves_can_be_anagrams", "[findAnagrams][33d3f67e-fbb9-49d3-a90e-0beb00861da7]") -{ +TEST_CASE("words_other_than_themselves_can_be_anagrams", + "[findAnagrams][33d3f67e-fbb9-49d3-a90e-0beb00861da7]") { auto subject = anagram::anagram("LISTEN"); auto matches = subject.matches({"Silent", "LISTEN"}); vector expected{"Silent"}; diff --git a/exercises/practice/armstrong-numbers/.meta/example.h b/exercises/practice/armstrong-numbers/.meta/example.h index 2a24233d6..1ac6f08ee 100644 --- a/exercises/practice/armstrong-numbers/.meta/example.h +++ b/exercises/practice/armstrong-numbers/.meta/example.h @@ -5,6 +5,6 @@ namespace armstrong_numbers { bool is_armstrong_number(int number); -} // namespace armstrong_numbers +} // namespace armstrong_numbers -#endif // !ARMSTRONG_NUMBERS_H_ \ No newline at end of file +#endif // !ARMSTRONG_NUMBERS_H_ \ No newline at end of file diff --git a/exercises/practice/armstrong-numbers/armstrong_numbers.cpp b/exercises/practice/armstrong-numbers/armstrong_numbers.cpp index 3f3d0a4f8..3e0442272 100644 --- a/exercises/practice/armstrong-numbers/armstrong_numbers.cpp +++ b/exercises/practice/armstrong-numbers/armstrong_numbers.cpp @@ -1,5 +1,3 @@ #include "armstrong_numbers.h" -namespace armstrong_numbers { - -} // namespace armstrong_numbers +namespace armstrong_numbers {} // namespace armstrong_numbers diff --git a/exercises/practice/armstrong-numbers/armstrong_numbers.h b/exercises/practice/armstrong-numbers/armstrong_numbers.h index 6ac175358..5a19be08a 100644 --- a/exercises/practice/armstrong-numbers/armstrong_numbers.h +++ b/exercises/practice/armstrong-numbers/armstrong_numbers.h @@ -1,8 +1,6 @@ #if !defined(ARMSTRONG_NUMBERS_H) #define ARMSTRONG_NUMBERS_H -namespace armstrong_numbers { +namespace armstrong_numbers {} // namespace armstrong_numbers -} // namespace armstrong_numbers - -#endif // ARMSTRONG_NUMBERS_H \ No newline at end of file +#endif // ARMSTRONG_NUMBERS_H \ No newline at end of file diff --git a/exercises/practice/armstrong-numbers/armstrong_numbers_test.cpp b/exercises/practice/armstrong-numbers/armstrong_numbers_test.cpp index aa95c47b9..8db31c23c 100644 --- a/exercises/practice/armstrong-numbers/armstrong_numbers_test.cpp +++ b/exercises/practice/armstrong-numbers/armstrong_numbers_test.cpp @@ -7,49 +7,40 @@ // Armstrong-numbers exercise test case data version 1.1.0 -TEST_CASE("zero_is_an_armstrong_number") -{ +TEST_CASE("zero_is_an_armstrong_number") { REQUIRE(armstrong_numbers::is_armstrong_number(0)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("single_digit_numbers_are_armstrong_numbers") -{ +TEST_CASE("single_digit_numbers_are_armstrong_numbers") { REQUIRE(armstrong_numbers::is_armstrong_number(5)); } -TEST_CASE("there_are_no_2_digit_armstrong_numbers") -{ +TEST_CASE("there_are_no_2_digit_armstrong_numbers") { REQUIRE_FALSE(armstrong_numbers::is_armstrong_number(10)); } -TEST_CASE("three_digit_number_that_is_an_armstrong_number") -{ +TEST_CASE("three_digit_number_that_is_an_armstrong_number") { REQUIRE(armstrong_numbers::is_armstrong_number(153)); } -TEST_CASE("three_digit_number_that_is_not_an_armstrong_number") -{ +TEST_CASE("three_digit_number_that_is_not_an_armstrong_number") { REQUIRE_FALSE(armstrong_numbers::is_armstrong_number(100)); } -TEST_CASE("four_digit_number_that_is_an_armstrong_number") -{ +TEST_CASE("four_digit_number_that_is_an_armstrong_number") { REQUIRE(armstrong_numbers::is_armstrong_number(9474)); } -TEST_CASE("four_digit_number_that_is_not_an_armstrong_number") -{ +TEST_CASE("four_digit_number_that_is_not_an_armstrong_number") { REQUIRE_FALSE(armstrong_numbers::is_armstrong_number(9475)); } -TEST_CASE("seven_digit_number_that_is_an_armstrong_number") -{ +TEST_CASE("seven_digit_number_that_is_an_armstrong_number") { REQUIRE(armstrong_numbers::is_armstrong_number(9926315)); } -TEST_CASE("seven_digit_number_that_is_not_an_armstrong_number") -{ +TEST_CASE("seven_digit_number_that_is_not_an_armstrong_number") { REQUIRE_FALSE(armstrong_numbers::is_armstrong_number(9926314)); } -#endif // !EXERCISM_RUN_ALL_TESTS \ No newline at end of file +#endif // !EXERCISM_RUN_ALL_TESTS \ No newline at end of file diff --git a/exercises/practice/atbash-cipher/.meta/example.cpp b/exercises/practice/atbash-cipher/.meta/example.cpp index bdf615ac9..d3d7dd816 100644 --- a/exercises/practice/atbash-cipher/.meta/example.cpp +++ b/exercises/practice/atbash-cipher/.meta/example.cpp @@ -8,25 +8,23 @@ namespace atbash_cipher { const char ALPHA_START = 'a'; const char ALPHA_END = 'z'; -char atbash_transform(char c) -{ +char atbash_transform(char c) { return std::isalpha(c) ? ALPHA_END - std::tolower(c) + ALPHA_START : c; } -std::string encode(std::string const& plaintext) -{ +std::string encode(std::string const& plaintext) { int chunkSize = 5; int chunkCounter = 0; std::ostringstream os; - for(std::size_t i = 0; i < plaintext.length(); i++) { + for (std::size_t i = 0; i < plaintext.length(); i++) { char currentChar = plaintext.at(i); if (std::isalnum(currentChar)) { if ((chunkCounter > 0) && ((chunkCounter) % chunkSize == 0)) { os << " "; } - + os << atbash_transform(currentChar); chunkCounter++; } @@ -35,11 +33,10 @@ std::string encode(std::string const& plaintext) return os.str(); } -std::string decode(std::string const& ciphertext) -{ +std::string decode(std::string const& ciphertext) { std::ostringstream os; - for(std::size_t i = 0; i < ciphertext.length(); i++) { + for (std::size_t i = 0; i < ciphertext.length(); i++) { char currentChar = ciphertext.at(i); if (std::isalnum(currentChar)) { @@ -50,5 +47,4 @@ std::string decode(std::string const& ciphertext) return os.str(); } -} - +} // namespace atbash_cipher diff --git a/exercises/practice/atbash-cipher/.meta/example.h b/exercises/practice/atbash-cipher/.meta/example.h index 2e34bc138..0c0f36754 100644 --- a/exercises/practice/atbash-cipher/.meta/example.h +++ b/exercises/practice/atbash-cipher/.meta/example.h @@ -3,11 +3,10 @@ #include -namespace atbash_cipher -{ +namespace atbash_cipher { std::string encode(std::string const& plaintext); std::string decode(std::string const& ciphertext); -} +} // namespace atbash_cipher #endif diff --git a/exercises/practice/atbash-cipher/atbash_cipher.cpp b/exercises/practice/atbash-cipher/atbash_cipher.cpp index e6f4d0648..a9f3c79fb 100644 --- a/exercises/practice/atbash-cipher/atbash_cipher.cpp +++ b/exercises/practice/atbash-cipher/atbash_cipher.cpp @@ -1,5 +1,3 @@ #include "atbash_cipher.h" -namespace atbash_cipher { - -} // namespace atbash_cipher +namespace atbash_cipher {} // namespace atbash_cipher diff --git a/exercises/practice/atbash-cipher/atbash_cipher.h b/exercises/practice/atbash-cipher/atbash_cipher.h index fd7ac80fb..4d195e50b 100644 --- a/exercises/practice/atbash-cipher/atbash_cipher.h +++ b/exercises/practice/atbash-cipher/atbash_cipher.h @@ -1,8 +1,6 @@ #if !defined(ATBASH_CIPHER_H) #define ATBASH_CIPHER_H -namespace atbash_cipher { +namespace atbash_cipher {} // namespace atbash_cipher -} // namespace atbash_cipher - -#endif // ATBASH_CIPHER_H \ No newline at end of file +#endif // ATBASH_CIPHER_H \ No newline at end of file diff --git a/exercises/practice/atbash-cipher/atbash_cipher_test.cpp b/exercises/practice/atbash-cipher/atbash_cipher_test.cpp index 321b9e632..8e2a5eb67 100644 --- a/exercises/practice/atbash-cipher/atbash_cipher_test.cpp +++ b/exercises/practice/atbash-cipher/atbash_cipher_test.cpp @@ -5,67 +5,50 @@ #include "test/catch.hpp" #endif -TEST_CASE("encode_yes") -{ - REQUIRE("bvh" == atbash_cipher::encode("yes")); -} +TEST_CASE("encode_yes") { REQUIRE("bvh" == atbash_cipher::encode("yes")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("encode_no") -{ - REQUIRE("ml" == atbash_cipher::encode("no")); -} +TEST_CASE("encode_no") { REQUIRE("ml" == atbash_cipher::encode("no")); } -TEST_CASE("encode_OMG") -{ - REQUIRE("lnt" == atbash_cipher::encode("OMG")); -} +TEST_CASE("encode_OMG") { REQUIRE("lnt" == atbash_cipher::encode("OMG")); } -TEST_CASE("encode_spaces") -{ - REQUIRE("lnt" == atbash_cipher::encode("O M G")); -} +TEST_CASE("encode_spaces") { REQUIRE("lnt" == atbash_cipher::encode("O M G")); } -TEST_CASE("encode_mindblowingly") -{ +TEST_CASE("encode_mindblowingly") { REQUIRE("nrmwy oldrm tob" == atbash_cipher::encode("mindblowingly")); } -TEST_CASE("encode_numbers") -{ - REQUIRE("gvhgr mt123 gvhgr mt" == atbash_cipher::encode("Testing,1 2 3, testing.")); +TEST_CASE("encode_numbers") { + REQUIRE("gvhgr mt123 gvhgr mt" == + atbash_cipher::encode("Testing,1 2 3, testing.")); } -TEST_CASE("encode_deep_thought") -{ +TEST_CASE("encode_deep_thought") { REQUIRE("gifgs rhurx grlm" == atbash_cipher::encode("Truth is fiction.")); } -TEST_CASE("encode_all_the_letters") -{ - REQUIRE("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" == - atbash_cipher::encode("The quick brown fox jumps over the lazy dog.")); +TEST_CASE("encode_all_the_letters") { + REQUIRE( + "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" == + atbash_cipher::encode("The quick brown fox jumps over the lazy dog.")); } -TEST_CASE("decode_exercism") -{ +TEST_CASE("decode_exercism") { REQUIRE("exercism" == atbash_cipher::decode("vcvix rhn")); } -TEST_CASE("decode_a_sentence") -{ +TEST_CASE("decode_a_sentence") { REQUIRE("anobstacleisoftenasteppingstone" == - atbash_cipher::decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v")); + atbash_cipher::decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v")); } -TEST_CASE("decode_numbers") -{ - REQUIRE("testing123testing" == atbash_cipher::decode("gvhgr mt123 gvhgr mt")); +TEST_CASE("decode_numbers") { + REQUIRE("testing123testing" == + atbash_cipher::decode("gvhgr mt123 gvhgr mt")); } -TEST_CASE("decode_all_the_letters") -{ +TEST_CASE("decode_all_the_letters") { REQUIRE("thequickbrownfoxjumpsoverthelazydog" == - atbash_cipher::decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")); + atbash_cipher::decode("gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt")); } #endif diff --git a/exercises/practice/bank-account/.meta/example.cpp b/exercises/practice/bank-account/.meta/example.cpp index 12ffbc6f2..c0c35f4bc 100644 --- a/exercises/practice/bank-account/.meta/example.cpp +++ b/exercises/practice/bank-account/.meta/example.cpp @@ -1,7 +1,7 @@ -#include "bank_account.h" - #include +#include "bank_account.h" + namespace Bankaccount { void Bankaccount::open() { if (open_) { diff --git a/exercises/practice/bank-account/bank_account_test.cpp b/exercises/practice/bank-account/bank_account_test.cpp index 07ea90108..32f8aed84 100644 --- a/exercises/practice/bank-account/bank_account_test.cpp +++ b/exercises/practice/bank-account/bank_account_test.cpp @@ -8,7 +8,8 @@ #include #include -TEST_CASE("Newly opened account has zero balance", "[983a1528-4ceb-45e5-8257-8ce01aceb5ed]") { +TEST_CASE("Newly opened account has zero balance", + "[983a1528-4ceb-45e5-8257-8ce01aceb5ed]") { Bankaccount::Bankaccount account{}; account.open(); REQUIRE(account.balance() == 0); @@ -47,7 +48,8 @@ TEST_CASE("Withdraw twice", "[6f6d242f-8c31-4ac6-8995-a90d42cad59f]") { REQUIRE(account.balance() == 0); } -TEST_CASE("Can do multiple operations sequentially", "[45161c94-a094-4c77-9cec-998b70429bda]") { +TEST_CASE("Can do multiple operations sequentially", + "[45161c94-a094-4c77-9cec-998b70429bda]") { Bankaccount::Bankaccount account{}; account.open(); account.deposit(100); @@ -58,7 +60,8 @@ TEST_CASE("Can do multiple operations sequentially", "[45161c94-a094-4c77-9cec-9 REQUIRE(account.balance() == 20); } -TEST_CASE("annot check balance of closed account", "[f9facfaa-d824-486e-8381-48832c4bbffd]") { +TEST_CASE("annot check balance of closed account", + "[f9facfaa-d824-486e-8381-48832c4bbffd]") { Bankaccount::Bankaccount account{}; account.open(); account.close(); @@ -66,7 +69,8 @@ TEST_CASE("annot check balance of closed account", "[f9facfaa-d824-486e-8381-488 REQUIRE_THROWS_AS(account.balance(), std::runtime_error); } -TEST_CASE("Cannot deposit into closed account", "[7a65ba52-e35c-4fd2-8159-bda2bde6e59c]") { +TEST_CASE("Cannot deposit into closed account", + "[7a65ba52-e35c-4fd2-8159-bda2bde6e59c]") { Bankaccount::Bankaccount account{}; account.open(); account.close(); @@ -74,12 +78,14 @@ TEST_CASE("Cannot deposit into closed account", "[7a65ba52-e35c-4fd2-8159-bda2bd REQUIRE_THROWS_AS(account.deposit(50), std::runtime_error); } -TEST_CASE("Cannot deposit into unopened account", "[a0a1835d-faae-4ad4-a6f3-1fcc2121380b]") { +TEST_CASE("Cannot deposit into unopened account", + "[a0a1835d-faae-4ad4-a6f3-1fcc2121380b]") { Bankaccount::Bankaccount account{}; REQUIRE_THROWS_AS(account.deposit(50), std::runtime_error); } -TEST_CASE("Cannot withdraw from closed account", "[570dfaa5-0532-4c1f-a7d3-0f65c3265608]") { +TEST_CASE("Cannot withdraw from closed account", + "[570dfaa5-0532-4c1f-a7d3-0f65c3265608]") { Bankaccount::Bankaccount account{}; account.open(); account.close(); @@ -87,21 +93,23 @@ TEST_CASE("Cannot withdraw from closed account", "[570dfaa5-0532-4c1f-a7d3-0f65c REQUIRE_THROWS_AS(account.withdraw(50), std::runtime_error); } -TEST_CASE("Cannot close an account that was not opened", "[c396d233-1c49-4272-98dc-7f502dbb9470]") { +TEST_CASE("Cannot close an account that was not opened", + "[c396d233-1c49-4272-98dc-7f502dbb9470]") { Bankaccount::Bankaccount account; REQUIRE_THROWS_AS(account.close(), std::runtime_error); } -TEST_CASE("Cannot open an already opened account", "[c06f534f-bdc2-4a02-a388-1063400684de]") { +TEST_CASE("Cannot open an already opened account", + "[c06f534f-bdc2-4a02-a388-1063400684de]") { Bankaccount::Bankaccount account; account.open(); REQUIRE_THROWS_AS(account.open(), std::runtime_error); } - -TEST_CASE("Reopened account does not retain balance", "[0722d404-6116-4f92-ba3b-da7f88f1669c]") { +TEST_CASE("Reopened account does not retain balance", + "[0722d404-6116-4f92-ba3b-da7f88f1669c]") { Bankaccount::Bankaccount account; account.open(); account.deposit(50); @@ -111,7 +119,8 @@ TEST_CASE("Reopened account does not retain balance", "[0722d404-6116-4f92-ba3b- REQUIRE(account.balance() == 0); } -TEST_CASE("Cannot withdraw more than deposited", "[ec42245f-9361-4341-8231-a22e8d19c52f]") { +TEST_CASE("Cannot withdraw more than deposited", + "[ec42245f-9361-4341-8231-a22e8d19c52f]") { Bankaccount::Bankaccount account; account.open(); account.deposit(25); @@ -119,7 +128,8 @@ TEST_CASE("Cannot withdraw more than deposited", "[ec42245f-9361-4341-8231-a22e8 REQUIRE_THROWS_AS(account.withdraw(50), std::runtime_error); } -TEST_CASE("Cannot withdraw negative", "[4f381ef8-10ef-4507-8e1d-0631ecc8ee72]") { +TEST_CASE("Cannot withdraw negative", + "[4f381ef8-10ef-4507-8e1d-0631ecc8ee72]") { Bankaccount::Bankaccount account; account.open(); account.deposit(100); @@ -133,7 +143,8 @@ TEST_CASE("Cannot deposit negative", "[d45df9ea-1db0-47f3-b18c-d365db49d938]") { REQUIRE_THROWS_AS(account.deposit(-50), std::runtime_error); } -TEST_CASE("Can handle concurrent transactions", "[ba0c1e0b-0f00-416f-8097-a7dfc97871ff]") { +TEST_CASE("Can handle concurrent transactions", + "[ba0c1e0b-0f00-416f-8097-a7dfc97871ff]") { Bankaccount::Bankaccount account; account.open(); diff --git a/exercises/practice/beer-song/.meta/example.cpp b/exercises/practice/beer-song/.meta/example.cpp index 03c5fb6ca..2509d7879 100644 --- a/exercises/practice/beer-song/.meta/example.cpp +++ b/exercises/practice/beer-song/.meta/example.cpp @@ -1,26 +1,20 @@ -#include "beer_song.h" #include +#include "beer_song.h" + using namespace std; -namespace beer_song -{ +namespace beer_song { -namespace -{ +namespace { -struct bottles -{ - bottles(unsigned num) - : count(num), - suffix(num > 1 ? "s" : "") - {} +struct bottles { + bottles(unsigned num) : count(num), suffix(num > 1 ? "s" : "") {} unsigned const count; string const suffix; }; -ostream& operator<<(ostream& stream, bottles const& b) -{ +ostream& operator<<(ostream& stream, bottles const& b) { if (b.count) { stream << b.count << " bottle" << b.suffix; } else { @@ -29,43 +23,42 @@ ostream& operator<<(ostream& stream, bottles const& b) return stream << " of beer"; } -void bottles_of_beer_on_the_wall(ostream& stream, unsigned count) -{ +void bottles_of_beer_on_the_wall(ostream& stream, unsigned count) { if (count) { stream << bottles(count) << " on the wall, " << bottles(count) << ".\n"; } else { - stream << "No more bottles of beer on the wall, " << bottles(count) << ".\n"; + stream << "No more bottles of beer on the wall, " << bottles(count) + << ".\n"; } } -void take_one_down_and_pass_it_around(ostream& stream, unsigned count) -{ +void take_one_down_and_pass_it_around(ostream& stream, unsigned count) { if (count > 1) { - stream << "Take one down and pass it around, " << bottles(count - 1) << " on the wall.\n"; + stream << "Take one down and pass it around, " << bottles(count - 1) + << " on the wall.\n"; } else if (count) { - stream << "Take it down and pass it around, " << bottles(count - 1) << " on the wall.\n"; + stream << "Take it down and pass it around, " << bottles(count - 1) + << " on the wall.\n"; } else { - stream << "Go to the store and buy some more, 99 bottles of beer on the wall.\n"; + stream << "Go to the store and buy some more, 99 bottles of beer on " + "the wall.\n"; } } -void verse(ostream& stream, unsigned count) -{ +void verse(ostream& stream, unsigned count) { bottles_of_beer_on_the_wall(stream, count); take_one_down_and_pass_it_around(stream, count); } -} +} // namespace -string verse(unsigned num) -{ +string verse(unsigned num) { ostringstream stream; verse(stream, num); return stream.str(); } -string sing(unsigned begin, unsigned end) -{ +string sing(unsigned begin, unsigned end) { ostringstream stream; for (unsigned num = begin; num > end; --num) { verse(stream, num); @@ -75,9 +68,6 @@ string sing(unsigned begin, unsigned end) return stream.str(); } -string sing(unsigned num) -{ - return sing(num, 0); -} +string sing(unsigned num) { return sing(num, 0); } -} +} // namespace beer_song diff --git a/exercises/practice/beer-song/.meta/example.h b/exercises/practice/beer-song/.meta/example.h index 2d351c1e9..fdc47dc2b 100644 --- a/exercises/practice/beer-song/.meta/example.h +++ b/exercises/practice/beer-song/.meta/example.h @@ -3,13 +3,12 @@ #include -namespace beer_song -{ +namespace beer_song { std::string verse(unsigned bottles); std::string sing(unsigned begin, unsigned end); std::string sing(unsigned bottles); -} +} // namespace beer_song #endif diff --git a/exercises/practice/beer-song/beer_song.cpp b/exercises/practice/beer-song/beer_song.cpp index 83cdf26b7..e97c3743c 100644 --- a/exercises/practice/beer-song/beer_song.cpp +++ b/exercises/practice/beer-song/beer_song.cpp @@ -1,5 +1,3 @@ #include "beer_song.h" -namespace beer_song { - -} // namespace beer_song +namespace beer_song {} // namespace beer_song diff --git a/exercises/practice/beer-song/beer_song.h b/exercises/practice/beer-song/beer_song.h index b266e6256..c0ac8177c 100644 --- a/exercises/practice/beer-song/beer_song.h +++ b/exercises/practice/beer-song/beer_song.h @@ -1,8 +1,6 @@ #if !defined(BEER_SONG_H) #define BEER_SONG_H -namespace beer_song { +namespace beer_song {} // namespace beer_song -} // namespace beer_song - -#endif // BEER_SONG_H \ No newline at end of file +#endif // BEER_SONG_H \ No newline at end of file diff --git a/exercises/practice/beer-song/beer_song_test.cpp b/exercises/practice/beer-song/beer_song_test.cpp index b58ef5640..226c89394 100644 --- a/exercises/practice/beer-song/beer_song_test.cpp +++ b/exercises/practice/beer-song/beer_song_test.cpp @@ -7,34 +7,35 @@ using namespace std; -TEST_CASE("prints_an_arbitrary_verse") -{ - string expected = "8 bottles of beer on the wall, 8 bottles of beer.\n" +TEST_CASE("prints_an_arbitrary_verse") { + string expected = + "8 bottles of beer on the wall, 8 bottles of beer.\n" "Take one down and pass it around, 7 bottles of beer on the wall.\n"; REQUIRE(expected == beer_song::verse(8)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("handles_1_bottle") -{ - string expected = "1 bottle of beer on the wall, 1 bottle of beer.\n" - "Take it down and pass it around, no more bottles of beer on the wall.\n"; +TEST_CASE("handles_1_bottle") { + string expected = + "1 bottle of beer on the wall, 1 bottle of beer.\n" + "Take it down and pass it around, no more bottles of beer on the " + "wall.\n"; REQUIRE(expected == beer_song::verse(1)); } -TEST_CASE("handles_0_bottles") -{ - string expected = "No more bottles of beer on the wall, no more bottles of beer.\n" +TEST_CASE("handles_0_bottles") { + string expected = + "No more bottles of beer on the wall, no more bottles of beer.\n" "Go to the store and buy some more, 99 bottles of beer on the wall.\n"; REQUIRE(expected == beer_song::verse(0)); } -TEST_CASE("sings_several_verses") -{ - string expected = "8 bottles of beer on the wall, 8 bottles of beer.\n" +TEST_CASE("sings_several_verses") { + string expected = + "8 bottles of beer on the wall, 8 bottles of beer.\n" "Take one down and pass it around, 7 bottles of beer on the wall.\n" "\n" "7 bottles of beer on the wall, 7 bottles of beer.\n" @@ -46,16 +47,17 @@ TEST_CASE("sings_several_verses") REQUIRE(expected == beer_song::sing(8, 6)); } -TEST_CASE("sings_the_rest_of_the_verses") -{ - string expected = "3 bottles of beer on the wall, 3 bottles of beer.\n" +TEST_CASE("sings_the_rest_of_the_verses") { + string expected = + "3 bottles of beer on the wall, 3 bottles of beer.\n" "Take one down and pass it around, 2 bottles of beer on the wall.\n" "\n" "2 bottles of beer on the wall, 2 bottles of beer.\n" "Take one down and pass it around, 1 bottle of beer on the wall.\n" "\n" "1 bottle of beer on the wall, 1 bottle of beer.\n" - "Take it down and pass it around, no more bottles of beer on the wall.\n" + "Take it down and pass it around, no more bottles of beer on the " + "wall.\n" "\n" "No more bottles of beer on the wall, no more bottles of beer.\n" "Go to the store and buy some more, 99 bottles of beer on the wall.\n"; diff --git a/exercises/practice/binary-search-tree/.meta/example.h b/exercises/practice/binary-search-tree/.meta/example.h index be11e75fe..d0ad7afbe 100644 --- a/exercises/practice/binary-search-tree/.meta/example.h +++ b/exercises/practice/binary-search-tree/.meta/example.h @@ -1,173 +1,161 @@ #if !defined(_BINARY_SEARCH_TREE_H_) #define _BINARY_SEARCH_TREE_H_ -#include #include -#include +#include #include +#include -namespace binary_search_tree -{ - template - using enable_if_t = typename std::enable_if::type; - template - using remove_reference_t = typename std::remove_reference::type; - - template - class binary_tree final - { - public: - class binary_tree_iter; - using binary_tree_ptr = std::unique_ptr; - - template >::value>> - explicit binary_tree(TParam &&data) - : _data(std::forward(data)), - _left(nullptr), - _right(nullptr) - {} - - ~binary_tree() = default; - - binary_tree(binary_tree &) = delete; - binary_tree& operator=(binary_tree &) = delete; - - binary_tree(binary_tree &&) = delete; - binary_tree&& operator=(binary_tree &&) = delete; - - public: - template >::value>> - void insert(TParam &&data); - - const T &data() const {return _data;}; - const binary_tree_ptr& left() const {return _left;}; - const binary_tree_ptr& right() const {return _right;}; - - binary_tree_iter begin() const; - binary_tree_iter end() const; - - private: - T _data; - binary_tree_ptr _left; - binary_tree_ptr _right; - - public: - class binary_tree_iter final - { - friend binary_tree_iter binary_tree::begin() const; - friend binary_tree_iter binary_tree::end() const; - public: - using binary_tree_iter_ptr = std::unique_ptr; - private: - enum class state - { - LEFT, - RIGHT, - MIDDLE, - DONE - }; - - explicit binary_tree_iter(const binary_tree &tree); - static binary_tree_iter build_end_iterator(const binary_tree &tree); - - public: - ~binary_tree_iter() = default; - - binary_tree_iter(binary_tree_iter &) = delete; - binary_tree_iter & operator=(binary_tree_iter &) = delete; - - binary_tree_iter(binary_tree_iter &&) = default; - binary_tree_iter & operator=(binary_tree_iter &&) = default; - - const T& operator*() const; - const T* operator->() const; - binary_tree_iter& operator++(); - - bool operator==(const binary_tree_iter &) const; - bool operator!=(const binary_tree_iter &) const; - - private: - void advance_branch_iter(state next_state); - static binary_tree_iter_ptr build_first_branch_iter(const binary_tree &tree); - static binary_tree_iter_ptr copy_branch_iter(const binary_tree_iter &other); - - const binary_tree &_tree; - state _state; - binary_tree_iter_ptr _branch_iter; - }; - }; +namespace binary_search_tree { +template +using enable_if_t = typename std::enable_if::type; +template +using remove_reference_t = typename std::remove_reference::type; - // tree - - template - template - void binary_tree::insert(TParam &&data) - { - binary_tree_ptr &insert_location = data > _data ? _right : _left; - if (!insert_location) - insert_location = binary_tree_ptr(new binary_tree(std::forward(data))); - else - insert_location->insert(std::forward(data)); - } +template +class binary_tree final { + public: + class binary_tree_iter; + using binary_tree_ptr = std::unique_ptr; - template - typename binary_tree::binary_tree_iter binary_tree::begin() const {return binary_tree_iter(*this);} - template - typename binary_tree::binary_tree_iter binary_tree::end() const {return binary_tree_iter::build_end_iterator(*this);} + template >::value>> + explicit binary_tree(TParam &&data) + : _data(std::forward(data)), _left(nullptr), _right(nullptr) {} + ~binary_tree() = default; - // iter - template - binary_tree::binary_tree_iter::binary_tree_iter(const binary_tree &tree) - : _tree(tree), - _branch_iter(build_first_branch_iter(tree)) - { - _state = _tree.left() ? state::LEFT : state::MIDDLE; - } + binary_tree(binary_tree &) = delete; + binary_tree &operator=(binary_tree &) = delete; - template - typename binary_tree::binary_tree_iter::binary_tree_iter_ptr binary_tree::binary_tree_iter::build_first_branch_iter(const binary_tree &tree) - { - if (!tree.left()) - return nullptr; - return binary_tree_iter_ptr(new binary_tree_iter(*tree.left())); - } + binary_tree(binary_tree &&) = delete; + binary_tree &&operator=(binary_tree &&) = delete; + public: + template >::value>> + void insert(TParam &&data); - template - typename binary_tree::binary_tree_iter binary_tree::binary_tree_iter::build_end_iterator(const binary_tree &tree) - { - binary_tree_iter iter(tree); - iter._branch_iter.reset(nullptr); - iter._state = state::DONE; + const T &data() const { return _data; }; + const binary_tree_ptr &left() const { return _left; }; + const binary_tree_ptr &right() const { return _right; }; - return iter; - } + binary_tree_iter begin() const; + binary_tree_iter end() const; - template - bool binary_tree::binary_tree_iter::operator==(const binary_tree::binary_tree_iter &other) const - { - if (&_tree != &other._tree) - return false; - if (_state != other._state) - return false; - return _branch_iter == other._branch_iter; - } + private: + T _data; + binary_tree_ptr _left; + binary_tree_ptr _right; + public: + class binary_tree_iter final { + friend binary_tree_iter binary_tree::begin() const; + friend binary_tree_iter binary_tree::end() const; - template - bool binary_tree::binary_tree_iter::operator!=(const binary_tree_iter &other) const - { - return !(*this == other); - } + public: + using binary_tree_iter_ptr = std::unique_ptr; + + private: + enum class state { LEFT, RIGHT, MIDDLE, DONE }; + + explicit binary_tree_iter(const binary_tree &tree); + static binary_tree_iter build_end_iterator(const binary_tree &tree); + + public: + ~binary_tree_iter() = default; + + binary_tree_iter(binary_tree_iter &) = delete; + binary_tree_iter &operator=(binary_tree_iter &) = delete; + + binary_tree_iter(binary_tree_iter &&) = default; + binary_tree_iter &operator=(binary_tree_iter &&) = default; + + const T &operator*() const; + const T *operator->() const; + binary_tree_iter &operator++(); + + bool operator==(const binary_tree_iter &) const; + bool operator!=(const binary_tree_iter &) const; + + private: + void advance_branch_iter(state next_state); + static binary_tree_iter_ptr build_first_branch_iter( + const binary_tree &tree); + static binary_tree_iter_ptr copy_branch_iter( + const binary_tree_iter &other); + + const binary_tree &_tree; + state _state; + binary_tree_iter_ptr _branch_iter; + }; +}; + +// tree + +template +template +void binary_tree::insert(TParam &&data) { + binary_tree_ptr &insert_location = data > _data ? _right : _left; + if (!insert_location) + insert_location = + binary_tree_ptr(new binary_tree(std::forward(data))); + else + insert_location->insert(std::forward(data)); +} - template - const T& binary_tree::binary_tree_iter::operator*() const - { - switch (_state) - { +template +typename binary_tree::binary_tree_iter binary_tree::begin() const { + return binary_tree_iter(*this); +} +template +typename binary_tree::binary_tree_iter binary_tree::end() const { + return binary_tree_iter::build_end_iterator(*this); +} + +// iter +template +binary_tree::binary_tree_iter::binary_tree_iter(const binary_tree &tree) + : _tree(tree), _branch_iter(build_first_branch_iter(tree)) { + _state = _tree.left() ? state::LEFT : state::MIDDLE; +} + +template +typename binary_tree::binary_tree_iter::binary_tree_iter_ptr +binary_tree::binary_tree_iter::build_first_branch_iter( + const binary_tree &tree) { + if (!tree.left()) return nullptr; + return binary_tree_iter_ptr(new binary_tree_iter(*tree.left())); +} + +template +typename binary_tree::binary_tree_iter +binary_tree::binary_tree_iter::build_end_iterator( + const binary_tree &tree) { + binary_tree_iter iter(tree); + iter._branch_iter.reset(nullptr); + iter._state = state::DONE; + + return iter; +} + +template +bool binary_tree::binary_tree_iter::operator==( + const binary_tree::binary_tree_iter &other) const { + if (&_tree != &other._tree) return false; + if (_state != other._state) return false; + return _branch_iter == other._branch_iter; +} + +template +bool binary_tree::binary_tree_iter::operator!=( + const binary_tree_iter &other) const { + return !(*this == other); +} + +template +const T &binary_tree::binary_tree_iter::operator*() const { + switch (_state) { case state::DONE: throw std::out_of_range("Access of iterator after end"); case state::MIDDLE: @@ -177,30 +165,28 @@ namespace binary_search_tree return _branch_iter->operator*(); default: throw std::logic_error("Missing switch value"); - } } +} - template - const T* binary_tree::binary_tree_iter::operator->() const - { - return &this->operator*(); - } +template +const T *binary_tree::binary_tree_iter::operator->() const { + return &this->operator*(); +} - template - typename binary_tree::binary_tree_iter& binary_tree::binary_tree_iter::operator++() - { - switch (_state) - { +template +typename binary_tree::binary_tree_iter & +binary_tree::binary_tree_iter::operator++() { + switch (_state) { case state::DONE: throw std::out_of_range("Cannot advance iterator after end"); case state::MIDDLE: - if (!_tree.right()) - { + if (!_tree.right()) { _state = state::DONE; break; } _state = state::RIGHT; - _branch_iter = binary_tree_iter_ptr(new binary_tree_iter(*_tree.right())); + _branch_iter = + binary_tree_iter_ptr(new binary_tree_iter(*_tree.right())); break; case state::LEFT: advance_branch_iter(state::MIDDLE); @@ -210,22 +196,20 @@ namespace binary_search_tree break; default: throw std::logic_error("Missing switch value"); - } - - return *this; } - template - void binary_tree::binary_tree_iter::advance_branch_iter(state next_state) - { - _branch_iter->operator++(); - if (_branch_iter->_state == state::DONE) - { - _branch_iter.reset(nullptr); - _state = next_state; - } - } + return *this; +} +template +void binary_tree::binary_tree_iter::advance_branch_iter(state next_state) { + _branch_iter->operator++(); + if (_branch_iter->_state == state::DONE) { + _branch_iter.reset(nullptr); + _state = next_state; + } } -#endif // _BINARY_SEARCH_TREE_H_ +} // namespace binary_search_tree + +#endif // _BINARY_SEARCH_TREE_H_ diff --git a/exercises/practice/binary-search-tree/binary_search_tree.cpp b/exercises/practice/binary-search-tree/binary_search_tree.cpp index 6c58c82c0..b9751123b 100644 --- a/exercises/practice/binary-search-tree/binary_search_tree.cpp +++ b/exercises/practice/binary-search-tree/binary_search_tree.cpp @@ -1,5 +1,3 @@ #include "binary_search_tree.h" -namespace binary_search_tree { - -} // namespace binary_search_tree +namespace binary_search_tree {} // namespace binary_search_tree diff --git a/exercises/practice/binary-search-tree/binary_search_tree.h b/exercises/practice/binary-search-tree/binary_search_tree.h index 419cf9a60..86d8c44f8 100644 --- a/exercises/practice/binary-search-tree/binary_search_tree.h +++ b/exercises/practice/binary-search-tree/binary_search_tree.h @@ -1,8 +1,6 @@ #if !defined(BINARY_SEARCH_TREE_H) #define BINARY_SEARCH_TREE_H -namespace binary_search_tree { +namespace binary_search_tree {} // namespace binary_search_tree -} // namespace binary_search_tree - -#endif // BINARY_SEARCH_TREE_H \ No newline at end of file +#endif // BINARY_SEARCH_TREE_H \ No newline at end of file diff --git a/exercises/practice/binary-search-tree/binary_search_tree_test.cpp b/exercises/practice/binary-search-tree/binary_search_tree_test.cpp index 9acdcc58b..0e3398ab3 100644 --- a/exercises/practice/binary-search-tree/binary_search_tree_test.cpp +++ b/exercises/practice/binary-search-tree/binary_search_tree_test.cpp @@ -8,70 +8,61 @@ // test data version: 1.0.0 -template +template using tree_ptr = typename std::unique_ptr>; -template -static void test_leaf(const tree_ptr &tree, - const T& data, bool has_left, bool has_right) -{ +template +static void test_leaf(const tree_ptr &tree, const T &data, bool has_left, + bool has_right) { REQUIRE(data == tree->data()); - REQUIRE((bool) tree->left() == has_left); - REQUIRE((bool) tree->right() == has_right); + REQUIRE((bool)tree->left() == has_left); + REQUIRE((bool)tree->right() == has_right); } -template -static tree_ptr make_tree(const std::vector &data) -{ - if (data.empty()) - return tree_ptr(nullptr); - +template +static tree_ptr make_tree(const std::vector &data) { + if (data.empty()) return tree_ptr(nullptr); + auto data_iter = data.begin(); auto tree = tree_ptr(new binary_search_tree::binary_tree(*data_iter)); ++data_iter; - for (; data_iter != data.end(); ++data_iter) - { + for (; data_iter != data.end(); ++data_iter) { tree->insert(*data_iter); } return tree; } -TEST_CASE("data_is_retained") -{ +TEST_CASE("data_is_retained") { auto tested = make_tree({4}); test_leaf(tested, 4, false, false); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("smaller_number_at_left_node") -{ +TEST_CASE("smaller_number_at_left_node") { auto tested = make_tree({4, 2}); test_leaf(tested, 4, true, false); test_leaf(tested->left(), 2, false, false); } -TEST_CASE("same_number_at_left_node") -{ +TEST_CASE("same_number_at_left_node") { auto tested = make_tree({4, 4}); test_leaf(tested, 4, true, false); test_leaf(tested->left(), 4, false, false); } -TEST_CASE("greater_number_at_right_node") -{ +TEST_CASE("greater_number_at_right_node") { auto tested = make_tree({4, 5}); - + test_leaf(tested, 4, false, true); test_leaf(tested->right(), 5, false, false); } -TEST_CASE("can_create_complex_tree") -{ +TEST_CASE("can_create_complex_tree") { auto tested = make_tree({4, 2, 6, 1, 3, 5, 7}); test_leaf(tested, 4, true, true); @@ -88,47 +79,40 @@ TEST_CASE("can_create_complex_tree") // The tests below require an implementation of an iterator. // You can get more details here: http://www.cplusplus.com/reference/iterator/ -template -static void test_sort(const tree_ptr &tree, const std::vector &expected) -{ +template +static void test_sort(const tree_ptr &tree, const std::vector &expected) { std::vector actual; - for (auto& x : *tree) { + for (auto &x : *tree) { actual.push_back(x); } REQUIRE(expected == actual); } - -TEST_CASE("can_sort_single_number") -{ +TEST_CASE("can_sort_single_number") { test_sort(make_tree({2}), {2}); } -TEST_CASE("can_sort_if_second_number_is_smaller_than_first") -{ +TEST_CASE("can_sort_if_second_number_is_smaller_than_first") { test_sort(make_tree({2, 1}), {1, 2}); } -TEST_CASE("can_sort_if_second_number_is_same_as_first") -{ +TEST_CASE("can_sort_if_second_number_is_same_as_first") { test_sort(make_tree({2, 2}), {2, 2}); } -TEST_CASE("can_sort_if_second_number_is_greater_than_first") -{ +TEST_CASE("can_sort_if_second_number_is_greater_than_first") { test_sort(make_tree({2, 3}), {2, 3}); } -TEST_CASE("can_sort_complex_tree") -{ +TEST_CASE("can_sort_complex_tree") { test_sort(make_tree({2, 1, 3, 6, 7, 5}), {1, 2, 3, 5, 6, 7}); } // strings -TEST_CASE("can_create_complex_tree_strings") -{ - auto tested = make_tree({"delicious", "ballon", "flag", "apple", "cat", "elispsis", "grains"}); +TEST_CASE("can_create_complex_tree_strings") { + auto tested = make_tree( + {"delicious", "ballon", "flag", "apple", "cat", "elispsis", "grains"}); test_leaf(tested, "delicious", true, true); test_leaf(tested->left(), "ballon", true, true); @@ -141,9 +125,11 @@ TEST_CASE("can_create_complex_tree_strings") test_leaf(tested->right()->right(), "grains", false, false); } -TEST_CASE("can_sort_complex_tree_strings") -{ - test_sort(make_tree({"A", "few", "random", "strings", "that", "should", "be", "sorted"}), {"A", "be", "few", "random", "should", "sorted", "strings", "that"}); +TEST_CASE("can_sort_complex_tree_strings") { + test_sort( + make_tree({"A", "few", "random", "strings", "that", + "should", "be", "sorted"}), + {"A", "be", "few", "random", "should", "sorted", "strings", "that"}); } #endif diff --git a/exercises/practice/binary-search/.meta/example.cpp b/exercises/practice/binary-search/.meta/example.cpp index a96783ef5..4877a0716 100644 --- a/exercises/practice/binary-search/.meta/example.cpp +++ b/exercises/practice/binary-search/.meta/example.cpp @@ -1,47 +1,39 @@ #include + #include "binary_search.h" -namespace binary_search -{ +namespace binary_search { -bool is_value_in_range(std::vector const& data, int const value) -{ +bool is_value_in_range(std::vector const& data, int const value) { return ((data.front() <= value) && (value <= data.back())); } -size_t find(std::vector const& data, int const value) -{ - if(data.empty() || !is_value_in_range(data, value)) - { +size_t find(std::vector const& data, int const value) { + if (data.empty() || !is_value_in_range(data, value)) { throw std::domain_error("Value not in input vector!"); } - - size_t lpos {0}; - size_t rpos {data.size() - 1}; - size_t mid {0}; - while (lpos <= rpos) - { + size_t lpos{0}; + size_t rpos{data.size() - 1}; + size_t mid{0}; + + while (lpos <= rpos) { mid = lpos + ((rpos - lpos) / 2); - if (data.at(mid) == value) - { - return mid; + if (data.at(mid) == value) { + return mid; } - - if (value < data.at(mid)) - { + + if (value < data.at(mid)) { rpos = mid - 1; - } - - if (value > data.at(mid)) - { - lpos = mid + 1; + } + + if (value > data.at(mid)) { + lpos = mid + 1; } } throw std::domain_error("Value not in input vector!"); } -} // namespace binary_search - +} // namespace binary_search diff --git a/exercises/practice/binary-search/.meta/example.h b/exercises/practice/binary-search/.meta/example.h index 0a28b72ae..3b1566634 100644 --- a/exercises/practice/binary-search/.meta/example.h +++ b/exercises/practice/binary-search/.meta/example.h @@ -1,16 +1,15 @@ #if !defined(BINARY_SEARCH_H) #define BINARY_SEARCH_H -#include #include +#include -namespace binary_search -{ +namespace binary_search { using std::size_t; size_t find(std::vector const&, int const); -} // namespace binary_search +} // namespace binary_search -#endif // BINARY_SEARCH_H +#endif // BINARY_SEARCH_H diff --git a/exercises/practice/binary-search/binary_search.cpp b/exercises/practice/binary-search/binary_search.cpp index 67c96be9e..04dde4a8c 100644 --- a/exercises/practice/binary-search/binary_search.cpp +++ b/exercises/practice/binary-search/binary_search.cpp @@ -1,5 +1,3 @@ #include "binary_search.h" -namespace binary_search { - -} // namespace binary_search +namespace binary_search {} // namespace binary_search diff --git a/exercises/practice/binary-search/binary_search.h b/exercises/practice/binary-search/binary_search.h index 4e96247c3..a1c93e059 100644 --- a/exercises/practice/binary-search/binary_search.h +++ b/exercises/practice/binary-search/binary_search.h @@ -1,8 +1,6 @@ #if !defined(BINARY_SEARCH_H) #define BINARY_SEARCH_H -namespace binary_search { +namespace binary_search {} // namespace binary_search -} // namespace binary_search - -#endif // BINARY_SEARCH_H \ No newline at end of file +#endif // BINARY_SEARCH_H \ No newline at end of file diff --git a/exercises/practice/binary-search/binary_search_test.cpp b/exercises/practice/binary-search/binary_search_test.cpp index a651c0c18..2ead66ae9 100644 --- a/exercises/practice/binary-search/binary_search_test.cpp +++ b/exercises/practice/binary-search/binary_search_test.cpp @@ -4,18 +4,17 @@ #else #include "test/catch.hpp" #endif +#include #include #include -#include using namespace std; // Binary-Search exercise test case data version 1.3.0 -TEST_CASE("finds_a_value_in_an_array_with_one_element") -{ - const std::vector data {6}; - +TEST_CASE("finds_a_value_in_an_array_with_one_element") { + const std::vector data{6}; + const std::size_t actual = binary_search::find(data, 6); const std::size_t expected = 0; @@ -24,10 +23,9 @@ TEST_CASE("finds_a_value_in_an_array_with_one_element") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("finds_a_value_in_the_middle_of_an_array") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("finds_a_value_in_the_middle_of_an_array") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + const std::size_t actual = binary_search::find(data, 6); const std::size_t expected = 3; @@ -35,10 +33,9 @@ TEST_CASE("finds_a_value_in_the_middle_of_an_array") REQUIRE(expected == actual); } -TEST_CASE("finds_a_value_at_the_beginning_of_an_array") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("finds_a_value_at_the_beginning_of_an_array") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + const std::size_t actual = binary_search::find(data, 1); const std::size_t expected = 0; @@ -46,10 +43,9 @@ TEST_CASE("finds_a_value_at_the_beginning_of_an_array") REQUIRE(expected == actual); } -TEST_CASE("finds_a_value_at_the_end_of_an_array") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("finds_a_value_at_the_end_of_an_array") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + const std::size_t actual = binary_search::find(data, 11); const std::size_t expected = 6; @@ -57,10 +53,10 @@ TEST_CASE("finds_a_value_at_the_end_of_an_array") REQUIRE(expected == actual); } -TEST_CASE("finds_a_value_in_an_array_of_odd_length") -{ - const std::vector data {1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634}; - +TEST_CASE("finds_a_value_in_an_array_of_odd_length") { + const std::vector data{1, 3, 5, 8, 13, 21, 34, + 55, 89, 144, 233, 377, 634}; + const std::size_t actual = binary_search::find(data, 144); const std::size_t expected = 9; @@ -68,10 +64,9 @@ TEST_CASE("finds_a_value_in_an_array_of_odd_length") REQUIRE(expected == actual); } -TEST_CASE("finds_a_value_in_an_array_of_even_length") -{ - const std::vector data {1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377}; - +TEST_CASE("finds_a_value_in_an_array_of_even_length") { + const std::vector data{1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377}; + const std::size_t actual = binary_search::find(data, 21); const std::size_t expected = 5; @@ -79,38 +74,33 @@ TEST_CASE("finds_a_value_in_an_array_of_even_length") REQUIRE(expected == actual); } -TEST_CASE("identifies_that_a_value_is_not_included_in_the_array") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("identifies_that_a_value_is_not_included_in_the_array") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + REQUIRE_THROWS_AS(binary_search::find(data, 7), std::domain_error); } -TEST_CASE("a_value_smaller_than_the_arrays_smallest_value_is_not_found") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("a_value_smaller_than_the_arrays_smallest_value_is_not_found") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + REQUIRE_THROWS_AS(binary_search::find(data, 0), std::domain_error); } -TEST_CASE("a_value_larger_than_the_arrays_largest_value_is_not_found") -{ - const std::vector data {1, 3, 4, 6, 8, 9, 11}; - +TEST_CASE("a_value_larger_than_the_arrays_largest_value_is_not_found") { + const std::vector data{1, 3, 4, 6, 8, 9, 11}; + REQUIRE_THROWS_AS(binary_search::find(data, 13), std::domain_error); } -TEST_CASE("nothing_is_found_in_an_empty_array") -{ - const std::vector data {}; - +TEST_CASE("nothing_is_found_in_an_empty_array") { + const std::vector data{}; + REQUIRE_THROWS_AS(binary_search::find(data, 1), std::domain_error); } -TEST_CASE("nothing_is_found_when_the_left_and_right_bounds_cross") -{ - const std::vector data {1, 2}; - +TEST_CASE("nothing_is_found_when_the_left_and_right_bounds_cross") { + const std::vector data{1, 2}; + REQUIRE_THROWS_AS(binary_search::find(data, 0), std::domain_error); } diff --git a/exercises/practice/binary/.meta/example.cpp b/exercises/practice/binary/.meta/example.cpp index 532c80573..80250933b 100644 --- a/exercises/practice/binary/.meta/example.cpp +++ b/exercises/practice/binary/.meta/example.cpp @@ -1,12 +1,10 @@ #include "binary.h" -namespace binary -{ +namespace binary { -int convert(std::string const& text) -{ +int convert(std::string const& text) { int result = 0; - if (text.length() > sizeof(int)*8-1) { + if (text.length() > sizeof(int) * 8 - 1) { return 0; } for (const char x : text) { @@ -20,4 +18,4 @@ int convert(std::string const& text) return result; } -} +} // namespace binary diff --git a/exercises/practice/binary/.meta/example.h b/exercises/practice/binary/.meta/example.h index 6c0bb35cf..21c838218 100644 --- a/exercises/practice/binary/.meta/example.h +++ b/exercises/practice/binary/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace binary -{ +namespace binary { int convert(std::string const& text); diff --git a/exercises/practice/binary/binary.cpp b/exercises/practice/binary/binary.cpp index c772682c6..4e45914ca 100644 --- a/exercises/practice/binary/binary.cpp +++ b/exercises/practice/binary/binary.cpp @@ -1,5 +1,3 @@ #include "binary.h" -namespace binary { - -} // namespace binary +namespace binary {} // namespace binary diff --git a/exercises/practice/binary/binary.h b/exercises/practice/binary/binary.h index 713bb04ac..90686cd6b 100644 --- a/exercises/practice/binary/binary.h +++ b/exercises/practice/binary/binary.h @@ -1,8 +1,6 @@ #if !defined(BINARY_H) #define BINARY_H -namespace binary { +namespace binary {} // namespace binary -} // namespace binary - -#endif // BINARY_H \ No newline at end of file +#endif // BINARY_H \ No newline at end of file diff --git a/exercises/practice/binary/binary_test.cpp b/exercises/practice/binary/binary_test.cpp index e91d95ba6..b95d5ae26 100644 --- a/exercises/practice/binary/binary_test.cpp +++ b/exercises/practice/binary/binary_test.cpp @@ -5,49 +5,26 @@ #include "test/catch.hpp" #endif -TEST_CASE("b1_is_decimal_1") -{ - REQUIRE(1 == binary::convert("1")); -} +TEST_CASE("b1_is_decimal_1") { REQUIRE(1 == binary::convert("1")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("b10_is_decimal_2") -{ - REQUIRE(2 == binary::convert("10")); -} +TEST_CASE("b10_is_decimal_2") { REQUIRE(2 == binary::convert("10")); } -TEST_CASE("b11_is_decimal_3") -{ - REQUIRE(3 == binary::convert("11")); -} +TEST_CASE("b11_is_decimal_3") { REQUIRE(3 == binary::convert("11")); } -TEST_CASE("b100_is_decimal_4") -{ - REQUIRE(4 == binary::convert("100")); -} +TEST_CASE("b100_is_decimal_4") { REQUIRE(4 == binary::convert("100")); } -TEST_CASE("b1001_is_decimal_9") -{ - REQUIRE(9 == binary::convert("1001")); -} +TEST_CASE("b1001_is_decimal_9") { REQUIRE(9 == binary::convert("1001")); } -TEST_CASE("b11010_is_decimal_26") -{ - REQUIRE(26 == binary::convert("11010")); -} +TEST_CASE("b11010_is_decimal_26") { REQUIRE(26 == binary::convert("11010")); } -TEST_CASE("b10001101000_is_decimal_1128") -{ +TEST_CASE("b10001101000_is_decimal_1128") { REQUIRE(1128 == binary::convert("10001101000")); } -TEST_CASE("carrot_is_decimal_0") -{ - REQUIRE(0 == binary::convert("carrot")); -} +TEST_CASE("carrot_is_decimal_0") { REQUIRE(0 == binary::convert("carrot")); } -TEST_CASE("x1100101b_is_decimal_0") -{ +TEST_CASE("x1100101b_is_decimal_0") { REQUIRE(0 == binary::convert("1100101b")); } #endif diff --git a/exercises/practice/bob/.meta/example.cpp b/exercises/practice/bob/.meta/example.cpp index 563f81782..4e026779d 100644 --- a/exercises/practice/bob/.meta/example.cpp +++ b/exercises/practice/bob/.meta/example.cpp @@ -1,20 +1,19 @@ -#include "bob.h" #include #include #include +#include "bob.h" + using namespace std; -namespace bob -{ -namespace -{ +namespace bob { +namespace { -string trim_copy(string const& s) -{ +string trim_copy(string const& s) { string cpy(s); // Trim front - while (!cpy.empty() && std::isspace(static_cast(cpy.front()))) + while (!cpy.empty() && + std::isspace(static_cast(cpy.front()))) cpy.erase(cpy.begin()); // Trim back while (!cpy.empty() && std::isspace(static_cast(cpy.back()))) @@ -22,46 +21,36 @@ string trim_copy(string const& s) return cpy; } -bool is_upper(string const& text) -{ +bool is_upper(string const& text) { auto last = end(text); - auto it = find_if_not(begin(text), last, - [](char c) { return c == toupper(c); }); + auto it = + find_if_not(begin(text), last, [](char c) { return c == toupper(c); }); return it == last; } -bool has_alpha(string const& text) -{ +bool has_alpha(string const& text) { auto last = end(text); - auto it = find_if(begin(text), last, [](char c) { return isalpha(c) != 0; }); + auto it = + find_if(begin(text), last, [](char c) { return isalpha(c) != 0; }); return it != last; } -bool is_shouting(string const &text) -{ +bool is_shouting(string const& text) { return is_upper(text) && has_alpha(text); } -bool is_question(string const &text) -{ - return trim_copy(text).back() == '?'; -} +bool is_question(string const& text) { return trim_copy(text).back() == '?'; } -bool is_silence(string const& text) -{ - return trim_copy(text).length() == 0; -} +bool is_silence(string const& text) { return trim_copy(text).length() == 0; } -} // anonymous namespace +} // anonymous namespace -string hey(string const& text) -{ +string hey(string const& text) { if (is_silence(text)) { return "Fine. Be that way!"; } if (is_shouting(text)) { - if (is_question(text)) - return "Calm down, I know what I'm doing!"; + if (is_question(text)) return "Calm down, I know what I'm doing!"; return "Whoa, chill out!"; } if (is_question(text)) { @@ -70,4 +59,4 @@ string hey(string const& text) return "Whatever."; } -} // namespace bob +} // namespace bob diff --git a/exercises/practice/bob/bob.cpp b/exercises/practice/bob/bob.cpp index 0337391df..c2eff3f49 100644 --- a/exercises/practice/bob/bob.cpp +++ b/exercises/practice/bob/bob.cpp @@ -1,5 +1,3 @@ #include "bob.h" -namespace bob { - -} // namespace bob +namespace bob {} // namespace bob diff --git a/exercises/practice/bob/bob.h b/exercises/practice/bob/bob.h index 294e2981b..d8a67a955 100644 --- a/exercises/practice/bob/bob.h +++ b/exercises/practice/bob/bob.h @@ -1,8 +1,6 @@ #if !defined(BOB_H) #define BOB_H -namespace bob { +namespace bob {} // namespace bob -} // namespace bob - -#endif // BOB_H \ No newline at end of file +#endif // BOB_H \ No newline at end of file diff --git a/exercises/practice/bob/bob_test.cpp b/exercises/practice/bob/bob_test.cpp index fc1003251..9a9c07328 100644 --- a/exercises/practice/bob/bob_test.cpp +++ b/exercises/practice/bob/bob_test.cpp @@ -7,129 +7,98 @@ // Bob exercise test case data version 1.4.0 -TEST_CASE("stating_something") -{ +TEST_CASE("stating_something") { REQUIRE("Whatever." == bob::hey("Tom-ay-to, tom-aaaah-to.")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("shouting") -{ - REQUIRE("Whoa, chill out!" == bob::hey("WATCH OUT!")); -} +TEST_CASE("shouting") { REQUIRE("Whoa, chill out!" == bob::hey("WATCH OUT!")); } -TEST_CASE("shouting_gibberish") -{ +TEST_CASE("shouting_gibberish") { REQUIRE("Whoa, chill out!" == bob::hey("FCECDFCAAB")); } -TEST_CASE("asking_a_question") -{ - REQUIRE("Sure." == bob::hey("Does this cryogenic chamber make me look fat?")); +TEST_CASE("asking_a_question") { + REQUIRE("Sure." == + bob::hey("Does this cryogenic chamber make me look fat?")); } -TEST_CASE("asking_a_numeric_question") -{ +TEST_CASE("asking_a_numeric_question") { REQUIRE("Sure." == bob::hey("You are, what, like 15?")); } -TEST_CASE("asking_gibberish") -{ - REQUIRE("Sure." == bob::hey("fffbbcbeab?")); -} +TEST_CASE("asking_gibberish") { REQUIRE("Sure." == bob::hey("fffbbcbeab?")); } -TEST_CASE("talking_forcefully") -{ +TEST_CASE("talking_forcefully") { REQUIRE("Whatever." == bob::hey("Let's go make out behind the gym!")); } -TEST_CASE("using_acronyms_in_regular_speech") -{ - REQUIRE("Whatever." == bob::hey("It's OK if you don't want to go to the DMV.")); +TEST_CASE("using_acronyms_in_regular_speech") { + REQUIRE("Whatever." == + bob::hey("It's OK if you don't want to go to the DMV.")); } -TEST_CASE("forceful_questions") -{ - REQUIRE("Calm down, I know what I'm doing!" == bob::hey("WHAT THE HELL WERE YOU THINKING?")); +TEST_CASE("forceful_questions") { + REQUIRE("Calm down, I know what I'm doing!" == + bob::hey("WHAT THE HELL WERE YOU THINKING?")); } -TEST_CASE("shouting_numbers") -{ +TEST_CASE("shouting_numbers") { REQUIRE("Whoa, chill out!" == bob::hey("1, 2, 3 GO!")); } -TEST_CASE("no_letters") -{ - REQUIRE("Whatever." == bob::hey("1, 2, 3")); -} +TEST_CASE("no_letters") { REQUIRE("Whatever." == bob::hey("1, 2, 3")); } -TEST_CASE("question_with_no_letters") -{ - REQUIRE("Sure." == bob::hey("4?")); -} +TEST_CASE("question_with_no_letters") { REQUIRE("Sure." == bob::hey("4?")); } -TEST_CASE("shouting_with_special_characters") -{ - REQUIRE("Whoa, chill out!" == bob::hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")); +TEST_CASE("shouting_with_special_characters") { + REQUIRE("Whoa, chill out!" == + bob::hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!")); } -TEST_CASE("shouting_with_no_exclamation_mark") -{ +TEST_CASE("shouting_with_no_exclamation_mark") { REQUIRE("Whoa, chill out!" == bob::hey("I HATE THE DMV")); } -TEST_CASE("statement_containing_question_mark") -{ +TEST_CASE("statement_containing_question_mark") { REQUIRE("Whatever." == bob::hey("Ending with ? means a question.")); } -TEST_CASE("non_letters_with_question") -{ - REQUIRE("Sure." == bob::hey(":) ?")); -} +TEST_CASE("non_letters_with_question") { REQUIRE("Sure." == bob::hey(":) ?")); } -TEST_CASE("prattling_on") -{ +TEST_CASE("prattling_on") { REQUIRE("Sure." == bob::hey("Wait! Hang on. Are you going to be OK?")); } -TEST_CASE("silence") -{ - REQUIRE("Fine. Be that way!" == bob::hey("")); -} +TEST_CASE("silence") { REQUIRE("Fine. Be that way!" == bob::hey("")); } -TEST_CASE("prolonged_silence") -{ +TEST_CASE("prolonged_silence") { REQUIRE("Fine. Be that way!" == bob::hey(" ")); } -TEST_CASE("alternate_silence") -{ +TEST_CASE("alternate_silence") { REQUIRE("Fine. Be that way!" == bob::hey("\t\t\t\t\t\t\t\t\t\t")); } -TEST_CASE("multiple_line_question") -{ - REQUIRE("Whatever." == bob::hey("\nDoes this cryogenic chamber make me look fat?\nNo.")); +TEST_CASE("multiple_line_question") { + REQUIRE("Whatever." == + bob::hey("\nDoes this cryogenic chamber make me look fat?\nNo.")); } -TEST_CASE("starting_with_whitespace") -{ - REQUIRE("Whatever." == bob::hey(" hmmmmmmm...")); +TEST_CASE("starting_with_whitespace") { + REQUIRE("Whatever." == bob::hey(" hmmmmmmm...")); } -TEST_CASE("ending_with_whitespace") -{ - REQUIRE("Sure." == bob::hey("Okay if like my spacebar quite a bit? ")); +TEST_CASE("ending_with_whitespace") { + REQUIRE("Sure." == bob::hey("Okay if like my spacebar quite a bit? ")); } -TEST_CASE("other_whitespace") -{ - REQUIRE("Fine. Be that way!" == bob::hey("\n\r \t")); +TEST_CASE("other_whitespace") { + REQUIRE("Fine. Be that way!" == bob::hey("\n\r \t")); } -TEST_CASE("non_question_ending_with_whitespace") -{ - REQUIRE("Whatever." == bob::hey("This is a statement ending with whitespace ")); +TEST_CASE("non_question_ending_with_whitespace") { + REQUIRE("Whatever." == + bob::hey("This is a statement ending with whitespace ")); } #endif diff --git a/exercises/practice/circular-buffer/.meta/example.h b/exercises/practice/circular-buffer/.meta/example.h index f89b67398..acb29887b 100644 --- a/exercises/practice/circular-buffer/.meta/example.h +++ b/exercises/practice/circular-buffer/.meta/example.h @@ -1,35 +1,37 @@ #if !defined(CIRCULAR_BUFFER_H_) #define CIRCULAR_BUFFER_H_ -#include #include +#include namespace circular_buffer { template class circular_buffer { -public: - circular_buffer(std::size_t capacity) + public: + circular_buffer(std::size_t capacity) : buffer_(capacity + 1), head_(0), tail_(0) {} ValueType read(); void write(ValueType item); void overwrite(ValueType item); void clear() { head_ = tail_; } -private: + private: std::vector buffer_; std::size_t head_; std::size_t tail_; void push_back(ValueType item); - void move_position(std::size_t& position) { position = (position + 1) % buffer_.size(); } + void move_position(std::size_t& position) { + position = (position + 1) % buffer_.size(); + } bool is_empty() const { return head_ == tail_; } bool is_full() const { return head_ == (tail_ + 1) % buffer_.size(); } }; template ValueType circular_buffer::read() { - if (is_empty()) throw std::domain_error("Circular buffer is empty."); + if (is_empty()) throw std::domain_error("Circular buffer is empty."); ValueType item = buffer_[head_]; move_position(head_); return item; @@ -53,6 +55,6 @@ void circular_buffer::push_back(ValueType item) { move_position(tail_); } -} // namespace circular_buffer +} // namespace circular_buffer -#endif // !CIRCULAR_BUFFER_H_ \ No newline at end of file +#endif // !CIRCULAR_BUFFER_H_ \ No newline at end of file diff --git a/exercises/practice/circular-buffer/circular_buffer.cpp b/exercises/practice/circular-buffer/circular_buffer.cpp index 8a58f85c5..422bf44d6 100644 --- a/exercises/practice/circular-buffer/circular_buffer.cpp +++ b/exercises/practice/circular-buffer/circular_buffer.cpp @@ -1,5 +1,3 @@ #include "circular_buffer.h" -namespace circular_buffer { - -} // namespace circular_buffer +namespace circular_buffer {} // namespace circular_buffer diff --git a/exercises/practice/circular-buffer/circular_buffer.h b/exercises/practice/circular-buffer/circular_buffer.h index 07f91edaa..ab8a16f91 100644 --- a/exercises/practice/circular-buffer/circular_buffer.h +++ b/exercises/practice/circular-buffer/circular_buffer.h @@ -1,8 +1,6 @@ #if !defined(CIRCULAR_BUFFER_H) #define CIRCULAR_BUFFER_H -namespace circular_buffer { +namespace circular_buffer {} // namespace circular_buffer -} // namespace circular_buffer - -#endif // CIRCULAR_BUFFER_H \ No newline at end of file +#endif // CIRCULAR_BUFFER_H \ No newline at end of file diff --git a/exercises/practice/circular-buffer/circular_buffer_test.cpp b/exercises/practice/circular-buffer/circular_buffer_test.cpp index 041952f87..6d83611cc 100644 --- a/exercises/practice/circular-buffer/circular_buffer_test.cpp +++ b/exercises/practice/circular-buffer/circular_buffer_test.cpp @@ -9,16 +9,14 @@ // Circular-buffer exercise test case data version 1.2.0 -TEST_CASE("reading_empty_buffer_should_fail") -{ +TEST_CASE("reading_empty_buffer_should_fail") { circular_buffer::circular_buffer buffer(1); REQUIRE_THROWS_AS(buffer.read(), std::domain_error); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("can_read_an_item_just_written") -{ +TEST_CASE("can_read_an_item_just_written") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -27,8 +25,7 @@ TEST_CASE("can_read_an_item_just_written") REQUIRE(expected == buffer.read()); } -TEST_CASE("each_item_may_only_be_read_once") -{ +TEST_CASE("each_item_may_only_be_read_once") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -39,8 +36,7 @@ TEST_CASE("each_item_may_only_be_read_once") REQUIRE_THROWS_AS(buffer.read(), std::domain_error); } -TEST_CASE("items_are_read_in_the_order_they_are_written") -{ +TEST_CASE("items_are_read_in_the_order_they_are_written") { circular_buffer::circular_buffer buffer(2); REQUIRE_NOTHROW(buffer.write(1)); @@ -53,16 +49,14 @@ TEST_CASE("items_are_read_in_the_order_they_are_written") REQUIRE(expected == buffer.read()); } -TEST_CASE("full_buffer_cant_be_written") -{ +TEST_CASE("full_buffer_cant_be_written") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); REQUIRE_THROWS_AS(buffer.write(2), std::domain_error); } -TEST_CASE("a_read_frees_up_capacity_for_another_write") -{ +TEST_CASE("a_read_frees_up_capacity_for_another_write") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -76,8 +70,7 @@ TEST_CASE("a_read_frees_up_capacity_for_another_write") REQUIRE(expected == buffer.read()); } -TEST_CASE("read_position_is_maintained_even_across_multiple_writes") -{ +TEST_CASE("read_position_is_maintained_even_across_multiple_writes") { circular_buffer::circular_buffer buffer(3); REQUIRE_NOTHROW(buffer.write(1)); @@ -95,8 +88,7 @@ TEST_CASE("read_position_is_maintained_even_across_multiple_writes") REQUIRE(expected == buffer.read()); } -TEST_CASE("items_cleared_out_of_buffer_cant_be_read") -{ +TEST_CASE("items_cleared_out_of_buffer_cant_be_read") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -106,8 +98,7 @@ TEST_CASE("items_cleared_out_of_buffer_cant_be_read") REQUIRE_THROWS_AS(buffer.read(), std::domain_error); } -TEST_CASE("clear_frees_up_capacity_for_another_write") -{ +TEST_CASE("clear_frees_up_capacity_for_another_write") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -120,8 +111,7 @@ TEST_CASE("clear_frees_up_capacity_for_another_write") REQUIRE(expected == buffer.read()); } -TEST_CASE("clear_does_nothing_on_empty_buffer") -{ +TEST_CASE("clear_does_nothing_on_empty_buffer") { circular_buffer::circular_buffer buffer(1); buffer.clear(); @@ -132,8 +122,7 @@ TEST_CASE("clear_does_nothing_on_empty_buffer") REQUIRE(expected == buffer.read()); } -TEST_CASE("overwrite_acts_like_write_on_non_full_buffer") -{ +TEST_CASE("overwrite_acts_like_write_on_non_full_buffer") { circular_buffer::circular_buffer buffer(2); REQUIRE_NOTHROW(buffer.write(1)); @@ -147,8 +136,7 @@ TEST_CASE("overwrite_acts_like_write_on_non_full_buffer") REQUIRE(expected == buffer.read()); } -TEST_CASE("overwrite_replaces_the_oldest_item_on_full_buffer") -{ +TEST_CASE("overwrite_replaces_the_oldest_item_on_full_buffer") { circular_buffer::circular_buffer buffer(2); REQUIRE_NOTHROW(buffer.write(1)); @@ -163,8 +151,8 @@ TEST_CASE("overwrite_replaces_the_oldest_item_on_full_buffer") REQUIRE(expected == buffer.read()); } -TEST_CASE("overwrite_replaces_the_oldest_item_remaining_in_buffer_following_a_read") -{ +TEST_CASE( + "overwrite_replaces_the_oldest_item_remaining_in_buffer_following_a_read") { circular_buffer::circular_buffer buffer(3); REQUIRE_NOTHROW(buffer.write(1)); @@ -188,8 +176,7 @@ TEST_CASE("overwrite_replaces_the_oldest_item_remaining_in_buffer_following_a_re REQUIRE(expected == buffer.read()); } -TEST_CASE("full_buffer_cant_be_written_after_overwrite") -{ +TEST_CASE("full_buffer_cant_be_written_after_overwrite") { circular_buffer::circular_buffer buffer(1); REQUIRE_NOTHROW(buffer.write(1)); @@ -200,8 +187,7 @@ TEST_CASE("full_buffer_cant_be_written_after_overwrite") REQUIRE(expected == buffer.read()); } -TEST_CASE("check_correctness_with_string_type") -{ +TEST_CASE("check_correctness_with_string_type") { circular_buffer::circular_buffer buffer(3); REQUIRE_NOTHROW(buffer.write("hello")); @@ -225,8 +211,7 @@ TEST_CASE("check_correctness_with_string_type") REQUIRE(expected == buffer.read()); } -TEST_CASE("initial_clear_does_not_affect_wrapping_around") -{ +TEST_CASE("initial_clear_does_not_affect_wrapping_around") { circular_buffer::circular_buffer buffer(2); buffer.clear(); diff --git a/exercises/practice/clock/.meta/example.cpp b/exercises/practice/clock/.meta/example.cpp index 4627e3c36..c0ea8611d 100644 --- a/exercises/practice/clock/.meta/example.cpp +++ b/exercises/practice/clock/.meta/example.cpp @@ -1,71 +1,56 @@ -#include "clock.h" #include #include +#include "clock.h" + using namespace std; -namespace -{ +namespace { const int minutes_per_hour = 60; const int hours_per_day = 24; -} +} // namespace -namespace date_independent -{ +namespace date_independent { -clock& clock::plus(int minutes) -{ +clock& clock::plus(int minutes) { minute_ += minutes; clean(); return *this; } -clock& clock::minus(int minutes) -{ +clock& clock::minus(int minutes) { minute_ -= minutes; clean(); return *this; } -clock::operator string() const -{ +clock::operator string() const { ostringstream str; - str << setw(2) << setfill('0') << hour_ << ':' << setw(2) << setfill('0') << minute_; + str << setw(2) << setfill('0') << hour_ << ':' << setw(2) << setfill('0') + << minute_; return str.str(); } -clock::clock(int hour, int minute) - : hour_(hour), - minute_(minute) -{ - clean(); -} +clock::clock(int hour, int minute) : hour_(hour), minute_(minute) { clean(); } -void clock::clean() -{ +void clock::clean() { if (minute_ < 0) { int tmp = 1 + (minute_ / -minutes_per_hour); hour_ -= tmp; minute_ += minutes_per_hour * tmp; } - if (hour_ < 0) - hour_ += hours_per_day*(1 + (hour_ / -hours_per_day)); + if (hour_ < 0) hour_ += hours_per_day * (1 + (hour_ / -hours_per_day)); hour_ += minute_ / minutes_per_hour; hour_ %= hours_per_day; minute_ %= minutes_per_hour; } -clock clock::at(int hour, int minute /*= 0*/) -{ - return clock(hour, minute); -} +clock clock::at(int hour, int minute /*= 0*/) { return clock(hour, minute); } -bool clock::operator==(const clock& rhs) const -{ - return hour_ == rhs.hour_ - && minute_ == rhs.minute_; +bool clock::operator==(const clock& rhs) const { + return hour_ == rhs.hour_ && minute_ == rhs.minute_; } -} +} // namespace date_independent diff --git a/exercises/practice/clock/.meta/example.h b/exercises/practice/clock/.meta/example.h index 63d0bc5b5..0396c9638 100644 --- a/exercises/practice/clock/.meta/example.h +++ b/exercises/practice/clock/.meta/example.h @@ -3,12 +3,10 @@ #include -namespace date_independent -{ +namespace date_independent { -class clock -{ -public: +class clock { + public: static clock at(int hour, int minute = 0); clock& plus(int minutes); @@ -18,18 +16,17 @@ class clock bool operator==(const clock& rhs) const; -private: + private: clock(int hour, int minute); void clean(); int hour_; int minute_; }; -inline bool operator!=(const clock& lhs, const clock& rhs) -{ +inline bool operator!=(const clock& lhs, const clock& rhs) { return !(lhs == rhs); } -} +} // namespace date_independent #endif diff --git a/exercises/practice/clock/clock.cpp b/exercises/practice/clock/clock.cpp index e109f597c..709a259af 100644 --- a/exercises/practice/clock/clock.cpp +++ b/exercises/practice/clock/clock.cpp @@ -1,5 +1,3 @@ #include "clock.h" -namespace date_independent { - -} // namespace date_independent +namespace date_independent {} // namespace date_independent diff --git a/exercises/practice/clock/clock.h b/exercises/practice/clock/clock.h index 44d3e924e..bebd1c203 100644 --- a/exercises/practice/clock/clock.h +++ b/exercises/practice/clock/clock.h @@ -1,8 +1,6 @@ #if !defined(CLOCK_H) #define CLOCK_H -namespace date_independent { +namespace date_independent {} // namespace date_independent -} // namespace date_independent - -#endif // CLOCK_H \ No newline at end of file +#endif // CLOCK_H \ No newline at end of file diff --git a/exercises/practice/clock/clock_test.cpp b/exercises/practice/clock/clock_test.cpp index f56df83bc..2f053c6f4 100644 --- a/exercises/practice/clock/clock_test.cpp +++ b/exercises/practice/clock/clock_test.cpp @@ -16,25 +16,26 @@ struct timeTest { }; vector timeCases = { - {8, 0, "08:00", "on the hour"}, - {11, 9, "11:09", "past the hour"}, - {24, 0, "00:00", "midnight is zero hours"}, - {25, 0, "01:00", "hour rolls over"}, - {100, 0, "04:00", "hour rolls over continuously"}, - {1, 60, "02:00", "sixty minutes is next hour"}, - {0, 160, "02:40", "minutes roll over"}, - {0, 1723, "04:43", "minutes roll over continuously"}, - {25, 160, "03:40", "hour and minutes roll over"}, - {201, 3001, "11:01", "hour and minutes roll over continuously"}, - {72, 8640, "00:00", "hour and minutes roll over to exactly midnight"}, - {-1, 15, "23:15", "negative hour"}, - {-25, 0, "23:00", "negative hour rolls over"}, - {-91, 0, "05:00", "negative hour rolls over continuously"}, - {1, -40, "00:20", "negative minutes"}, - {1, -160, "22:20", "negative minutes roll over"}, - {1, -4820, "16:40", "negative minutes roll over continuously"}, - {-25, -160, "20:20", "negative hour and minutes both roll over"}, - {-121, -5810, "22:10", "negative hour and minutes both roll over continuously"}, + {8, 0, "08:00", "on the hour"}, + {11, 9, "11:09", "past the hour"}, + {24, 0, "00:00", "midnight is zero hours"}, + {25, 0, "01:00", "hour rolls over"}, + {100, 0, "04:00", "hour rolls over continuously"}, + {1, 60, "02:00", "sixty minutes is next hour"}, + {0, 160, "02:40", "minutes roll over"}, + {0, 1723, "04:43", "minutes roll over continuously"}, + {25, 160, "03:40", "hour and minutes roll over"}, + {201, 3001, "11:01", "hour and minutes roll over continuously"}, + {72, 8640, "00:00", "hour and minutes roll over to exactly midnight"}, + {-1, 15, "23:15", "negative hour"}, + {-25, 0, "23:00", "negative hour rolls over"}, + {-91, 0, "05:00", "negative hour rolls over continuously"}, + {1, -40, "00:20", "negative minutes"}, + {1, -160, "22:20", "negative minutes roll over"}, + {1, -4820, "16:40", "negative minutes roll over continuously"}, + {-25, -160, "20:20", "negative hour and minutes both roll over"}, + {-121, -5810, "22:10", + "negative hour and minutes both roll over continuously"}, }; struct addTest { @@ -46,20 +47,20 @@ struct addTest { }; vector addCases = { - {10, 0, 3, "10:03", "add minutes"}, - {6, 41, 0, "06:41", "add no minutes"}, - {0, 45, 40, "01:25", "add to next hour"}, - {10, 0, 61, "11:01", "add more than one hour"}, - {0, 45, 160, "03:25", "add more than two hours with carry"}, - {23, 59, 2, "00:01", "add across midnight"}, - {5, 32, 1500, "06:32", "add more than one day (1500 min = 25 hrs)"}, - {1, 1, 3500, "11:21", "add more than two days"}, - {10, 3, -3, "10:00", "subtract minutes"}, - {10, 3, -30, "09:33", "subtract to previous hour"}, - {10, 3, -70, "08:53", "subtract more than an hour"}, - {0, 3, -4, "23:59", "subtract across midnight"}, - {0, 0, -160, "21:20", "subtract more than two hours"}, - {6, 15, -160, "03:35", "subtract more than two hours with borrow"}, + {10, 0, 3, "10:03", "add minutes"}, + {6, 41, 0, "06:41", "add no minutes"}, + {0, 45, 40, "01:25", "add to next hour"}, + {10, 0, 61, "11:01", "add more than one hour"}, + {0, 45, 160, "03:25", "add more than two hours with carry"}, + {23, 59, 2, "00:01", "add across midnight"}, + {5, 32, 1500, "06:32", "add more than one day (1500 min = 25 hrs)"}, + {1, 1, 3500, "11:21", "add more than two days"}, + {10, 3, -3, "10:00", "subtract minutes"}, + {10, 3, -30, "09:33", "subtract to previous hour"}, + {10, 3, -70, "08:53", "subtract more than an hour"}, + {0, 3, -4, "23:59", "subtract across midnight"}, + {0, 0, -160, "21:20", "subtract more than two hours"}, + {6, 15, -160, "03:35", "subtract more than two hours with borrow"}, {5, 32, -1500, "04:32", "subtract more than one day (1500 min = 25 hrs)"}, {2, 20, -3000, "00:20", "subtract more than two days"}, }; @@ -170,17 +171,16 @@ vector equalCases = { }, }; -string errorMsg(string expected, string actual, string test) -{ +string errorMsg(string expected, string actual, string test) { stringstream ret; ret << "[" << expected << " != " << actual << "] test case: " << test; return ret.str(); } -TEST_CASE("time_tests") -{ +TEST_CASE("time_tests") { for (timeTest t : timeCases) { - const auto actual = string(date_independent::clock::at(t.hour, t.minute)); + const auto actual = + string(date_independent::clock::at(t.hour, t.minute)); INFO(errorMsg(t.expected, actual, t.msg)); REQUIRE(t.expected == actual); @@ -188,18 +188,17 @@ TEST_CASE("time_tests") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("add_tests") -{ +TEST_CASE("add_tests") { for (addTest a : addCases) { - const auto actual = string(date_independent::clock::at(a.hour, a.minute).plus(a.add)); + const auto actual = + string(date_independent::clock::at(a.hour, a.minute).plus(a.add)); INFO(errorMsg(a.expected, actual, a.msg)); REQUIRE(a.expected == actual); } } -TEST_CASE("equal_tests") -{ +TEST_CASE("equal_tests") { for (equalTest e : equalCases) { const auto clock1 = date_independent::clock::at(e.c1.hour, e.c1.minute); const auto clock2 = date_independent::clock::at(e.c2.hour, e.c2.minute); @@ -207,9 +206,9 @@ TEST_CASE("equal_tests") if (e.expected) { INFO(errorMsg(string(clock1), string(clock2), e.msg)); REQUIRE(clock1 == clock2); - } - else { - INFO("[" << string(clock1) << " == " << string(clock2) << "] test case: " << e.msg); + } else { + INFO("[" << string(clock1) << " == " << string(clock2) + << "] test case: " << e.msg); REQUIRE(clock1 != clock2); } } diff --git a/exercises/practice/collatz-conjecture/.meta/example.cpp b/exercises/practice/collatz-conjecture/.meta/example.cpp index 2d131a20b..5f89108aa 100644 --- a/exercises/practice/collatz-conjecture/.meta/example.cpp +++ b/exercises/practice/collatz-conjecture/.meta/example.cpp @@ -1,8 +1,10 @@ -#include "collatz_conjecture.h" #include +#include "collatz_conjecture.h" + int collatz_conjecture::steps(int value) { - if (value <= 0) throw std::domain_error("Only positive numbers are allowed!"); + if (value <= 0) + throw std::domain_error("Only positive numbers are allowed!"); int step = 0; while (value != 1) { value = value % 2 == 0 ? value / 2 : 3 * value + 1; diff --git a/exercises/practice/collatz-conjecture/.meta/example.h b/exercises/practice/collatz-conjecture/.meta/example.h index 7c3c64c7c..abbcd5912 100644 --- a/exercises/practice/collatz-conjecture/.meta/example.h +++ b/exercises/practice/collatz-conjecture/.meta/example.h @@ -5,6 +5,6 @@ namespace collatz_conjecture { int steps(int value); -} // namespace collatz_conjecture +} // namespace collatz_conjecture #endif // !COLLATZ_CONJECTURE_H_ \ No newline at end of file diff --git a/exercises/practice/collatz-conjecture/collatz_conjecture.cpp b/exercises/practice/collatz-conjecture/collatz_conjecture.cpp index f8c1409a2..5f36fb541 100644 --- a/exercises/practice/collatz-conjecture/collatz_conjecture.cpp +++ b/exercises/practice/collatz-conjecture/collatz_conjecture.cpp @@ -1,5 +1,3 @@ #include "collatz_conjecture.h" -namespace collatz_conjecture { - -} // namespace collatz_conjecture +namespace collatz_conjecture {} // namespace collatz_conjecture diff --git a/exercises/practice/collatz-conjecture/collatz_conjecture.h b/exercises/practice/collatz-conjecture/collatz_conjecture.h index 83f8bde94..394afd2ec 100644 --- a/exercises/practice/collatz-conjecture/collatz_conjecture.h +++ b/exercises/practice/collatz-conjecture/collatz_conjecture.h @@ -1,8 +1,6 @@ #if !defined(COLLATZ_CONJECTURE_H) #define COLLATZ_CONJECTURE_H -namespace collatz_conjecture { +namespace collatz_conjecture {} // namespace collatz_conjecture -} // namespace collatz_conjecture - -#endif // COLLATZ_CONJECTURE_H \ No newline at end of file +#endif // COLLATZ_CONJECTURE_H \ No newline at end of file diff --git a/exercises/practice/collatz-conjecture/collatz_conjecture_test.cpp b/exercises/practice/collatz-conjecture/collatz_conjecture_test.cpp index c0df0f29d..d46117ac4 100644 --- a/exercises/practice/collatz-conjecture/collatz_conjecture_test.cpp +++ b/exercises/practice/collatz-conjecture/collatz_conjecture_test.cpp @@ -6,35 +6,23 @@ #endif #include -TEST_CASE("zero_steps_for_one") -{ - REQUIRE(0 == collatz_conjecture::steps(1)); -} +TEST_CASE("zero_steps_for_one") { REQUIRE(0 == collatz_conjecture::steps(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("divide_if_even") -{ - REQUIRE(4 == collatz_conjecture::steps(16)); -} +TEST_CASE("divide_if_even") { REQUIRE(4 == collatz_conjecture::steps(16)); } -TEST_CASE("even_and_odd_steps") -{ - REQUIRE(9 == collatz_conjecture::steps(12)); -} +TEST_CASE("even_and_odd_steps") { REQUIRE(9 == collatz_conjecture::steps(12)); } -TEST_CASE("large_number_of_even_and_odd_steps") -{ +TEST_CASE("large_number_of_even_and_odd_steps") { REQUIRE(152 == collatz_conjecture::steps(1000000)); } -TEST_CASE("zero_is_an_error") -{ +TEST_CASE("zero_is_an_error") { REQUIRE_THROWS_AS(collatz_conjecture::steps(0), std::domain_error); } -TEST_CASE("negative_value_is_an_error") -{ +TEST_CASE("negative_value_is_an_error") { REQUIRE_THROWS_AS(collatz_conjecture::steps(-15), std::domain_error); } #endif diff --git a/exercises/practice/complex-numbers/.meta/example.h b/exercises/practice/complex-numbers/.meta/example.h index b49d458aa..49a5ad008 100644 --- a/exercises/practice/complex-numbers/.meta/example.h +++ b/exercises/practice/complex-numbers/.meta/example.h @@ -11,7 +11,7 @@ class Complex { Complex operator-(const Complex& other) const; Complex operator*(const Complex& other) const; Complex operator/(const Complex& other) const; - + double abs() const; Complex conj() const; double real() const; diff --git a/exercises/practice/complex-numbers/complex_numbers.cpp b/exercises/practice/complex-numbers/complex_numbers.cpp index 4ff2ad0bf..538bd230c 100644 --- a/exercises/practice/complex-numbers/complex_numbers.cpp +++ b/exercises/practice/complex-numbers/complex_numbers.cpp @@ -1,5 +1,3 @@ #include "complex_numbers.h" -namespace complex_numbers { - -} // namespace complex_numbers +namespace complex_numbers {} // namespace complex_numbers diff --git a/exercises/practice/complex-numbers/complex_numbers.h b/exercises/practice/complex-numbers/complex_numbers.h index 9eca7c1f8..024916c34 100644 --- a/exercises/practice/complex-numbers/complex_numbers.h +++ b/exercises/practice/complex-numbers/complex_numbers.h @@ -1,8 +1,6 @@ #if !defined(COMPLEX_NUMBERS_H) #define COMPLEX_NUMBERS_H -namespace complex_numbers { - -} // namespace complex_numbers +namespace complex_numbers {} // namespace complex_numbers #endif // COMPLEX_NUMBERS_H diff --git a/exercises/practice/complex-numbers/complex_numbers_test.cpp b/exercises/practice/complex-numbers/complex_numbers_test.cpp index 553628574..bbaf6febc 100644 --- a/exercises/practice/complex-numbers/complex_numbers_test.cpp +++ b/exercises/practice/complex-numbers/complex_numbers_test.cpp @@ -26,47 +26,52 @@ static const double eps = 0.005; // Helper function for comparing Complex numbers with approximate float values. static void require_approx_equal(const Complex& lhs, const Complex& rhs) { - REQUIRE_THAT(lhs.real(), - Catch::Matchers::WithinAbs(rhs.real(), eps)); - REQUIRE_THAT(lhs.imag(), - Catch::Matchers::WithinAbs(rhs.imag(), eps)); + REQUIRE_THAT(lhs.real(), Catch::Matchers::WithinAbs(rhs.real(), eps)); + REQUIRE_THAT(lhs.imag(), Catch::Matchers::WithinAbs(rhs.imag(), eps)); } -TEST_CASE("Real part -> Real part of a purely real number", "[9f98e133-eb7f-45b0-9676-cce001cd6f7a]") { +TEST_CASE("Real part -> Real part of a purely real number", + "[9f98e133-eb7f-45b0-9676-cce001cd6f7a]") { const Complex c{1.0, 0.0}; REQUIRE_THAT(c.real(), Catch::Matchers::WithinAbs(1.0, eps)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Real part -> Real part of a purely imaginary number", "[07988e20-f287-4bb7-90cf-b32c4bffe0f3]") { +TEST_CASE("Real part -> Real part of a purely imaginary number", + "[07988e20-f287-4bb7-90cf-b32c4bffe0f3]") { const Complex c{0.0, 1.0}; REQUIRE_THAT(c.real(), Catch::Matchers::WithinAbs(0.0, eps)); } -TEST_CASE("Real part -> Real part of a number with real and imaginary part", "[4a370e86-939e-43de-a895-a00ca32da60a]") { +TEST_CASE("Real part -> Real part of a number with real and imaginary part", + "[4a370e86-939e-43de-a895-a00ca32da60a]") { const Complex c{1.0, 2.0}; REQUIRE_THAT(c.real(), Catch::Matchers::WithinAbs(1.0, eps)); } -TEST_CASE("Imaginary part -> Imaginary part of a purely real number", "[9b3fddef-4c12-4a99-b8f8-e3a42c7ccef6]") { +TEST_CASE("Imaginary part -> Imaginary part of a purely real number", + "[9b3fddef-4c12-4a99-b8f8-e3a42c7ccef6]") { const Complex c{1.0, 0.0}; REQUIRE_THAT(c.imag(), Catch::Matchers::WithinAbs(0.0, eps)); } -TEST_CASE("Imaginary part -> Imaginary part of a purely imaginary number", "[a8dafedd-535a-4ed3-8a39-fda103a2b01e]") { +TEST_CASE("Imaginary part -> Imaginary part of a purely imaginary number", + "[a8dafedd-535a-4ed3-8a39-fda103a2b01e]") { const Complex c{0.0, 1.0}; REQUIRE_THAT(c.imag(), Catch::Matchers::WithinAbs(1.0, eps)); } -TEST_CASE("Imaginary part -> Imaginary part of a number with real and imaginary part", "[0f998f19-69ee-4c64-80ef-01b086feab80]") { +TEST_CASE( + "Imaginary part -> Imaginary part of a number with real and imaginary part", + "[0f998f19-69ee-4c64-80ef-01b086feab80]") { const Complex c{1.0, 2.0}; - REQUIRE_THAT( c.imag(), Catch::Matchers::WithinAbs(2.0, eps)); + REQUIRE_THAT(c.imag(), Catch::Matchers::WithinAbs(2.0, eps)); } TEST_CASE("Imaginary unit", "[a39b7fd6-6527-492f-8c34-609d2c913879]") { @@ -76,217 +81,293 @@ TEST_CASE("Imaginary unit", "[a39b7fd6-6527-492f-8c34-609d2c913879]") { require_approx_equal(Complex(-1.0, 0.0), c1 * c2); } -TEST_CASE("Arithmetic -> Addition -> Add purely real numbers", "[9a2c8de9-f068-4f6f-b41c-82232cc6c33e]") { +TEST_CASE("Arithmetic -> Addition -> Add purely real numbers", + "[9a2c8de9-f068-4f6f-b41c-82232cc6c33e]") { const Complex c1{1.0, 0.0}; const Complex c2{2.0, 0.0}; require_approx_equal(Complex(3.0, 0.0), c1 + c2); } -TEST_CASE("Arithmetic -> Addition -> Add purely imaginary numbers", "[657c55e1-b14b-4ba7-bd5c-19db22b7d659]") { +TEST_CASE("Arithmetic -> Addition -> Add purely imaginary numbers", + "[657c55e1-b14b-4ba7-bd5c-19db22b7d659]") { const Complex c1{0.0, 1.0}; const Complex c2{0.0, 2.0}; require_approx_equal(Complex(0.0, 3.0), c1 + c2); } -TEST_CASE("Arithmetic -> Addition -> Add numbers with real and imaginary part", "[4e1395f5-572b-4ce8-bfa9-9a63056888da]") { +TEST_CASE("Arithmetic -> Addition -> Add numbers with real and imaginary part", + "[4e1395f5-572b-4ce8-bfa9-9a63056888da]") { const Complex c1{1.0, 2.0}; const Complex c2{3.0, 4.0}; require_approx_equal(Complex(4.0, 6.0), c1 + c2); } -TEST_CASE("Arithmetic -> Subtraction -> Subtract purely real numbers", "[1155dc45-e4f7-44b8-af34-a91aa431475d]") { +TEST_CASE("Arithmetic -> Subtraction -> Subtract purely real numbers", + "[1155dc45-e4f7-44b8-af34-a91aa431475d]") { const Complex c1{1.0, 0.0}; const Complex c2{2.0, 0.0}; require_approx_equal(Complex(-1.0, 0.0), c1 - c2); } -TEST_CASE("Arithmetic -> Subtraction -> Subtract purely imaginary numbers", "[f95e9da8-acd5-4da4-ac7c-c861b02f774b]") { +TEST_CASE("Arithmetic -> Subtraction -> Subtract purely imaginary numbers", + "[f95e9da8-acd5-4da4-ac7c-c861b02f774b]") { const Complex c1{0.0, 1.0}; const Complex c2{0.0, 2.0}; require_approx_equal(Complex(0.0, -1.0), c1 - c2); } -TEST_CASE("Arithmetic -> Subtraction -> Subtract numbers with real and imaginary part", "[f876feb1-f9d1-4d34-b067-b599a8746400]") { +TEST_CASE( + // clang-format off + "Arithmetic -> Subtraction -> Subtract numbers with real and imaginary part", + // clang-format on + "[f876feb1-f9d1-4d34-b067-b599a8746400]") { const Complex c1{1.0, 2.0}; const Complex c2{3.0, 4.0}; require_approx_equal(Complex(-2.0, -2.0), c1 - c2); } -TEST_CASE("Arithmetic -> Multiplication -> Multiply purely real numbers", "[8a0366c0-9e16-431f-9fd7-40ac46ff4ec4]") { +TEST_CASE("Arithmetic -> Multiplication -> Multiply purely real numbers", + "[8a0366c0-9e16-431f-9fd7-40ac46ff4ec4]") { const Complex c1{1.0, 0.0}; const Complex c2{2.0, 0.0}; require_approx_equal(Complex(2.0, 0.0), c1 * c2); } -TEST_CASE("Arithmetic -> Multiplication -> Multiply purely imaginary numbers", "[e560ed2b-0b80-4b4f-90f2-63cefc911aaf]") { +TEST_CASE("Arithmetic -> Multiplication -> Multiply purely imaginary numbers", + "[e560ed2b-0b80-4b4f-90f2-63cefc911aaf]") { const Complex c1{0.0, 1.0}; const Complex c2{0.0, 2.0}; require_approx_equal(Complex(-2.0, 0.0), c1 * c2); } -TEST_CASE("Arithmetic -> Multiplication -> Multiply numbers with real and imaginary part", "[4d1d10f0-f8d4-48a0-b1d0-f284ada567e6]") { +TEST_CASE( + // clang-format off + "Arithmetic -> Multiplication -> Multiply numbers with real and imaginary part", + // clang-format on + "[4d1d10f0-f8d4-48a0-b1d0-f284ada567e6]") { const Complex c1{1.0, 2.0}; const Complex c2{3.0, 4.0}; require_approx_equal(Complex(-5.0, 10.0), c1 * c2); } -TEST_CASE("Arithmetic -> Division -> Divide purely real numbers", "[b0571ddb-9045-412b-9c15-cd1d816d36c1]") { +TEST_CASE("Arithmetic -> Division -> Divide purely real numbers", + "[b0571ddb-9045-412b-9c15-cd1d816d36c1]") { const Complex c1{1.0, 0.0}; const Complex c2{2.0, 0.0}; require_approx_equal(Complex(0.5, 0.0), c1 / c2); } -TEST_CASE("Arithmetic -> Division -> Divide purely imaginary numbers", "[5bb4c7e4-9934-4237-93cc-5780764fdbdd]") { +TEST_CASE("Arithmetic -> Division -> Divide purely imaginary numbers", + "[5bb4c7e4-9934-4237-93cc-5780764fdbdd]") { const Complex c1{0.0, 1.0}; const Complex c2{0.0, 2.0}; require_approx_equal(Complex(0.5, 0.0), c1 / c2); } -TEST_CASE("Arithmetic -> Division -> Divide numbers with real and imaginary part", "[c4e7fef5-64ac-4537-91c2-c6529707701f]") { +TEST_CASE( + "Arithmetic -> Division -> Divide numbers with real and imaginary part", + "[c4e7fef5-64ac-4537-91c2-c6529707701f]") { const Complex c1{1.0, 2.0}; const Complex c2{3.0, 4.0}; require_approx_equal(Complex(0.44, 0.08), c1 / c2); } -TEST_CASE("Absolute value -> Absolute value of a positive purely real number", "[c56a7332-aad2-4437-83a0-b3580ecee843]") { +TEST_CASE("Absolute value -> Absolute value of a positive purely real number", + "[c56a7332-aad2-4437-83a0-b3580ecee843]") { const Complex c{5.0, 0.0}; REQUIRE_THAT(c.abs(), Catch::Matchers::WithinAbs(5.0, eps)); } -TEST_CASE("Absolute value -> Absolute value of a negative purely real number", "[cf88d7d3-ee74-4f4e-8a88-a1b0090ecb0c]") { +TEST_CASE("Absolute value -> Absolute value of a negative purely real number", + "[cf88d7d3-ee74-4f4e-8a88-a1b0090ecb0c]") { const Complex c{-5.0, 0.0}; REQUIRE_THAT(c.abs(), Catch::Matchers::WithinAbs(5.0, eps)); } TEST_CASE( - "Absolute value -> Absolute value of a purely imaginary number with positive imaginary part", "[bbe26568-86c1-4bb4-ba7a-da5697e2b994]") { + // clang-format off + "Absolute value -> Absolute value of a purely imaginary number with positive imaginary part", + // clang-format on + "[bbe26568-86c1-4bb4-ba7a-da5697e2b994]") { const Complex c{0.0, 5.0}; REQUIRE_THAT(c.abs(), Catch::Matchers::WithinAbs(5.0, eps)); } TEST_CASE( - "Absolute value -> Absolute value of a purely imaginary number with negative imaginary part", "[3b48233d-468e-4276-9f59-70f4ca1f26f3]") { + // clang-format off + "Absolute value -> Absolute value of a purely imaginary number with negative imaginary part", + // clang-format on + "[3b48233d-468e-4276-9f59-70f4ca1f26f3]") { const Complex c{0.0, -5.0}; REQUIRE_THAT(c.abs(), Catch::Matchers::WithinAbs(5.0, eps)); } -TEST_CASE("Absolute value -> Absolute value of a number with real and imaginary part", "[fe400a9f-aa22-4b49-af92-51e0f5a2a6d3]") { +TEST_CASE( + "Absolute value -> Absolute value of a number with real and imaginary part", + "[fe400a9f-aa22-4b49-af92-51e0f5a2a6d3]") { const Complex c{3.0, 4.0}; REQUIRE_THAT(c.abs(), Catch::Matchers::WithinAbs(5.0, eps)); } -TEST_CASE("Complex conjugate -> Conjugate a purely real number", "[fb2d0792-e55a-4484-9443-df1eddfc84a2]") { +TEST_CASE("Complex conjugate -> Conjugate a purely real number", + "[fb2d0792-e55a-4484-9443-df1eddfc84a2]") { const Complex c{5.0, 0.0}; require_approx_equal(Complex(5.0, 0.0), c.conj()); } -TEST_CASE("Complex conjugate -> Conjugate a purely imaginary number", "[e37fe7ac-a968-4694-a460-66cb605f8691]") { +TEST_CASE("Complex conjugate -> Conjugate a purely imaginary number", + "[e37fe7ac-a968-4694-a460-66cb605f8691]") { const Complex c{0.0, 5.0}; require_approx_equal(Complex(0.0, -5.0), c.conj()); } -TEST_CASE("Complex conjugate -> Conjugate a number with real and imaginary part", "[f7704498-d0be-4192-aaf5-a1f3a7f43e68]") { +TEST_CASE( + "Complex conjugate -> Conjugate a number with real and imaginary part", + "[f7704498-d0be-4192-aaf5-a1f3a7f43e68]") { const Complex c{1.0, 1.0}; require_approx_equal(Complex(1.0, -1.0), c.conj()); } -TEST_CASE("Complex exponential function -> Euler's identity/formula", "[6d96d4c6-2edb-445b-94a2-7de6d4caaf60]") { +TEST_CASE("Complex exponential function -> Euler's identity/formula", + "[6d96d4c6-2edb-445b-94a2-7de6d4caaf60]") { const Complex c{0.0, M_PI}; require_approx_equal(Complex(-1.0, 0.0), c.exp()); } -TEST_CASE("Complex exponential function -> Exponential of 0", "[2d2c05a0-4038-4427-a24d-72f6624aa45f]") { +TEST_CASE("Complex exponential function -> Exponential of 0", + "[2d2c05a0-4038-4427-a24d-72f6624aa45f]") { const Complex c{0.0, 0.0}; require_approx_equal(Complex(1.0, 0.0), c.exp()); } -TEST_CASE("Complex exponential function -> Exponential of a purely real number", "[ed87f1bd-b187-45d6-8ece-7e331232c809]") { +TEST_CASE("Complex exponential function -> Exponential of a purely real number", + "[ed87f1bd-b187-45d6-8ece-7e331232c809]") { const Complex c{1.0, 0.0}; require_approx_equal(Complex(M_E, 0.0), c.exp()); } // Extra Credit -TEST_CASE("Complex exponential function -> Exponential of a number with real and imaginary part", "[08eedacc-5a95-44fc-8789-1547b27a8702]") { +TEST_CASE( + // clang-format off + "Complex exponential function -> Exponential of a number with real and imaginary part", + // clang-format on + "[08eedacc-5a95-44fc-8789-1547b27a8702]") { const Complex c{std::log(2.0), M_PI}; require_approx_equal(Complex(-2.0, 0.0), c.exp()); } -TEST_CASE("Complex exponential function -> Exponential resulting in a number with real and imaginary part", "[d2de4375-7537-479a-aa0e-d474f4f09859]") { - const Complex c{std::log(2.0)/2.0, M_PI/4.0}; +TEST_CASE( + // clang-format off + "Complex exponential function -> Exponential resulting in a number with real and imaginary part", + // clang-format on + "[d2de4375-7537-479a-aa0e-d474f4f09859]") { + const Complex c{std::log(2.0) / 2.0, M_PI / 4.0}; require_approx_equal(Complex(1.0, 1.0), c.exp()); } -TEST_CASE("Operations between real numbers and complex numbers -> Add real number to complex number", "[06d793bf-73bd-4b02-b015-3030b2c952ec]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Add real number to complex number", + // clang-format on + "[06d793bf-73bd-4b02-b015-3030b2c952ec]") { const Complex c{1.0, 2.0}; - require_approx_equal(Complex(6.0,2.0), c + 5.0); + require_approx_equal(Complex(6.0, 2.0), c + 5.0); } -TEST_CASE("Operations between real numbers and complex numbers -> Add complex number to real number", "[d77dbbdf-b8df-43f6-a58d-3acb96765328]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Add complex number to real number", + // clang-format on + "[d77dbbdf-b8df-43f6-a58d-3acb96765328]") { const Complex c{1.0, 2.0}; - require_approx_equal(Complex(6.0,2.0), 5.0 + c); + require_approx_equal(Complex(6.0, 2.0), 5.0 + c); } -TEST_CASE("Operations between real numbers and complex numbers -> Subtract real number from complex number", "[20432c8e-8960-4c40-ba83-c9d910ff0a0f]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Subtract real number from complex number", + // clang-format on + "[20432c8e-8960-4c40-ba83-c9d910ff0a0f]") { const Complex c{5.0, 7.0}; - require_approx_equal(Complex(1.0,7.0), c - 4.0 ); + require_approx_equal(Complex(1.0, 7.0), c - 4.0); } -TEST_CASE("Operations between real numbers and complex numbers -> Subtract complex number from real number", "[b4b38c85-e1bf-437d-b04d-49bba6e55000]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Subtract complex number from real number", + // clang-format on + "[b4b38c85-e1bf-437d-b04d-49bba6e55000]") { const Complex c{5.0, 7.0}; - require_approx_equal(Complex(-1.0,-7.0), 4.0 - c); + require_approx_equal(Complex(-1.0, -7.0), 4.0 - c); } -TEST_CASE("Operations between real numbers and complex numbers -> Multiply complex number by real number", "[dabe1c8c-b8f4-44dd-879d-37d77c4d06bd]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Multiply complex number by real number", + // clang-format on + "[dabe1c8c-b8f4-44dd-879d-37d77c4d06bd]") { const Complex c{2.0, 5.0}; - require_approx_equal(Complex(10.0,25.0), c * 5.0); + require_approx_equal(Complex(10.0, 25.0), c * 5.0); } -TEST_CASE("Operations between real numbers and complex numbers -> Multiply real number by complex number", "[6c81b8c8-9851-46f0-9de5-d96d314c3a28]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Multiply real number by complex number", + // clang-format on + "[6c81b8c8-9851-46f0-9de5-d96d314c3a28]") { const Complex c{2.0, 5.0}; - require_approx_equal(Complex(10.0,25.0), 5.0 * c); + require_approx_equal(Complex(10.0, 25.0), 5.0 * c); } -TEST_CASE("Operations between real numbers and complex numbers -> Divide complex number by real number", "[8a400f75-710e-4d0c-bcb4-5e5a00c78aa0]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Divide complex number by real number", + // clang-format on + "[8a400f75-710e-4d0c-bcb4-5e5a00c78aa0]") { const Complex c{10.0, 100.0}; - require_approx_equal(Complex(1.0,10.0), c / 10.0 ); + require_approx_equal(Complex(1.0, 10.0), c / 10.0); } -TEST_CASE("Operations between real numbers and complex numbers -> Divide real number by complex number", "[9a867d1b-d736-4c41-a41e-90bd148e9d5e]") { +TEST_CASE( + // clang-format off + "Operations between real numbers and complex numbers -> Divide real number by complex number", + // clang-format on + "[9a867d1b-d736-4c41-a41e-90bd148e9d5e]") { const Complex c{1.0, 1.0}; - require_approx_equal(Complex(2.5,-2.5), 5.0 / c); + require_approx_equal(Complex(2.5, -2.5), 5.0 / c); } #endif diff --git a/exercises/practice/crypto-square/.meta/example.cpp b/exercises/practice/crypto-square/.meta/example.cpp index de8dcbbad..cd7903dd5 100644 --- a/exercises/practice/crypto-square/.meta/example.cpp +++ b/exercises/practice/crypto-square/.meta/example.cpp @@ -1,56 +1,45 @@ -#include "crypto_square.h" #include #include #include +#include "crypto_square.h" + using namespace std; -namespace -{ +namespace { -string to_lower_copy(string const& s) -{ +string to_lower_copy(string const& s) { string cpy(s); - for (auto& c: cpy) { + for (auto& c : cpy) { c = tolower(c); } return cpy; } -string normalize(string const& text) -{ +string normalize(string const& text) { string result; copy_if(text.begin(), text.end(), back_inserter(result), - [](const char c) { return !isspace(c) && !ispunct(c); }); + [](const char c) { return !isspace(c) && !ispunct(c); }); return to_lower_copy(result); } -} +} // namespace -namespace crypto_square -{ +namespace crypto_square { -cipher::cipher(string const& text) - : text_(normalize(text)) -{ -} +cipher::cipher(string const& text) : text_(normalize(text)) {} -string cipher::normalize_plain_text() const -{ - return text_; -} +string cipher::normalize_plain_text() const { return text_; } -size_t cipher::size() const -{ +size_t cipher::size() const { size_t length = 0; - while (length*length < text_.size()) { + while (length * length < text_.size()) { ++length; } return length; } -vector cipher::plain_text_segments() const -{ +vector cipher::plain_text_segments() const { vector segments; const size_t segment_size{size()}; for (size_t i = 0; i < text_.length(); i += segment_size) { @@ -59,8 +48,7 @@ vector cipher::plain_text_segments() const return segments; } -string cipher::cipher_text() const -{ +string cipher::cipher_text() const { string s{normalized_cipher_text()}; if (!s.empty()) { s.erase(remove(s.begin(), s.end(), ' '), s.end()); @@ -68,8 +56,7 @@ string cipher::cipher_text() const return s; } -string cipher::normalized_cipher_text() const -{ +string cipher::normalized_cipher_text() const { const auto num_rows = size(); const auto plain = plain_text_segments(); string result; @@ -77,8 +64,7 @@ string cipher::normalized_cipher_text() const for (string const& s : plain) { if (s.length() > i) { result += s[i]; - } - else { + } else { result += ' '; } } @@ -90,4 +76,4 @@ string cipher::normalized_cipher_text() const return result; } -} +} // namespace crypto_square diff --git a/exercises/practice/crypto-square/.meta/example.h b/exercises/practice/crypto-square/.meta/example.h index 16a5a5c6c..3ac12dc0d 100644 --- a/exercises/practice/crypto-square/.meta/example.h +++ b/exercises/practice/crypto-square/.meta/example.h @@ -4,12 +4,10 @@ #include #include -namespace crypto_square -{ +namespace crypto_square { -class cipher -{ -public: +class cipher { + public: cipher(std::string const& text); std::string normalize_plain_text() const; @@ -22,10 +20,10 @@ class cipher std::string normalized_cipher_text() const; -private: + private: std::string const text_; }; -} +} // namespace crypto_square #endif diff --git a/exercises/practice/crypto-square/crypto_square.cpp b/exercises/practice/crypto-square/crypto_square.cpp index 39089e328..e58be0f5e 100644 --- a/exercises/practice/crypto-square/crypto_square.cpp +++ b/exercises/practice/crypto-square/crypto_square.cpp @@ -1,5 +1,3 @@ #include "crypto_square.h" -namespace crypto_square { - -} // namespace crypto_square +namespace crypto_square {} // namespace crypto_square diff --git a/exercises/practice/crypto-square/crypto_square.h b/exercises/practice/crypto-square/crypto_square.h index ab43ceea1..b8d9f13fa 100644 --- a/exercises/practice/crypto-square/crypto_square.h +++ b/exercises/practice/crypto-square/crypto_square.h @@ -1,8 +1,6 @@ #if !defined(CRYPTO_SQUARE_H) #define CRYPTO_SQUARE_H -namespace crypto_square { +namespace crypto_square {} // namespace crypto_square -} // namespace crypto_square - -#endif // CRYPTO_SQUARE_H \ No newline at end of file +#endif // CRYPTO_SQUARE_H \ No newline at end of file diff --git a/exercises/practice/darts/.meta/example.cpp b/exercises/practice/darts/.meta/example.cpp index 9667aa076..236b7f744 100644 --- a/exercises/practice/darts/.meta/example.cpp +++ b/exercises/practice/darts/.meta/example.cpp @@ -1,20 +1,21 @@ -#include "darts.h" #include +#include "darts.h" + namespace darts { - int score(float x, float y) { - auto distance = std::hypot(x,y); +int score(float x, float y) { + auto distance = std::hypot(x, y); - if (distance <= 1.0) { - return 10; - } else if (distance <= 5.0) { - return 5; - } else if (distance <= 10.0) { - return 1; - } else { - return 0; - } + if (distance <= 1.0) { + return 10; + } else if (distance <= 5.0) { + return 5; + } else if (distance <= 10.0) { + return 1; + } else { + return 0; } +} -} // namespace darts +} // namespace darts diff --git a/exercises/practice/darts/.meta/example.h b/exercises/practice/darts/.meta/example.h index 5d132c122..cf3fb376c 100644 --- a/exercises/practice/darts/.meta/example.h +++ b/exercises/practice/darts/.meta/example.h @@ -3,8 +3,8 @@ namespace darts { - int score(float x, float y); +int score(float x, float y); -} // namespace darts +} // namespace darts -#endif //DARTS_H \ No newline at end of file +#endif // DARTS_H \ No newline at end of file diff --git a/exercises/practice/darts/darts.cpp b/exercises/practice/darts/darts.cpp index 197a0364c..4bb23fd23 100644 --- a/exercises/practice/darts/darts.cpp +++ b/exercises/practice/darts/darts.cpp @@ -1,5 +1,3 @@ #include "darts.h" -namespace darts { - -} // namespace darts \ No newline at end of file +namespace darts {} // namespace darts \ No newline at end of file diff --git a/exercises/practice/darts/darts.h b/exercises/practice/darts/darts.h index 46f69516c..a80346d5e 100644 --- a/exercises/practice/darts/darts.h +++ b/exercises/practice/darts/darts.h @@ -1,8 +1,6 @@ #if !defined(DARTS_H) #define DARTS_H -namespace darts { +namespace darts {} // namespace darts -} // namespace darts - -#endif //DARTS_H \ No newline at end of file +#endif // DARTS_H \ No newline at end of file diff --git a/exercises/practice/darts/darts_test.cpp b/exercises/practice/darts/darts_test.cpp index 83ffa1be2..4c3164ebe 100644 --- a/exercises/practice/darts/darts_test.cpp +++ b/exercises/practice/darts/darts_test.cpp @@ -5,70 +5,44 @@ #include "test/catch.hpp" #endif - -TEST_CASE("missed_target") -{ - REQUIRE(darts::score(-9,9) == 0); -} +TEST_CASE("missed_target") { REQUIRE(darts::score(-9, 9) == 0); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("on_the_outer_circle") -{ - REQUIRE(darts::score(0,10) == 1); -} +TEST_CASE("on_the_outer_circle") { REQUIRE(darts::score(0, 10) == 1); } -TEST_CASE("on_the_middle_circle") -{ - REQUIRE(darts::score(-5,0) == 5); -} +TEST_CASE("on_the_middle_circle") { REQUIRE(darts::score(-5, 0) == 5); } -TEST_CASE("on_the_inner_circle") -{ - REQUIRE(darts::score(0,-1) == 10); -} +TEST_CASE("on_the_inner_circle") { REQUIRE(darts::score(0, -1) == 10); } -TEST_CASE("exactly_on_centre") -{ - REQUIRE(darts::score(0,0) == 10); -} +TEST_CASE("exactly_on_centre") { REQUIRE(darts::score(0, 0) == 10); } -TEST_CASE("near_the_centre") -{ - REQUIRE(darts::score(-0.1,-0.1) == 10); -} +TEST_CASE("near_the_centre") { REQUIRE(darts::score(-0.1, -0.1) == 10); } -TEST_CASE("just_within_the_inner_circle") -{ - REQUIRE(darts::score(0.7,0.7) == 10); +TEST_CASE("just_within_the_inner_circle") { + REQUIRE(darts::score(0.7, 0.7) == 10); } -TEST_CASE("just_outside_the_inner_circle") -{ - REQUIRE(darts::score(0.8,-0.8) == 5); +TEST_CASE("just_outside_the_inner_circle") { + REQUIRE(darts::score(0.8, -0.8) == 5); } -TEST_CASE("just_within_the_middle_circle") -{ - REQUIRE(darts::score(-3.5,3.5) == 5); +TEST_CASE("just_within_the_middle_circle") { + REQUIRE(darts::score(-3.5, 3.5) == 5); } -TEST_CASE("just_outside_the_middle_circle") -{ - REQUIRE(darts::score(-3.6,-3.6) == 1); +TEST_CASE("just_outside_the_middle_circle") { + REQUIRE(darts::score(-3.6, -3.6) == 1); } -TEST_CASE("just_within_the_outer_circle") -{ - REQUIRE(darts::score(-7.0,7.0) == 1); +TEST_CASE("just_within_the_outer_circle") { + REQUIRE(darts::score(-7.0, 7.0) == 1); } -TEST_CASE("just_outside_the_outer_circle") -{ - REQUIRE(darts::score(7.1,-7.1) == 0); +TEST_CASE("just_outside_the_outer_circle") { + REQUIRE(darts::score(7.1, -7.1) == 0); } -TEST_CASE("asymmetric_position_between_the_inner_and_middle_circles") -{ - REQUIRE(darts::score(0.5,-4) == 5); +TEST_CASE("asymmetric_position_between_the_inner_and_middle_circles") { + REQUIRE(darts::score(0.5, -4) == 5); } #endif diff --git a/exercises/practice/diamond/.meta/example.cpp b/exercises/practice/diamond/.meta/example.cpp index a49cc9333..1b990d5e8 100644 --- a/exercises/practice/diamond/.meta/example.cpp +++ b/exercises/practice/diamond/.meta/example.cpp @@ -1,25 +1,25 @@ #include "diamond.h" namespace diamond { - std::vector rows(char middle_letter) { - if (middle_letter == 'A') return {"A"}; - std::vector diamond; - for(char c{'A'}; c <= middle_letter; ++c) { - int outer_spacing = middle_letter - c; - std::string row{}; - row.append(outer_spacing, ' '); +std::vector rows(char middle_letter) { + if (middle_letter == 'A') return {"A"}; + std::vector diamond; + for (char c{'A'}; c <= middle_letter; ++c) { + int outer_spacing = middle_letter - c; + std::string row{}; + row.append(outer_spacing, ' '); + row += c; + int inner_spacing = (c - 'A') * 2 - 1; + if (inner_spacing > 0) { + row.append(inner_spacing, ' '); row += c; - int inner_spacing = (c - 'A') * 2 - 1; - if (inner_spacing > 0) { - row.append(inner_spacing, ' '); - row += c; - } - row.append(outer_spacing, ' '); - diamond.emplace_back(row); } - for(int i{middle_letter - 'A' - 1}; i >= 0; --i) { - diamond.emplace_back(diamond.at(i)); - } - return diamond; + row.append(outer_spacing, ' '); + diamond.emplace_back(row); + } + for (int i{middle_letter - 'A' - 1}; i >= 0; --i) { + diamond.emplace_back(diamond.at(i)); } + return diamond; +} } // namespace diamond diff --git a/exercises/practice/diamond/.meta/example.h b/exercises/practice/diamond/.meta/example.h index 24cae35dd..afd04ae4b 100644 --- a/exercises/practice/diamond/.meta/example.h +++ b/exercises/practice/diamond/.meta/example.h @@ -4,5 +4,5 @@ #include namespace diamond { - std::vector rows(char middle_letter); +std::vector rows(char middle_letter); } // namespace diamond diff --git a/exercises/practice/diamond/diamond.cpp b/exercises/practice/diamond/diamond.cpp index 153f52c1f..e843626c5 100644 --- a/exercises/practice/diamond/diamond.cpp +++ b/exercises/practice/diamond/diamond.cpp @@ -1,5 +1,3 @@ #include "diamond.h" -namespace diamond { - -} // namespace diamond +namespace diamond {} // namespace diamond diff --git a/exercises/practice/diamond/diamond.h b/exercises/practice/diamond/diamond.h index 6c8c5d36d..8643cc133 100644 --- a/exercises/practice/diamond/diamond.h +++ b/exercises/practice/diamond/diamond.h @@ -1,5 +1,3 @@ #pragma once -namespace diamond { - -} // namespace diamond +namespace diamond {} // namespace diamond diff --git a/exercises/practice/diamond/diamond_test.cpp b/exercises/practice/diamond/diamond_test.cpp index 81ab249ea..e6447e515 100644 --- a/exercises/practice/diamond/diamond_test.cpp +++ b/exercises/practice/diamond/diamond_test.cpp @@ -5,112 +5,106 @@ #include "test/catch.hpp" #endif - /* - The tests contained within this canonical data file are suitable - for value-based testing, in which each test case checks that the - value returned by the function under test is in every way - identical to a given expected value. - - This exercise is also amenable to property-based testing, in which - each test case verifies that the value returned by the function - under test exhibits a specific desired property. - - Several tracks (notably, C# and Go) forgo the value-based tests - below in favor of property-based tests. If you are feeling - adventurous and would like to use this exercise to introduce the - concept of property-based testing to participants in your track, - please ignore the value-based tests below and instead reference - the test suites in the aforementioned tracks. -*/ + The tests contained within this canonical data file are suitable + for value-based testing, in which each test case checks that the + value returned by the function under test is in every way + identical to a given expected value. -TEST_CASE("Degenerate case with a single 'A' row", "[202fb4cc-6a38-4883-9193-a29d5cb92076]") { - std::vector expected{"A"}; - REQUIRE(diamond::rows('A') == expected); -} + This exercise is also amenable to property-based testing, in which + each test case verifies that the value returned by the function + under test exhibits a specific desired property. + Several tracks (notably, C# and Go) forgo the value-based tests + below in favor of property-based tests. If you are feeling + adventurous and would like to use this exercise to introduce the + concept of property-based testing to participants in your track, + please ignore the value-based tests below and instead reference + the test suites in the aforementioned tracks. +*/ +TEST_CASE("Degenerate case with a single 'A' row", + "[202fb4cc-6a38-4883-9193-a29d5cb92076]") { + std::vector expected{"A"}; + REQUIRE(diamond::rows('A') == expected); +} -TEST_CASE("Degenerate case with no row containing 3 distinct groups of spaces", "[bd6a6d78-9302-42e9-8f60-ac1461e9abae]") { - std::vector expected{" A ", - "B B", - " A "}; - REQUIRE(diamond::rows('B') == expected); +TEST_CASE("Degenerate case with no row containing 3 distinct groups of spaces", + "[bd6a6d78-9302-42e9-8f60-ac1461e9abae]") { + std::vector expected{" A ", "B B", " A "}; + REQUIRE(diamond::rows('B') == expected); } -TEST_CASE("Smallest non-degenerate case with odd diamond side length", "[af8efb49-14ed-447f-8944-4cc59ce3fd76]") { - std::vector expected{" A ", - " B B ", - "C C", - " B B ", - " A "}; - REQUIRE(diamond::rows('C') == expected); +TEST_CASE("Smallest non-degenerate case with odd diamond side length", + "[af8efb49-14ed-447f-8944-4cc59ce3fd76]") { + std::vector expected{" A ", " B B ", "C C", " B B ", + " A "}; + REQUIRE(diamond::rows('C') == expected); } -TEST_CASE("Smallest non-degenerate case with even diamond side length", "[e0c19a95-9888-4d05-86a0-fa81b9e70d1d]") { - std::vector expected{" A ", - " B B ", - " C C ", - "D D", - " C C ", - " B B ", - " A "}; - REQUIRE(diamond::rows('D') == expected); +TEST_CASE("Smallest non-degenerate case with even diamond side length", + "[e0c19a95-9888-4d05-86a0-fa81b9e70d1d]") { + std::vector expected{" A ", " B B ", " C C ", + "D D", " C C ", " B B ", + " A "}; + REQUIRE(diamond::rows('D') == expected); } -TEST_CASE("Largest possible diamond", "[82ea9aa9-4c0e-442a-b07e-40204e925944]") { - std::vector expected{" A ", - " B B ", - " C C ", - " D D ", - " E E ", - " F F ", - " G G ", - " H H ", - " I I ", - " J J ", - " K K ", - " L L ", - " M M ", - " N N ", - " O O ", - " P P ", - " Q Q ", - " R R ", - " S S ", - " T T ", - " U U ", - " V V ", - " W W ", - " X X ", - " Y Y ", - "Z Z", - " Y Y ", - " X X ", - " W W ", - " V V ", - " U U ", - " T T ", - " S S ", - " R R ", - " Q Q ", - " P P ", - " O O ", - " N N ", - " M M ", - " L L ", - " K K ", - " J J ", - " I I ", - " H H ", - " G G ", - " F F ", - " E E ", - " D D ", - " C C ", - " B B ", - " A "}; - REQUIRE(diamond::rows('Z') == expected); +TEST_CASE("Largest possible diamond", + "[82ea9aa9-4c0e-442a-b07e-40204e925944]") { + std::vector expected{ + " A ", + " B B ", + " C C ", + " D D ", + " E E ", + " F F ", + " G G ", + " H H ", + " I I ", + " J J ", + " K K ", + " L L ", + " M M ", + " N N ", + " O O ", + " P P ", + " Q Q ", + " R R ", + " S S ", + " T T ", + " U U ", + " V V ", + " W W ", + " X X ", + " Y Y ", + "Z Z", + " Y Y ", + " X X ", + " W W ", + " V V ", + " U U ", + " T T ", + " S S ", + " R R ", + " Q Q ", + " P P ", + " O O ", + " N N ", + " M M ", + " L L ", + " K K ", + " J J ", + " I I ", + " H H ", + " G G ", + " F F ", + " E E ", + " D D ", + " C C ", + " B B ", + " A "}; + REQUIRE(diamond::rows('Z') == expected); } #if defined(EXERCISM_RUN_ALL_TESTS) #endif diff --git a/exercises/practice/difference-of-squares/.meta/example.cpp b/exercises/practice/difference-of-squares/.meta/example.cpp index 1f124f025..9440e5279 100644 --- a/exercises/practice/difference-of-squares/.meta/example.cpp +++ b/exercises/practice/difference-of-squares/.meta/example.cpp @@ -1,32 +1,27 @@ -#include "difference_of_squares.h" #include +#include "difference_of_squares.h" + using namespace std; -namespace difference_of_squares -{ +namespace difference_of_squares { -int square_of_sum(int n) -{ +int square_of_sum(int n) { int sum = 0; for (int i = 1; i <= n; ++i) { sum += i; } - return sum*sum; + return sum * sum; } -int sum_of_squares(int n) -{ +int sum_of_squares(int n) { int sum = 0; for (int i = 1; i <= n; ++i) { - sum += i*i; + sum += i * i; } return sum; } -int difference(int n) -{ - return square_of_sum(n) - sum_of_squares(n); -} +int difference(int n) { return square_of_sum(n) - sum_of_squares(n); } -} +} // namespace difference_of_squares diff --git a/exercises/practice/difference-of-squares/.meta/example.h b/exercises/practice/difference-of-squares/.meta/example.h index cac055564..dff8d4aeb 100644 --- a/exercises/practice/difference-of-squares/.meta/example.h +++ b/exercises/practice/difference-of-squares/.meta/example.h @@ -1,13 +1,12 @@ #if !defined(DIFFERENCE_OF_SQUARES_H) #define DIFFERENCE_OF_SQUARES_H -namespace difference_of_squares -{ +namespace difference_of_squares { int square_of_sum(int n); int sum_of_squares(int n); int difference(int n); -} +} // namespace difference_of_squares #endif diff --git a/exercises/practice/difference-of-squares/difference_of_squares.cpp b/exercises/practice/difference-of-squares/difference_of_squares.cpp index ae1287eb5..194de17f9 100644 --- a/exercises/practice/difference-of-squares/difference_of_squares.cpp +++ b/exercises/practice/difference-of-squares/difference_of_squares.cpp @@ -1,5 +1,3 @@ #include "difference_of_squares.h" -namespace difference_of_squares { - -} // namespace difference_of_squares +namespace difference_of_squares {} // namespace difference_of_squares diff --git a/exercises/practice/difference-of-squares/difference_of_squares.h b/exercises/practice/difference-of-squares/difference_of_squares.h index 1196425dc..e3249fb4d 100644 --- a/exercises/practice/difference-of-squares/difference_of_squares.h +++ b/exercises/practice/difference-of-squares/difference_of_squares.h @@ -1,8 +1,6 @@ #if !defined(DIFFERENCE_OF_SQUARES_H) #define DIFFERENCE_OF_SQUARES_H -namespace difference_of_squares { +namespace difference_of_squares {} // namespace difference_of_squares -} // namespace difference_of_squares - -#endif // DIFFERENCE_OF_SQUARES_H \ No newline at end of file +#endif // DIFFERENCE_OF_SQUARES_H \ No newline at end of file diff --git a/exercises/practice/difference-of-squares/difference_of_squares_test.cpp b/exercises/practice/difference-of-squares/difference_of_squares_test.cpp index e3a882a80..13bf302f6 100644 --- a/exercises/practice/difference-of-squares/difference_of_squares_test.cpp +++ b/exercises/practice/difference-of-squares/difference_of_squares_test.cpp @@ -5,23 +5,20 @@ #include "test/catch.hpp" #endif -TEST_CASE("up_to_5") -{ +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") -{ +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") -{ +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)); diff --git a/exercises/practice/dnd-character/.meta/example.cpp b/exercises/practice/dnd-character/.meta/example.cpp index 1ea2761a3..b14c8fe21 100644 --- a/exercises/practice/dnd-character/.meta/example.cpp +++ b/exercises/practice/dnd-character/.meta/example.cpp @@ -1,10 +1,10 @@ -#include "dnd_character.h" - #include #include #include #include +#include "dnd_character.h" + namespace dnd_character { int modifier(int score) { return std::floor((static_cast(score) - 10) / 2); diff --git a/exercises/practice/dnd-character/dnd_character.cpp b/exercises/practice/dnd-character/dnd_character.cpp index d2221a81f..d1a6918ff 100644 --- a/exercises/practice/dnd-character/dnd_character.cpp +++ b/exercises/practice/dnd-character/dnd_character.cpp @@ -1,5 +1,3 @@ #include "dnd_character.h" -namespace dnd_character { - -} // namespace dnd_character +namespace dnd_character {} // namespace dnd_character diff --git a/exercises/practice/dnd-character/dnd_character.h b/exercises/practice/dnd-character/dnd_character.h index ccd2298d5..1d94ad71b 100644 --- a/exercises/practice/dnd-character/dnd_character.h +++ b/exercises/practice/dnd-character/dnd_character.h @@ -1,5 +1,3 @@ #pragma once -namespace dnd_character { - -} // namespace dnd_character +namespace dnd_character {} // namespace dnd_character diff --git a/exercises/practice/dnd-character/dnd_character_test.cpp b/exercises/practice/dnd-character/dnd_character_test.cpp index b13a59b83..13bcbad88 100644 --- a/exercises/practice/dnd-character/dnd_character_test.cpp +++ b/exercises/practice/dnd-character/dnd_character_test.cpp @@ -13,10 +13,9 @@ using namespace Catch::Matchers; template class IsBetweenMatcher : public MatcherBase { T m_begin, m_end; -public: - IsBetweenMatcher(T begin, T end) : - m_begin(begin), m_end(end) { - } + + public: + IsBetweenMatcher(T begin, T end) : m_begin(begin), m_end(end) {} bool match(T const& in) const override { return in >= m_begin && in <= m_end; } @@ -27,86 +26,105 @@ class IsBetweenMatcher : public MatcherBase { } }; -TEST_CASE("ability modifier for score 3 is -4", "[1e9ae1dc-35bd-43ba-aa08-e4b94c20fa37]") { - REQUIRE(-4 == dnd_character::modifier(3)); +TEST_CASE("ability modifier for score 3 is -4", + "[1e9ae1dc-35bd-43ba-aa08-e4b94c20fa37]") { + REQUIRE(-4 == dnd_character::modifier(3)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("ability modifier for score 4 is -3", "[cc9bb24e-56b8-4e9e-989d-a0d1a29ebb9c]") { - REQUIRE(-3 == dnd_character::modifier(4)); +TEST_CASE("ability modifier for score 4 is -3", + "[cc9bb24e-56b8-4e9e-989d-a0d1a29ebb9c]") { + REQUIRE(-3 == dnd_character::modifier(4)); } -TEST_CASE("ability modifier for score 5 is -3", "[5b519fcd-6946-41ee-91fe-34b4f9808326]") { - REQUIRE(-3 == dnd_character::modifier(5)); +TEST_CASE("ability modifier for score 5 is -3", + "[5b519fcd-6946-41ee-91fe-34b4f9808326]") { + REQUIRE(-3 == dnd_character::modifier(5)); } -TEST_CASE("ability modifier for score 6 is -2", "[dc2913bd-6d7a-402e-b1e2-6d568b1cbe21]") { - REQUIRE(-2 == dnd_character::modifier(6)); +TEST_CASE("ability modifier for score 6 is -2", + "[dc2913bd-6d7a-402e-b1e2-6d568b1cbe21]") { + REQUIRE(-2 == dnd_character::modifier(6)); } -TEST_CASE("ability modifier for score 7 is -2", "[099440f5-0d66-4b1a-8a10-8f3a03cc499f]") { - REQUIRE(-2 == dnd_character::modifier(7)); +TEST_CASE("ability modifier for score 7 is -2", + "[099440f5-0d66-4b1a-8a10-8f3a03cc499f]") { + REQUIRE(-2 == dnd_character::modifier(7)); } -TEST_CASE("ability modifier for score 8 is -1", "[cfda6e5c-3489-42f0-b22b-4acb47084df0]") { - REQUIRE(-1 == dnd_character::modifier(8)); +TEST_CASE("ability modifier for score 8 is -1", + "[cfda6e5c-3489-42f0-b22b-4acb47084df0]") { + REQUIRE(-1 == dnd_character::modifier(8)); } -TEST_CASE("ability modifier for score 9 is -1", "[c70f0507-fa7e-4228-8463-858bfbba1754]") { - REQUIRE(-1 == dnd_character::modifier(9)); +TEST_CASE("ability modifier for score 9 is -1", + "[c70f0507-fa7e-4228-8463-858bfbba1754]") { + REQUIRE(-1 == dnd_character::modifier(9)); } -TEST_CASE("ability modifier for score 10 is 0", "[6f4e6c88-1cd9-46a0-92b8-db4a99b372f7]") { - REQUIRE(0 == dnd_character::modifier(10)); +TEST_CASE("ability modifier for score 10 is 0", + "[6f4e6c88-1cd9-46a0-92b8-db4a99b372f7]") { + REQUIRE(0 == dnd_character::modifier(10)); } -TEST_CASE("ability modifier for score 11 is 0", "[e00d9e5c-63c8-413f-879d-cd9be9697097]") { - REQUIRE(0 == dnd_character::modifier(11)); +TEST_CASE("ability modifier for score 11 is 0", + "[e00d9e5c-63c8-413f-879d-cd9be9697097]") { + REQUIRE(0 == dnd_character::modifier(11)); } -TEST_CASE("ability modifier for score 12 is +1", "[eea06f3c-8de0-45e7-9d9d-b8cab4179715]") { - REQUIRE(1 == dnd_character::modifier(12)); +TEST_CASE("ability modifier for score 12 is +1", + "[eea06f3c-8de0-45e7-9d9d-b8cab4179715]") { + REQUIRE(1 == dnd_character::modifier(12)); } -TEST_CASE("ability modifier for score 13 is +1", "[9c51f6be-db72-4af7-92ac-b293a02c0dcd]") { - REQUIRE(1 == dnd_character::modifier(13)); +TEST_CASE("ability modifier for score 13 is +1", + "[9c51f6be-db72-4af7-92ac-b293a02c0dcd]") { + REQUIRE(1 == dnd_character::modifier(13)); } -TEST_CASE("ability modifier for score 14 is +2", "[94053a5d-53b6-4efc-b669-a8b5098f7762]") { - REQUIRE(2 == dnd_character::modifier(14)); +TEST_CASE("ability modifier for score 14 is +2", + "[94053a5d-53b6-4efc-b669-a8b5098f7762]") { + REQUIRE(2 == dnd_character::modifier(14)); } -TEST_CASE("ability modifier for score 15 is +2", "[8c33e7ca-3f9f-4820-8ab3-65f2c9e2f0e2]") { - REQUIRE(2 == dnd_character::modifier(15)); +TEST_CASE("ability modifier for score 15 is +2", + "[8c33e7ca-3f9f-4820-8ab3-65f2c9e2f0e2]") { + REQUIRE(2 == dnd_character::modifier(15)); } -TEST_CASE("ability modifier for score 16 is +3", "[c3ec871e-1791-44d0-b3cc-77e5fb4cd33d]") { - REQUIRE(3 == dnd_character::modifier(16)); +TEST_CASE("ability modifier for score 16 is +3", + "[c3ec871e-1791-44d0-b3cc-77e5fb4cd33d]") { + REQUIRE(3 == dnd_character::modifier(16)); } -TEST_CASE("ability modifier for score 17 is +3", "[3d053cee-2888-4616-b9fd-602a3b1efff4]") { - REQUIRE(3 == dnd_character::modifier(17)); +TEST_CASE("ability modifier for score 17 is +3", + "[3d053cee-2888-4616-b9fd-602a3b1efff4]") { + REQUIRE(3 == dnd_character::modifier(17)); } -TEST_CASE("ability modifier for score 18 is +4", "[bafd997a-e852-4e56-9f65-14b60261faee]") { - REQUIRE(4 == dnd_character::modifier(18)); +TEST_CASE("ability modifier for score 18 is +4", + "[bafd997a-e852-4e56-9f65-14b60261faee]") { + REQUIRE(4 == dnd_character::modifier(18)); } -TEST_CASE("random ability is within range", "[4f28f19c-2e47-4453-a46a-c0d365259c14]") { - int result{dnd_character::ability()}; - CHECK_THAT(result, IsBetweenMatcher(3, 18)); +TEST_CASE("random ability is within range", + "[4f28f19c-2e47-4453-a46a-c0d365259c14]") { + int result{dnd_character::ability()}; + CHECK_THAT(result, IsBetweenMatcher(3, 18)); } -TEST_CASE("random character is valid", "[385d7e72-864f-4e88-8279-81a7d75b04ad]") { - dnd_character::Character character; - CHECK_THAT(character.strength, IsBetweenMatcher(3, 18)); - CHECK_THAT(character.dexterity, IsBetweenMatcher(3, 18)); - CHECK_THAT(character.constitution, IsBetweenMatcher(3, 18)); - CHECK_THAT(character.intelligence, IsBetweenMatcher(3, 18)); - CHECK_THAT(character.wisdom, IsBetweenMatcher(3, 18)); - CHECK_THAT(character.charisma, IsBetweenMatcher(3, 18)); - REQUIRE(character.hitpoints == 10 + dnd_character::modifier(character.constitution)); +TEST_CASE("random character is valid", + "[385d7e72-864f-4e88-8279-81a7d75b04ad]") { + dnd_character::Character character; + CHECK_THAT(character.strength, IsBetweenMatcher(3, 18)); + CHECK_THAT(character.dexterity, IsBetweenMatcher(3, 18)); + CHECK_THAT(character.constitution, IsBetweenMatcher(3, 18)); + CHECK_THAT(character.intelligence, IsBetweenMatcher(3, 18)); + CHECK_THAT(character.wisdom, IsBetweenMatcher(3, 18)); + CHECK_THAT(character.charisma, IsBetweenMatcher(3, 18)); + REQUIRE(character.hitpoints == + 10 + dnd_character::modifier(character.constitution)); } #endif diff --git a/exercises/practice/eliuds-eggs/.meta/example.cpp b/exercises/practice/eliuds-eggs/.meta/example.cpp index dee2c3005..a1f151157 100644 --- a/exercises/practice/eliuds-eggs/.meta/example.cpp +++ b/exercises/practice/eliuds-eggs/.meta/example.cpp @@ -1,12 +1,12 @@ #include "eliuds_eggs.h" namespace chicken_coop { - int positions_to_quantity(int display_value) { - int counter{}; - while (display_value != 0) { - if (display_value % 2) ++counter; - display_value /= 2; - } - return counter; +int positions_to_quantity(int display_value) { + int counter{}; + while (display_value != 0) { + if (display_value % 2) ++counter; + display_value /= 2; } + return counter; +} } // namespace chicken_coop diff --git a/exercises/practice/eliuds-eggs/.meta/example.h b/exercises/practice/eliuds-eggs/.meta/example.h index f49d373dc..d1483f53f 100644 --- a/exercises/practice/eliuds-eggs/.meta/example.h +++ b/exercises/practice/eliuds-eggs/.meta/example.h @@ -1,5 +1,5 @@ #pragma once namespace chicken_coop { - int positions_to_quantity(int display_value); +int positions_to_quantity(int display_value); } // namespace chicken_coop diff --git a/exercises/practice/eliuds-eggs/eliuds_eggs.cpp b/exercises/practice/eliuds-eggs/eliuds_eggs.cpp index 373e489bd..273990e91 100644 --- a/exercises/practice/eliuds-eggs/eliuds_eggs.cpp +++ b/exercises/practice/eliuds-eggs/eliuds_eggs.cpp @@ -1,7 +1,3 @@ #include "eliuds_eggs.h" -namespace chicken_coop { - - - -} // namespace chicken_coop +namespace chicken_coop {} // namespace chicken_coop diff --git a/exercises/practice/eliuds-eggs/eliuds_eggs.h b/exercises/practice/eliuds-eggs/eliuds_eggs.h index 914fc563e..52e314fd7 100644 --- a/exercises/practice/eliuds-eggs/eliuds_eggs.h +++ b/exercises/practice/eliuds-eggs/eliuds_eggs.h @@ -1,7 +1,3 @@ #pragma once -namespace chicken_coop { - - - -} // namespace chicken_coop +namespace chicken_coop {} // namespace chicken_coop diff --git a/exercises/practice/eliuds-eggs/eliuds_eggs_test.cpp b/exercises/practice/eliuds-eggs/eliuds_eggs_test.cpp index 1e55c4f14..444567efe 100644 --- a/exercises/practice/eliuds-eggs/eliuds_eggs_test.cpp +++ b/exercises/practice/eliuds-eggs/eliuds_eggs_test.cpp @@ -5,25 +5,15 @@ #include "test/catch.hpp" #endif -TEST_CASE("0 eggs") -{ - REQUIRE(chicken_coop::positions_to_quantity(0) == 0); -} +TEST_CASE("0 eggs") { REQUIRE(chicken_coop::positions_to_quantity(0) == 0); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("1 egg") -{ - REQUIRE(chicken_coop::positions_to_quantity(16) == 1); -} +TEST_CASE("1 egg") { REQUIRE(chicken_coop::positions_to_quantity(16) == 1); } -TEST_CASE("4 eggs") -{ - REQUIRE(chicken_coop::positions_to_quantity(89) == 4); -} +TEST_CASE("4 eggs") { REQUIRE(chicken_coop::positions_to_quantity(89) == 4); } -TEST_CASE("13 eggs") -{ +TEST_CASE("13 eggs") { REQUIRE(chicken_coop::positions_to_quantity(2000000000) == 13); } diff --git a/exercises/practice/etl/.meta/example.cpp b/exercises/practice/etl/.meta/example.cpp index c46cab716..e8f5ff675 100644 --- a/exercises/practice/etl/.meta/example.cpp +++ b/exercises/practice/etl/.meta/example.cpp @@ -1,13 +1,12 @@ -#include "etl.h" #include +#include "etl.h" + using namespace std; -namespace etl -{ +namespace etl { -map transform(map> const& old) -{ +map transform(map> const& old) { map result; for (auto const& item : old) { for (char c : item.second) { @@ -17,4 +16,4 @@ map transform(map> const& old) return result; } -} +} // namespace etl diff --git a/exercises/practice/etl/.meta/example.h b/exercises/practice/etl/.meta/example.h index 961b6da12..33541b069 100644 --- a/exercises/practice/etl/.meta/example.h +++ b/exercises/practice/etl/.meta/example.h @@ -4,8 +4,7 @@ #include #include -namespace etl -{ +namespace etl { std::map transform(std::map> const& old); diff --git a/exercises/practice/etl/etl.cpp b/exercises/practice/etl/etl.cpp index 4d645cec3..8655b0273 100644 --- a/exercises/practice/etl/etl.cpp +++ b/exercises/practice/etl/etl.cpp @@ -1,5 +1,3 @@ #include "etl.h" -namespace etl { - -} // namespace etl +namespace etl {} // namespace etl diff --git a/exercises/practice/etl/etl.h b/exercises/practice/etl/etl.h index a38ebe042..a0a0406a7 100644 --- a/exercises/practice/etl/etl.h +++ b/exercises/practice/etl/etl.h @@ -1,8 +1,6 @@ #if !defined(ETL_H) #define ETL_H -namespace etl { +namespace etl {} // namespace etl -} // namespace etl - -#endif // ETL_H \ No newline at end of file +#endif // ETL_H \ No newline at end of file diff --git a/exercises/practice/etl/etl_test.cpp b/exercises/practice/etl/etl_test.cpp index eb5b62a5e..ca009c5fb 100644 --- a/exercises/practice/etl/etl_test.cpp +++ b/exercises/practice/etl/etl_test.cpp @@ -1,4 +1,5 @@ #include "etl.h" + #include #ifdef EXERCISM_TEST_SUITE #include @@ -6,8 +7,7 @@ #include "test/catch.hpp" #endif -TEST_CASE("transforms_one_value") -{ +TEST_CASE("transforms_one_value") { const std::map> old{{1, {'A'}}}; const auto actual = etl::transform(old); @@ -17,19 +17,19 @@ TEST_CASE("transforms_one_value") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("transforms_more_values") -{ +TEST_CASE("transforms_more_values") { const std::map> old{{1, {'A', 'E', 'I', 'O', 'U'}}}; const auto actual = etl::transform(old); - const std::map expected{{'a', 1}, {'e', 1}, {'i', 1}, {'o', 1}, {'u', 1}}; + const std::map expected{ + {'a', 1}, {'e', 1}, {'i', 1}, {'o', 1}, {'u', 1}}; REQUIRE(expected == actual); } -TEST_CASE("transforms_more_keys") -{ - const std::map> old{{1, {'A', 'E'}}, {2, {'D', 'G'}}}; +TEST_CASE("transforms_more_keys") { + const std::map> old{{1, {'A', 'E'}}, + {2, {'D', 'G'}}}; const auto actual = etl::transform(old); @@ -37,8 +37,7 @@ TEST_CASE("transforms_more_keys") REQUIRE(expected == actual); } -TEST_CASE("transforms_a_full_dataset") -{ +TEST_CASE("transforms_a_full_dataset") { const std::map> old{ {1, {'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'}}, {2, {'D', 'G'}}, @@ -46,19 +45,15 @@ TEST_CASE("transforms_a_full_dataset") {4, {'F', 'H', 'V', 'W', 'Y'}}, {5, {'K'}}, {8, {'J', 'X'}}, - {10, {'Q', 'Z'}} - }; + {10, {'Q', 'Z'}}}; const auto actual = etl::transform(old); const std::map expected{ - {'a', 1}, {'b', 3}, {'c', 3}, {'d', 2}, {'e', 1}, - {'f', 4}, {'g', 2}, {'h', 4}, {'i', 1}, {'j', 8}, - {'k', 5}, {'l', 1}, {'m', 3}, {'n', 1}, {'o', 1}, - {'p', 3}, {'q', 10}, {'r', 1}, {'s', 1}, {'t', 1}, - {'u', 1}, {'v', 4}, {'w', 4}, {'x', 8}, {'y', 4}, - {'z', 10} - }; + {'a', 1}, {'b', 3}, {'c', 3}, {'d', 2}, {'e', 1}, {'f', 4}, {'g', 2}, + {'h', 4}, {'i', 1}, {'j', 8}, {'k', 5}, {'l', 1}, {'m', 3}, {'n', 1}, + {'o', 1}, {'p', 3}, {'q', 10}, {'r', 1}, {'s', 1}, {'t', 1}, {'u', 1}, + {'v', 4}, {'w', 4}, {'x', 8}, {'y', 4}, {'z', 10}}; REQUIRE(expected == actual); } #endif diff --git a/exercises/practice/food-chain/.meta/example.cpp b/exercises/practice/food-chain/.meta/example.cpp index 3292aa714..4bffc7f27 100644 --- a/exercises/practice/food-chain/.meta/example.cpp +++ b/exercises/practice/food-chain/.meta/example.cpp @@ -2,92 +2,55 @@ using namespace std; -namespace food_chain -{ +namespace food_chain { -namespace -{ +namespace { -class song_verse -{ -public: +class song_verse { + public: song_verse(string f, string r, string v) - : food_(f), - reaction_(r), - verse_(v) - {} + : food_(f), reaction_(r), verse_(v) {} - string sing() const - { - return "I know an old lady who swallowed a " + food_ + ".\n" - + reaction_ + verse_; + string sing() const { + return "I know an old lady who swallowed a " + food_ + ".\n" + + reaction_ + verse_; } - string verse() const - { - return verse_; - } + string verse() const { return verse_; } -private: + private: string food_; string reaction_; string verse_; }; -song_verse const song_verses[] = -{ - { - "fly", - "", - "I don't know why she swallowed the fly. Perhaps she'll die.\n" - }, - { - "spider", - "It wriggled and jiggled and tickled inside her.\n", - "She swallowed the spider to catch the fly.\n" - }, - { - "bird", - "How absurd to swallow a bird!\n", - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" - }, - { - "cat", - "Imagine that, to swallow a cat!\n", - "She swallowed the cat to catch the bird.\n" - }, - { - "dog", - "What a hog, to swallow a dog!\n", - "She swallowed the dog to catch the cat.\n" - }, - { - "goat", - "Just opened her throat and swallowed a goat!\n", - "She swallowed the goat to catch the dog.\n" - }, - { - "cow", - "I don't know how she swallowed a cow!\n", - "She swallowed the cow to catch the goat.\n" - }, - { - "horse", - "", - "She's dead, of course!\n" - } -}; +song_verse const song_verses[] = { + {"fly", "", + "I don't know why she swallowed the fly. Perhaps she'll die.\n"}, + {"spider", "It wriggled and jiggled and tickled inside her.\n", + "She swallowed the spider to catch the fly.\n"}, + {"bird", "How absurd to swallow a bird!\n", + "She swallowed the bird to catch the spider that wriggled and jiggled and " + "tickled inside her.\n"}, + {"cat", "Imagine that, to swallow a cat!\n", + "She swallowed the cat to catch the bird.\n"}, + {"dog", "What a hog, to swallow a dog!\n", + "She swallowed the dog to catch the cat.\n"}, + {"goat", "Just opened her throat and swallowed a goat!\n", + "She swallowed the goat to catch the dog.\n"}, + {"cow", "I don't know how she swallowed a cow!\n", + "She swallowed the cow to catch the goat.\n"}, + {"horse", "", "She's dead, of course!\n"}}; -const unsigned num_verses = sizeof(song_verses)/sizeof(song_verses[0]); +const unsigned num_verses = sizeof(song_verses) / sizeof(song_verses[0]); -} +} // namespace -string verse(unsigned num) -{ +string verse(unsigned num) { if (num > 0 && num <= num_verses) { --num; string text = song_verses[num].sing(); - if (num < num_verses-1) { + if (num < num_verses - 1) { while (num--) { text += song_verses[num].verse(); } @@ -97,8 +60,7 @@ string verse(unsigned num) return ""; } -string verses(unsigned begin, unsigned end) -{ +string verses(unsigned begin, unsigned end) { string text; for (unsigned v = begin; v <= end; ++v) { text += verse(v) + "\n"; @@ -106,9 +68,6 @@ string verses(unsigned begin, unsigned end) return text; } -string sing() -{ - return verses(1, num_verses); -} +string sing() { return verses(1, num_verses); } -} +} // namespace food_chain diff --git a/exercises/practice/food-chain/.meta/example.h b/exercises/practice/food-chain/.meta/example.h index f56a67c1f..058d5ffcb 100644 --- a/exercises/practice/food-chain/.meta/example.h +++ b/exercises/practice/food-chain/.meta/example.h @@ -3,13 +3,12 @@ #include -namespace food_chain -{ +namespace food_chain { std::string verse(unsigned which); std::string verses(unsigned begin, unsigned end); std::string sing(); -} +} // namespace food_chain #endif diff --git a/exercises/practice/food-chain/food_chain.cpp b/exercises/practice/food-chain/food_chain.cpp index 948fea958..8bdd2e395 100644 --- a/exercises/practice/food-chain/food_chain.cpp +++ b/exercises/practice/food-chain/food_chain.cpp @@ -1,5 +1,3 @@ #include "food_chain.h" -namespace food_chain { - -} // namespace food_chain +namespace food_chain {} // namespace food_chain diff --git a/exercises/practice/food-chain/food_chain.h b/exercises/practice/food-chain/food_chain.h index 1afda200a..2d65d0f2c 100644 --- a/exercises/practice/food-chain/food_chain.h +++ b/exercises/practice/food-chain/food_chain.h @@ -1,8 +1,6 @@ #if !defined(FOOD_CHAIN_H) #define FOOD_CHAIN_H -namespace food_chain { +namespace food_chain {} // namespace food_chain -} // namespace food_chain - -#endif // FOOD_CHAIN_H \ No newline at end of file +#endif // FOOD_CHAIN_H \ No newline at end of file diff --git a/exercises/practice/food-chain/food_chain_test.cpp b/exercises/practice/food-chain/food_chain_test.cpp index e219db211..eb57a1258 100644 --- a/exercises/practice/food-chain/food_chain_test.cpp +++ b/exercises/practice/food-chain/food_chain_test.cpp @@ -7,18 +7,18 @@ using namespace std; -TEST_CASE("fly") -{ - string expected = "I know an old lady who swallowed a fly.\n" +TEST_CASE("fly") { + string expected = + "I know an old lady who swallowed a fly.\n" "I don't know why she swallowed the fly. Perhaps she'll die.\n"; REQUIRE(expected == food_chain::verse(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("spider") -{ - string expected = "I know an old lady who swallowed a spider.\n" +TEST_CASE("spider") { + string expected = + "I know an old lady who swallowed a spider.\n" "It wriggled and jiggled and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. Perhaps she'll die.\n"; @@ -26,23 +26,25 @@ TEST_CASE("spider") REQUIRE(expected == food_chain::verse(2)); } -TEST_CASE("bird") -{ - string expected = "I know an old lady who swallowed a bird.\n" +TEST_CASE("bird") { + string expected = + "I know an old lady who swallowed a bird.\n" "How absurd to swallow a bird!\n" - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled " + "and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. Perhaps she'll die.\n"; REQUIRE(expected == food_chain::verse(3)); } -TEST_CASE("cat") -{ - string expected = "I know an old lady who swallowed a cat.\n" +TEST_CASE("cat") { + string expected = + "I know an old lady who swallowed a cat.\n" "Imagine that, to swallow a cat!\n" "She swallowed the cat to catch the bird.\n" - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled " + "and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. " "Perhaps she'll die.\n"; @@ -50,13 +52,14 @@ TEST_CASE("cat") REQUIRE(expected == food_chain::verse(4)); } -TEST_CASE("dog") -{ - string expected = "I know an old lady who swallowed a dog.\n" +TEST_CASE("dog") { + string expected = + "I know an old lady who swallowed a dog.\n" "What a hog, to swallow a dog!\n" "She swallowed the dog to catch the cat.\n" "She swallowed the cat to catch the bird.\n" - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled " + "and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. " "Perhaps she'll die.\n"; @@ -64,14 +67,15 @@ TEST_CASE("dog") REQUIRE(expected == food_chain::verse(5)); } -TEST_CASE("goat") -{ - string expected = "I know an old lady who swallowed a goat.\n" +TEST_CASE("goat") { + string expected = + "I know an old lady who swallowed a goat.\n" "Just opened her throat and swallowed a goat!\n" "She swallowed the goat to catch the dog.\n" "She swallowed the dog to catch the cat.\n" "She swallowed the cat to catch the bird.\n" - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled " + "and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. " "Perhaps she'll die.\n"; @@ -79,15 +83,16 @@ TEST_CASE("goat") REQUIRE(expected == food_chain::verse(6)); } -TEST_CASE("cow") -{ - string expected = "I know an old lady who swallowed a cow.\n" +TEST_CASE("cow") { + string expected = + "I know an old lady who swallowed a cow.\n" "I don't know how she swallowed a cow!\n" "She swallowed the cow to catch the goat.\n" "She swallowed the goat to catch the dog.\n" "She swallowed the dog to catch the cat.\n" "She swallowed the cat to catch the bird.\n" - "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled " + "and tickled inside her.\n" "She swallowed the spider to catch the fly.\n" "I don't know why she swallowed the fly. " "Perhaps she'll die.\n"; @@ -95,17 +100,16 @@ TEST_CASE("cow") REQUIRE(expected == food_chain::verse(7)); } -TEST_CASE("horse") -{ - string expected = "I know an old lady who swallowed a horse.\n" +TEST_CASE("horse") { + string expected = + "I know an old lady who swallowed a horse.\n" "She's dead, of course!\n"; REQUIRE(expected == food_chain::verse(8)); } -TEST_CASE("multiple_verses") -{ - string expected = +TEST_CASE("multiple_verses") { + string expected = "I know an old lady who swallowed a fly.\n" "I don't know why she swallowed the fly. Perhaps she'll die.\n" "\n" @@ -118,8 +122,7 @@ TEST_CASE("multiple_verses") REQUIRE(expected == food_chain::verses(1, 2)); } -TEST_CASE("the_whole_song") -{ +TEST_CASE("the_whole_song") { REQUIRE(food_chain::verses(1, 8) == food_chain::sing()); } #endif diff --git a/exercises/practice/gigasecond/.meta/example.cpp b/exercises/practice/gigasecond/.meta/example.cpp index be2c499ed..7f1f27698 100644 --- a/exercises/practice/gigasecond/.meta/example.cpp +++ b/exercises/practice/gigasecond/.meta/example.cpp @@ -1,11 +1,9 @@ #include "gigasecond.h" -namespace gigasecond -{ +namespace gigasecond { -boost::posix_time::ptime advance(const boost::posix_time::ptime& start) -{ +boost::posix_time::ptime advance(const boost::posix_time::ptime& start) { return start + boost::posix_time::seconds(1000000000); } -} +} // namespace gigasecond diff --git a/exercises/practice/gigasecond/.meta/example.h b/exercises/practice/gigasecond/.meta/example.h index 71a79dd8b..f7f07ba9a 100644 --- a/exercises/practice/gigasecond/.meta/example.h +++ b/exercises/practice/gigasecond/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace gigasecond -{ +namespace gigasecond { boost::posix_time::ptime advance(const boost::posix_time::ptime& start); diff --git a/exercises/practice/gigasecond/gigasecond.cpp b/exercises/practice/gigasecond/gigasecond.cpp index 91b135242..a6cac582a 100644 --- a/exercises/practice/gigasecond/gigasecond.cpp +++ b/exercises/practice/gigasecond/gigasecond.cpp @@ -1,5 +1,3 @@ #include "gigasecond.h" -namespace gigasecond { - -} // namespace gigasecond +namespace gigasecond {} // namespace gigasecond diff --git a/exercises/practice/gigasecond/gigasecond.h b/exercises/practice/gigasecond/gigasecond.h index 3f3c8abc1..10572d3c9 100644 --- a/exercises/practice/gigasecond/gigasecond.h +++ b/exercises/practice/gigasecond/gigasecond.h @@ -1,8 +1,6 @@ #if !defined(GIGASECOND_H) #define GIGASECOND_H -namespace gigasecond { +namespace gigasecond {} // namespace gigasecond -} // namespace gigasecond - -#endif // GIGASECOND_H \ No newline at end of file +#endif // GIGASECOND_H \ No newline at end of file diff --git a/exercises/practice/grade-school/.meta/example.cpp b/exercises/practice/grade-school/.meta/example.cpp index 72d7f7bb3..7514f189b 100644 --- a/exercises/practice/grade-school/.meta/example.cpp +++ b/exercises/practice/grade-school/.meta/example.cpp @@ -1,22 +1,20 @@ -#include "grade_school.h" #include +#include "grade_school.h" + using namespace std; -namespace grade_school -{ +namespace grade_school { -void school::add(string const& name, int grade) -{ +void school::add(string const& name, int grade) { vector& grade_roster = roster_[grade]; auto it = lower_bound(grade_roster.begin(), grade_roster.end(), name); grade_roster.insert(it, name); } -vector school::grade(int grade) const -{ +vector school::grade(int grade) const { auto it = roster_.find(grade); return (it != roster_.end()) ? it->second : vector{}; } -} +} // namespace grade_school diff --git a/exercises/practice/grade-school/.meta/example.h b/exercises/practice/grade-school/.meta/example.h index 9a6baf692..82377e437 100644 --- a/exercises/practice/grade-school/.meta/example.h +++ b/exercises/practice/grade-school/.meta/example.h @@ -5,12 +5,10 @@ #include #include -namespace grade_school -{ +namespace grade_school { -class school -{ -public: +class school { + public: const std::map>& roster() const { return roster_; } @@ -19,10 +17,10 @@ class school std::vector grade(int grade) const; -private: + private: std::map> roster_; }; -} +} // namespace grade_school #endif diff --git a/exercises/practice/grade-school/grade_school.cpp b/exercises/practice/grade-school/grade_school.cpp index 106540f15..1f88e3c32 100644 --- a/exercises/practice/grade-school/grade_school.cpp +++ b/exercises/practice/grade-school/grade_school.cpp @@ -1,5 +1,3 @@ #include "grade_school.h" -namespace grade_school { - -} // namespace grade_school +namespace grade_school {} // namespace grade_school diff --git a/exercises/practice/grade-school/grade_school.h b/exercises/practice/grade-school/grade_school.h index 73dd9ac8e..80a1a9ef8 100644 --- a/exercises/practice/grade-school/grade_school.h +++ b/exercises/practice/grade-school/grade_school.h @@ -1,8 +1,6 @@ #if !defined(GRADE_SCHOOL_H) #define GRADE_SCHOOL_H -namespace grade_school { +namespace grade_school {} // namespace grade_school -} // namespace grade_school - -#endif // GRADE_SCHOOL_H \ No newline at end of file +#endif // GRADE_SCHOOL_H \ No newline at end of file diff --git a/exercises/practice/grade-school/grade_school_test.cpp b/exercises/practice/grade-school/grade_school_test.cpp index 54d0f46d3..74c5547d3 100644 --- a/exercises/practice/grade-school/grade_school_test.cpp +++ b/exercises/practice/grade-school/grade_school_test.cpp @@ -1,4 +1,5 @@ #include "grade_school.h" + #include #ifdef EXERCISM_TEST_SUITE #include @@ -8,15 +9,13 @@ using namespace std; -TEST_CASE("a_new_school_has_an_empty_roster") -{ +TEST_CASE("a_new_school_has_an_empty_roster") { const grade_school::school school_{}; REQUIRE(school_.roster().empty()); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("adding_a_student_adds_them_to_the_roster_for_the_given_grade") -{ +TEST_CASE("adding_a_student_adds_them_to_the_roster_for_the_given_grade") { grade_school::school school_; school_.add("Aimee", 2); @@ -26,8 +25,7 @@ TEST_CASE("adding_a_student_adds_them_to_the_roster_for_the_given_grade") REQUIRE(expected == actual); } -TEST_CASE("adding_more_students_to_the_same_grade_adds_them_to_the_roster") -{ +TEST_CASE("adding_more_students_to_the_same_grade_adds_them_to_the_roster") { grade_school::school school_; school_.add("Blair", 2); school_.add("James", 2); @@ -39,8 +37,7 @@ TEST_CASE("adding_more_students_to_the_same_grade_adds_them_to_the_roster") REQUIRE(expected == actual); } -TEST_CASE("adding_students_to_different_grades_adds_them_to_the_roster") -{ +TEST_CASE("adding_students_to_different_grades_adds_them_to_the_roster") { grade_school::school school_; school_.add("Chelsea", 3); school_.add("Logan", 7); @@ -51,8 +48,7 @@ TEST_CASE("adding_students_to_different_grades_adds_them_to_the_roster") REQUIRE(expected == actual); } -TEST_CASE("grade_returns_the_students_in_that_grade_in_alphabetical_order") -{ +TEST_CASE("grade_returns_the_students_in_that_grade_in_alphabetical_order") { grade_school::school school_; school_.add("Franklin", 5); school_.add("Bradley", 5); @@ -64,16 +60,15 @@ TEST_CASE("grade_returns_the_students_in_that_grade_in_alphabetical_order") REQUIRE(expected == actual); } -TEST_CASE("grade_returns_an_empty_array_if_there_are_no_students_in_that_grade") -{ +TEST_CASE( + "grade_returns_an_empty_array_if_there_are_no_students_in_that_grade") { const grade_school::school school_{}; const auto actual = school_.grade(1); REQUIRE(actual.empty()); } -TEST_CASE("the_student_names_in_each_grade_in_the_roster_are_sorted") -{ +TEST_CASE("the_student_names_in_each_grade_in_the_roster_are_sorted") { grade_school::school school_; school_.add("Jennifer", 4); school_.add("Kareem", 6); @@ -83,15 +78,11 @@ TEST_CASE("the_student_names_in_each_grade_in_the_roster_are_sorted") const auto actual = school_.roster(); const map> expected{ - {3, {"Kyle"}}, - {4, {"Christopher", "Jennifer"}}, - {6, {"Kareem"}} - }; + {3, {"Kyle"}}, {4, {"Christopher", "Jennifer"}}, {6, {"Kareem"}}}; REQUIRE(expected == actual); } -TEST_CASE("checking_a_grade_should_not_change_the_roster") -{ +TEST_CASE("checking_a_grade_should_not_change_the_roster") { const grade_school::school school_{}; school_.grade(1); REQUIRE(school_.roster().empty()); diff --git a/exercises/practice/grains/.meta/example.cpp b/exercises/practice/grains/.meta/example.cpp index 84c69513b..a4a0c30c9 100644 --- a/exercises/practice/grains/.meta/example.cpp +++ b/exercises/practice/grains/.meta/example.cpp @@ -1,15 +1,10 @@ #include "grains.h" -namespace grains -{ +namespace grains { -unsigned long long square(int which) -{ - return 1ULL << (which-1); -} +unsigned long long square(int which) { return 1ULL << (which - 1); } -unsigned long long total() -{ +unsigned long long total() { unsigned long long result = 0; for (int i = 1; i <= 64; ++i) { result += square(i); @@ -17,4 +12,4 @@ unsigned long long total() return result; } -} +} // namespace grains diff --git a/exercises/practice/grains/.meta/example.h b/exercises/practice/grains/.meta/example.h index 3bb92d8ad..46133528d 100644 --- a/exercises/practice/grains/.meta/example.h +++ b/exercises/practice/grains/.meta/example.h @@ -1,13 +1,12 @@ #if !defined(GRAINS_H) #define GRAINS_H -namespace grains -{ +namespace grains { unsigned long long square(int which); unsigned long long total(); -} +} // namespace grains #endif diff --git a/exercises/practice/grains/grains.cpp b/exercises/practice/grains/grains.cpp index ec7030182..da7a850ea 100644 --- a/exercises/practice/grains/grains.cpp +++ b/exercises/practice/grains/grains.cpp @@ -1,5 +1,3 @@ #include "grains.h" -namespace grains { - -} // namespace grains +namespace grains {} // namespace grains diff --git a/exercises/practice/grains/grains.h b/exercises/practice/grains/grains.h index 1d5167153..bd6458233 100644 --- a/exercises/practice/grains/grains.h +++ b/exercises/practice/grains/grains.h @@ -1,8 +1,6 @@ #if !defined(GRAINS_H) #define GRAINS_H -namespace grains { +namespace grains {} // namespace grains -} // namespace grains - -#endif // GRAINS_H \ No newline at end of file +#endif // GRAINS_H \ No newline at end of file diff --git a/exercises/practice/grains/grains_test.cpp b/exercises/practice/grains/grains_test.cpp index c866987f1..473f4daac 100644 --- a/exercises/practice/grains/grains_test.cpp +++ b/exercises/practice/grains/grains_test.cpp @@ -5,44 +5,22 @@ #include "test/catch.hpp" #endif -TEST_CASE("square_1") -{ - REQUIRE(1ULL == grains::square(1)); -} +TEST_CASE("square_1") { REQUIRE(1ULL == grains::square(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("square_2") -{ - REQUIRE(2ULL == grains::square(2)); -} +TEST_CASE("square_2") { REQUIRE(2ULL == grains::square(2)); } -TEST_CASE("square_3") -{ - REQUIRE(4ULL == grains::square(3)); -} +TEST_CASE("square_3") { REQUIRE(4ULL == grains::square(3)); } -TEST_CASE("square_4") -{ - REQUIRE(8ULL == grains::square(4)); -} +TEST_CASE("square_4") { REQUIRE(8ULL == grains::square(4)); } -TEST_CASE("square_16") -{ - REQUIRE(32768ULL == grains::square(16)); -} +TEST_CASE("square_16") { REQUIRE(32768ULL == grains::square(16)); } -TEST_CASE("square_32") -{ - REQUIRE(2147483648ULL == grains::square(32)); -} +TEST_CASE("square_32") { REQUIRE(2147483648ULL == grains::square(32)); } -TEST_CASE("square_64") -{ +TEST_CASE("square_64") { REQUIRE(9223372036854775808ULL == grains::square(64)); } -TEST_CASE("total") -{ - REQUIRE(18446744073709551615ULL == grains::total()); -} +TEST_CASE("total") { REQUIRE(18446744073709551615ULL == grains::total()); } #endif diff --git a/exercises/practice/hamming/.meta/example.cpp b/exercises/practice/hamming/.meta/example.cpp index 67ed430be..3b6846023 100644 --- a/exercises/practice/hamming/.meta/example.cpp +++ b/exercises/practice/hamming/.meta/example.cpp @@ -1,25 +1,23 @@ -#include "hamming.h" #include #include -namespace hamming -{ +#include "hamming.h" + +namespace hamming { -int compute(std::string const& lhs, std::string const& rhs) -{ - if (rhs.length() != lhs.length()) - { - throw std::domain_error("Hamming distance is not defined for different length strings."); +int compute(std::string const& lhs, std::string const& rhs) { + if (rhs.length() != lhs.length()) { + throw std::domain_error( + "Hamming distance is not defined for different length strings."); } int count = 0; for (auto p = std::mismatch(lhs.begin(), lhs.end(), rhs.begin()); - p.first != lhs.end(); - p = std::mismatch(++p.first, lhs.end(), ++p.second)) - { + p.first != lhs.end(); + p = std::mismatch(++p.first, lhs.end(), ++p.second)) { ++count; } return count; } -} +} // namespace hamming diff --git a/exercises/practice/hamming/.meta/example.h b/exercises/practice/hamming/.meta/example.h index 370026cc2..cecef603b 100644 --- a/exercises/practice/hamming/.meta/example.h +++ b/exercises/practice/hamming/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace hamming -{ +namespace hamming { int compute(std::string const& lhs, std::string const& rhs); diff --git a/exercises/practice/hamming/hamming.cpp b/exercises/practice/hamming/hamming.cpp index 2a0bafedf..881fefc73 100644 --- a/exercises/practice/hamming/hamming.cpp +++ b/exercises/practice/hamming/hamming.cpp @@ -1,5 +1,3 @@ #include "hamming.h" -namespace hamming { - -} // namespace hamming +namespace hamming {} // namespace hamming diff --git a/exercises/practice/hamming/hamming.h b/exercises/practice/hamming/hamming.h index df650b009..87dfbd39c 100644 --- a/exercises/practice/hamming/hamming.h +++ b/exercises/practice/hamming/hamming.h @@ -1,8 +1,6 @@ #if !defined(HAMMING_H) #define HAMMING_H -namespace hamming { +namespace hamming {} // namespace hamming -} // namespace hamming - -#endif // HAMMING_H \ No newline at end of file +#endif // HAMMING_H \ No newline at end of file diff --git a/exercises/practice/hamming/hamming_test.cpp b/exercises/practice/hamming/hamming_test.cpp index 80ed31b21..9667aaec4 100644 --- a/exercises/practice/hamming/hamming_test.cpp +++ b/exercises/practice/hamming/hamming_test.cpp @@ -1,4 +1,5 @@ #include "hamming.h" + #include #ifdef EXERCISM_TEST_SUITE #include @@ -6,49 +7,48 @@ #include "test/catch.hpp" #endif -TEST_CASE("single letter identical strands", "[hamming][54681314-eee2-439a-9db0-b0636c656156]") -{ +TEST_CASE("single letter identical strands", + "[hamming][54681314-eee2-439a-9db0-b0636c656156]") { REQUIRE(0 == hamming::compute("A", "A")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("empty strands", "[hamming][f6dcb64f-03b0-4b60-81b1-3c9dbf47e887]") -{ +TEST_CASE("empty strands", "[hamming][f6dcb64f-03b0-4b60-81b1-3c9dbf47e887]") { REQUIRE(0 == hamming::compute("", "")); } -TEST_CASE("single letter different strands", "[hamming][294479a3-a4c8-478f-8d63-6209815a827b]") -{ +TEST_CASE("single letter different strands", + "[hamming][294479a3-a4c8-478f-8d63-6209815a827b]") { REQUIRE(1 == hamming::compute("G", "T")); } -TEST_CASE("long identical strands", "[hamming][9aed5f34-5693-4344-9b31-40c692fb5592]") -{ +TEST_CASE("long identical strands", + "[hamming][9aed5f34-5693-4344-9b31-40c692fb5592]") { REQUIRE(0 == hamming::compute("GGACTGAAATCTG", "GGACTGAAATCTG")); } -TEST_CASE("long different strands", "[hamming][cd2273a5-c576-46c8-a52b-dee251c3e6e5]") -{ +TEST_CASE("long different strands", + "[hamming][cd2273a5-c576-46c8-a52b-dee251c3e6e5]") { REQUIRE(9 == hamming::compute("GGACGGATTCTG", "AGGACGGATTCT")); } -TEST_CASE("disallow first strand longer", "[hamming][b9228bb1-465f-4141-b40f-1f99812de5a8]") -{ +TEST_CASE("disallow first strand longer", + "[hamming][b9228bb1-465f-4141-b40f-1f99812de5a8]") { REQUIRE_THROWS_AS(hamming::compute("AATG", "AAA"), std::domain_error); } -TEST_CASE("disallow second strand longer", "[hamming][dab38838-26bb-4fff-acbe-3b0a9bfeba2d]") -{ +TEST_CASE("disallow second strand longer", + "[hamming][dab38838-26bb-4fff-acbe-3b0a9bfeba2d]") { REQUIRE_THROWS_AS(hamming::compute("ATA", "AGTG"), std::domain_error); } -TEST_CASE("disallow empty first strand", "[hamming][b764d47c-83ff-4de2-ab10-6cfe4b15c0f3]") -{ +TEST_CASE("disallow empty first strand", + "[hamming][b764d47c-83ff-4de2-ab10-6cfe4b15c0f3]") { REQUIRE_THROWS_AS(hamming::compute("", "G"), std::domain_error); } -TEST_CASE("disallow empty second strand", "[hamming][9ab9262f-3521-4191-81f5-0ed184a5aa89]") -{ +TEST_CASE("disallow empty second strand", + "[hamming][9ab9262f-3521-4191-81f5-0ed184a5aa89]") { REQUIRE_THROWS_AS(hamming::compute("G", ""), std::domain_error); } #endif diff --git a/exercises/practice/hello-world/.meta/example.cpp b/exercises/practice/hello-world/.meta/example.cpp index c4ca3e8ca..3493cbb75 100644 --- a/exercises/practice/hello-world/.meta/example.cpp +++ b/exercises/practice/hello-world/.meta/example.cpp @@ -2,12 +2,8 @@ using namespace std; -namespace hello_world -{ +namespace hello_world { -string hello() -{ - return "Hello, World!"; -} +string hello() { return "Hello, World!"; } -} +} // namespace hello_world diff --git a/exercises/practice/hello-world/hello_world.cpp b/exercises/practice/hello-world/hello_world.cpp index 5d339ce4c..4c8c5c31c 100644 --- a/exercises/practice/hello-world/hello_world.cpp +++ b/exercises/practice/hello-world/hello_world.cpp @@ -2,12 +2,8 @@ using namespace std; -namespace hello_world -{ +namespace hello_world { -string hello() -{ - return "Goodbye, Mars!"; -} +string hello() { return "Goodbye, Mars!"; } -} +} // namespace hello_world diff --git a/exercises/practice/hello-world/hello_world_test.cpp b/exercises/practice/hello-world/hello_world_test.cpp index 54c0ad074..d62f9caec 100644 --- a/exercises/practice/hello-world/hello_world_test.cpp +++ b/exercises/practice/hello-world/hello_world_test.cpp @@ -9,8 +9,7 @@ #endif // Declares a single test. -TEST_CASE("test_hello") -{ +TEST_CASE("test_hello") { // Check if your function returns "Hello, World!". REQUIRE(hello_world::hello() == "Hello, World!"); } diff --git a/exercises/practice/hexadecimal/.meta/example.cpp b/exercises/practice/hexadecimal/.meta/example.cpp index a2e522178..17a4cdd0f 100644 --- a/exercises/practice/hexadecimal/.meta/example.cpp +++ b/exercises/practice/hexadecimal/.meta/example.cpp @@ -1,11 +1,10 @@ -#include "hexadecimal.h" #include -namespace hexadecimal -{ +#include "hexadecimal.h" + +namespace hexadecimal { -int convert(const std::string &text) -{ +int convert(const std::string &text) { int result = 0; for (char c : text) { result *= 16; @@ -23,4 +22,4 @@ int convert(const std::string &text) return result; } -} +} // namespace hexadecimal diff --git a/exercises/practice/hexadecimal/.meta/example.h b/exercises/practice/hexadecimal/.meta/example.h index ff507bb96..ea5151be2 100644 --- a/exercises/practice/hexadecimal/.meta/example.h +++ b/exercises/practice/hexadecimal/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace hexadecimal -{ +namespace hexadecimal { int convert(const std::string &text); diff --git a/exercises/practice/hexadecimal/hexadecimal.cpp b/exercises/practice/hexadecimal/hexadecimal.cpp index eeb87fd45..00edc8af3 100644 --- a/exercises/practice/hexadecimal/hexadecimal.cpp +++ b/exercises/practice/hexadecimal/hexadecimal.cpp @@ -1,5 +1,3 @@ #include "hexadecimal.h" -namespace hexadecimal { - -} // namespace hexadecimal +namespace hexadecimal {} // namespace hexadecimal diff --git a/exercises/practice/hexadecimal/hexadecimal.h b/exercises/practice/hexadecimal/hexadecimal.h index 4b56336f9..8a29b6253 100644 --- a/exercises/practice/hexadecimal/hexadecimal.h +++ b/exercises/practice/hexadecimal/hexadecimal.h @@ -1,8 +1,6 @@ #if !defined(HEXADECIMAL_H) #define HEXADECIMAL_H -namespace hexadecimal { +namespace hexadecimal {} // namespace hexadecimal -} // namespace hexadecimal - -#endif // HEXADECIMAL_H \ No newline at end of file +#endif // HEXADECIMAL_H \ No newline at end of file diff --git a/exercises/practice/hexadecimal/hexadecimal_test.cpp b/exercises/practice/hexadecimal/hexadecimal_test.cpp index cbc7dd038..69fc0045f 100644 --- a/exercises/practice/hexadecimal/hexadecimal_test.cpp +++ b/exercises/practice/hexadecimal/hexadecimal_test.cpp @@ -5,54 +5,34 @@ #include "test/catch.hpp" #endif -TEST_CASE("hex_1_is_decimal_1") -{ - REQUIRE(0x1 == hexadecimal::convert("1")); -} +TEST_CASE("hex_1_is_decimal_1") { REQUIRE(0x1 == hexadecimal::convert("1")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("hex_c_is_decimal_12") -{ - REQUIRE(0xc == hexadecimal::convert("c")); -} +TEST_CASE("hex_c_is_decimal_12") { REQUIRE(0xc == hexadecimal::convert("c")); } -TEST_CASE("hex_10_is_decimal_16") -{ +TEST_CASE("hex_10_is_decimal_16") { REQUIRE(0x10 == hexadecimal::convert("10")); } -TEST_CASE("hex_af_is_decimal_175") -{ +TEST_CASE("hex_af_is_decimal_175") { REQUIRE(0xaf == hexadecimal::convert("af")); } -TEST_CASE("hex_100_is_decimal_256") -{ +TEST_CASE("hex_100_is_decimal_256") { REQUIRE(0x100 == hexadecimal::convert("100")); } -TEST_CASE("hex_19ace_is_decimal_105166") -{ +TEST_CASE("hex_19ace_is_decimal_105166") { REQUIRE(0x19ace == hexadecimal::convert("19ace")); } -TEST_CASE("invalid_hex_is_decimal_0") -{ +TEST_CASE("invalid_hex_is_decimal_0") { REQUIRE(0 == hexadecimal::convert("carrot")); } -TEST_CASE("black") -{ - REQUIRE(0x000000 == hexadecimal::convert("000000")); -} +TEST_CASE("black") { REQUIRE(0x000000 == hexadecimal::convert("000000")); } -TEST_CASE("white") -{ - REQUIRE(0xffffff == hexadecimal::convert("ffffff")); -} +TEST_CASE("white") { REQUIRE(0xffffff == hexadecimal::convert("ffffff")); } -TEST_CASE("yellow") -{ - REQUIRE(0xffff00 == hexadecimal::convert("ffff00")); -} +TEST_CASE("yellow") { REQUIRE(0xffff00 == hexadecimal::convert("ffff00")); } #endif diff --git a/exercises/practice/high-scores/.meta/example.cpp b/exercises/practice/high-scores/.meta/example.cpp index f4bf44222..248321379 100644 --- a/exercises/practice/high-scores/.meta/example.cpp +++ b/exercises/practice/high-scores/.meta/example.cpp @@ -4,13 +4,9 @@ namespace arcade { -std::vector HighScores::list_scores() { - return scores; -} +std::vector HighScores::list_scores() { return scores; } -int HighScores::latest_score() { - return scores.back(); -} +int HighScores::latest_score() { return scores.back(); } int HighScores::personal_best() { return *max_element(scores.begin(), scores.end()); @@ -21,7 +17,8 @@ std::vector HighScores::top_three() { std::sort(sorted_scores.begin(), sorted_scores.end(), std::greater()); size_t limit{3}; if (scores.size() < limit) limit = scores.size(); - return {begin(sorted_scores), begin(sorted_scores) + limit};; + return {begin(sorted_scores), begin(sorted_scores) + limit}; + ; } } // namespace arcade diff --git a/exercises/practice/high-scores/high_scores.cpp b/exercises/practice/high-scores/high_scores.cpp index 32d226d44..6dcb4743f 100644 --- a/exercises/practice/high-scores/high_scores.cpp +++ b/exercises/practice/high-scores/high_scores.cpp @@ -4,24 +4,24 @@ namespace arcade { - std::vector HighScores::list_scores() { - // TODO: Return all scores for this session. - return {0, 1, 2}; - } +std::vector HighScores::list_scores() { + // TODO: Return all scores for this session. + return {0, 1, 2}; +} - int HighScores::latest_score() { - // TODO: Return the latest score for this session. - return 0; - } +int HighScores::latest_score() { + // TODO: Return the latest score for this session. + return 0; +} - int HighScores::personal_best() { - // TODO: Return the highest score for this session. - return 0; - } +int HighScores::personal_best() { + // TODO: Return the highest score for this session. + return 0; +} - std::vector HighScores::top_three() { - // TODO: Return the top 3 scores for this session in descending order. - return {0, 1, 2}; - } +std::vector HighScores::top_three() { + // TODO: Return the top 3 scores for this session in descending order. + return {0, 1, 2}; +} } // namespace arcade diff --git a/exercises/practice/high-scores/high_scores_test.cpp b/exercises/practice/high-scores/high_scores_test.cpp index 576874140..398d54786 100644 --- a/exercises/practice/high-scores/high_scores_test.cpp +++ b/exercises/practice/high-scores/high_scores_test.cpp @@ -66,7 +66,8 @@ TEST_CASE("Personal top when there is only one", "[personalTopThree]") { REQUIRE(hs.top_three() == expected); } -TEST_CASE("Latest score after personal top scores", "[immutable, latestAfterTopThree]") { +TEST_CASE("Latest score after personal top scores", + "[immutable, latestAfterTopThree]") { // Test if latest_score is still valid after calling top_three std::vector scores{70, 50, 20, 30}; int expected{30}; @@ -75,7 +76,8 @@ TEST_CASE("Latest score after personal top scores", "[immutable, latestAfterTopT REQUIRE(hs.latest_score() == expected); } -TEST_CASE("Scores after personal top scores", "[immutable, scoresAfterTopThree]") { +TEST_CASE("Scores after personal top scores", + "[immutable, scoresAfterTopThree]") { // Test if list_scores is unchanged after calling top_three std::vector scores{30, 50, 20, 70}; arcade::HighScores hs{scores}; diff --git a/exercises/practice/isbn-verifier/.meta/example.cpp b/exercises/practice/isbn-verifier/.meta/example.cpp index f5be79868..afe2f570d 100644 --- a/exercises/practice/isbn-verifier/.meta/example.cpp +++ b/exercises/practice/isbn-verifier/.meta/example.cpp @@ -1,23 +1,24 @@ -#include "isbn_verifier.h" #include +#include "isbn_verifier.h" + namespace isbn_verifier { - bool is_valid(const std::string& isbn) { - auto raw_string = std::regex_replace(isbn, std::regex("-"), ""); - - if(!std::regex_match(raw_string, std::regex("\\d{9}[0-9X]"))) { - return false; - } - - int sum{0}; - - for(size_t i = 0; i < 9; ++i) { - sum += (raw_string[i] - '0') * (10-i); - } - - sum += ((raw_string[9] == 'X') ? 10 : raw_string[9] - '0'); - - return sum % 11 == 0; +bool is_valid(const std::string& isbn) { + auto raw_string = std::regex_replace(isbn, std::regex("-"), ""); + + if (!std::regex_match(raw_string, std::regex("\\d{9}[0-9X]"))) { + return false; } + int sum{0}; + + for (size_t i = 0; i < 9; ++i) { + sum += (raw_string[i] - '0') * (10 - i); + } + + sum += ((raw_string[9] == 'X') ? 10 : raw_string[9] - '0'); + + return sum % 11 == 0; +} + } // namespace isbn_verifier diff --git a/exercises/practice/isbn-verifier/.meta/example.h b/exercises/practice/isbn-verifier/.meta/example.h index 7414a0762..c8a961213 100644 --- a/exercises/practice/isbn-verifier/.meta/example.h +++ b/exercises/practice/isbn-verifier/.meta/example.h @@ -4,7 +4,7 @@ #include namespace isbn_verifier { - bool is_valid(const std::string& isbn); -} // namespace isbn_verifier +bool is_valid(const std::string& isbn); +} // namespace isbn_verifier -#endif // ISBN_VERIFIER_H \ No newline at end of file +#endif // ISBN_VERIFIER_H \ No newline at end of file diff --git a/exercises/practice/isbn-verifier/isbn_verifier.cpp b/exercises/practice/isbn-verifier/isbn_verifier.cpp index 6a6643b2b..0ba83b81e 100644 --- a/exercises/practice/isbn-verifier/isbn_verifier.cpp +++ b/exercises/practice/isbn-verifier/isbn_verifier.cpp @@ -1,5 +1,3 @@ #include "isbn_verifier.h" -namespace isbn_verifier { - -} // namespace isbn_verifier \ No newline at end of file +namespace isbn_verifier {} // namespace isbn_verifier \ No newline at end of file diff --git a/exercises/practice/isbn-verifier/isbn_verifier.h b/exercises/practice/isbn-verifier/isbn_verifier.h index 8b6a8bb65..be0028305 100644 --- a/exercises/practice/isbn-verifier/isbn_verifier.h +++ b/exercises/practice/isbn-verifier/isbn_verifier.h @@ -1,8 +1,6 @@ #if !defined(ISBN_VERIFIER_H) #define ISBN_VERIFIER_H -namespace isbn_verifier { - -} // namespace isbn_verifier +namespace isbn_verifier {} // namespace isbn_verifier -#endif // ISBN_VERIFIER_H \ No newline at end of file +#endif // ISBN_VERIFIER_H \ No newline at end of file diff --git a/exercises/practice/isbn-verifier/isbn_verifier_test.cpp b/exercises/practice/isbn-verifier/isbn_verifier_test.cpp index 377ee6a9a..355d15d06 100644 --- a/exercises/practice/isbn-verifier/isbn_verifier_test.cpp +++ b/exercises/practice/isbn-verifier/isbn_verifier_test.cpp @@ -5,101 +5,75 @@ #include "test/catch.hpp" #endif - -TEST_CASE("valid_isbn") -{ - REQUIRE(isbn_verifier::is_valid("3-598-21508-8")); -} +TEST_CASE("valid_isbn") { REQUIRE(isbn_verifier::is_valid("3-598-21508-8")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("invalid_isbn_check_digit") -{ +TEST_CASE("invalid_isbn_check_digit") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-21508-9")); } -TEST_CASE("valid_isbn_with_a_check_digit_of_10") -{ +TEST_CASE("valid_isbn_with_a_check_digit_of_10") { REQUIRE(isbn_verifier::is_valid("3-598-21507-X")); } -TEST_CASE("check_digit_is_a_character_other_than_x") -{ +TEST_CASE("check_digit_is_a_character_other_than_x") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-21507-A")); } -TEST_CASE("invalid_check_digit_in_isbn_is_not_treated_as_zero") -{ +TEST_CASE("invalid_check_digit_in_isbn_is_not_treated_as_zero") { REQUIRE_FALSE(isbn_verifier::is_valid("4-598-21507-B")); } -TEST_CASE("invalid_character_in_isbn_is_not_treated_as_zero") -{ +TEST_CASE("invalid_character_in_isbn_is_not_treated_as_zero") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-P1581-X")); } -TEST_CASE("x_is_only_valid_as_a_check_digit") -{ +TEST_CASE("x_is_only_valid_as_a_check_digit") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-2X507-9")); } -TEST_CASE("valid_isbn_without_separating_dashes") -{ +TEST_CASE("valid_isbn_without_separating_dashes") { REQUIRE(isbn_verifier::is_valid("3598215088")); } -TEST_CASE("isbn_without_separating_dashes_and_x_as_check_digit") -{ +TEST_CASE("isbn_without_separating_dashes_and_x_as_check_digit") { REQUIRE(isbn_verifier::is_valid("359821507X")); } -TEST_CASE("isbn_without_check_digit_and_dashes") -{ +TEST_CASE("isbn_without_check_digit_and_dashes") { REQUIRE_FALSE(isbn_verifier::is_valid("359821507")); } -TEST_CASE("too_long_isbn_and_no_dashes") -{ +TEST_CASE("too_long_isbn_and_no_dashes") { REQUIRE_FALSE(isbn_verifier::is_valid("3598215078X")); } -TEST_CASE("too_short_isbn") -{ - REQUIRE_FALSE(isbn_verifier::is_valid("00")); -} +TEST_CASE("too_short_isbn") { REQUIRE_FALSE(isbn_verifier::is_valid("00")); } -TEST_CASE("isbn_without_check_digit") -{ +TEST_CASE("isbn_without_check_digit") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-21507")); } -TEST_CASE("check_digit_of_x_should_not_be_used_for_0") -{ +TEST_CASE("check_digit_of_x_should_not_be_used_for_0") { REQUIRE_FALSE(isbn_verifier::is_valid("3-598-21515-X")); } -TEST_CASE("empty_isbn") -{ - REQUIRE_FALSE(isbn_verifier::is_valid("")); -} +TEST_CASE("empty_isbn") { REQUIRE_FALSE(isbn_verifier::is_valid("")); } -TEST_CASE("input_is_9_characters") -{ +TEST_CASE("input_is_9_characters") { REQUIRE_FALSE(isbn_verifier::is_valid("134456729")); } -TEST_CASE("invalid_characters_are_not_ignored_after_checking_length") -{ +TEST_CASE("invalid_characters_are_not_ignored_after_checking_length") { REQUIRE_FALSE(isbn_verifier::is_valid("3132P34035")); } -TEST_CASE("invalid_characters_are_not_ignored_before_checking_length") -{ +TEST_CASE("invalid_characters_are_not_ignored_before_checking_length") { REQUIRE_FALSE(isbn_verifier::is_valid("3598P215088")); } -TEST_CASE("input_is_too_long_but_contains_a_valid_isbn") -{ +TEST_CASE("input_is_too_long_but_contains_a_valid_isbn") { REQUIRE_FALSE(isbn_verifier::is_valid("98245726788")); } #endif diff --git a/exercises/practice/isogram/.meta/example.cpp b/exercises/practice/isogram/.meta/example.cpp index 0c0e0a9b2..caf35eb91 100644 --- a/exercises/practice/isogram/.meta/example.cpp +++ b/exercises/practice/isogram/.meta/example.cpp @@ -1,25 +1,22 @@ #include + #include "isogram.h" namespace isogram { - -bool is_isogram(std::string const& input_str) -{ + +bool is_isogram(std::string const& input_str) { std::unordered_set chars; - - for (char const ch : input_str) - { - if (isalnum(ch)) - { + + for (char const ch : input_str) { + if (isalnum(ch)) { auto ret = chars.insert(tolower(ch)); - if (ret.second == false) - { + if (ret.second == false) { return false; } } } - + return true; } - -} // namespace isogram + +} // namespace isogram diff --git a/exercises/practice/isogram/.meta/example.h b/exercises/practice/isogram/.meta/example.h index 3ca8da038..fe8227850 100644 --- a/exercises/practice/isogram/.meta/example.h +++ b/exercises/practice/isogram/.meta/example.h @@ -6,6 +6,6 @@ namespace isogram { bool is_isogram(std::string const&); - + } -#endif // ISOGRAM_H +#endif // ISOGRAM_H diff --git a/exercises/practice/isogram/isogram.cpp b/exercises/practice/isogram/isogram.cpp index 651b115dc..1aeb11f7a 100644 --- a/exercises/practice/isogram/isogram.cpp +++ b/exercises/practice/isogram/isogram.cpp @@ -1,5 +1,3 @@ #include "isogram.h" -namespace isogram { - -} // namespace isogram +namespace isogram {} // namespace isogram diff --git a/exercises/practice/isogram/isogram.h b/exercises/practice/isogram/isogram.h index 3ed25e2d7..d28d360bd 100644 --- a/exercises/practice/isogram/isogram.h +++ b/exercises/practice/isogram/isogram.h @@ -1,8 +1,6 @@ #if !defined(ISOGRAM_H) #define ISOGRAM_H -namespace isogram { +namespace isogram {} // namespace isogram -} // namespace isogram - -#endif // ISOGRAM_H \ No newline at end of file +#endif // ISOGRAM_H \ No newline at end of file diff --git a/exercises/practice/isogram/isogram_test.cpp b/exercises/practice/isogram/isogram_test.cpp index eeea4c83a..6a7e31141 100644 --- a/exercises/practice/isogram/isogram_test.cpp +++ b/exercises/practice/isogram/isogram_test.cpp @@ -9,129 +9,115 @@ using namespace std; // Isogram exercise test case data version 1.7.0 -TEST_CASE("empty_string") -{ +TEST_CASE("empty_string") { const bool actual = isogram::is_isogram(""); - const bool expected {true}; + const bool expected{true}; REQUIRE(expected == actual); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("isogram_with_only_lower_case_characters") -{ +TEST_CASE("isogram_with_only_lower_case_characters") { const bool actual = isogram::is_isogram("isogram"); - - const bool expected {true}; + + const bool expected{true}; REQUIRE(expected == actual); } -TEST_CASE("word_with_one_duplicated_character") -{ +TEST_CASE("word_with_one_duplicated_character") { const bool actual = isogram::is_isogram("eleven"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("word_with_one_duplicated_character_from_the_end_of_the_alphabet") -{ +TEST_CASE("word_with_one_duplicated_character_from_the_end_of_the_alphabet") { const bool actual = isogram::is_isogram("zzyzx"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("longest_reported_english_isogram") -{ +TEST_CASE("longest_reported_english_isogram") { const bool actual = isogram::is_isogram("subdermatoglyphic"); - const bool expected {true}; + const bool expected{true}; REQUIRE(expected == actual); } -TEST_CASE("word_with_duplicated_character_in_mixed_case") -{ +TEST_CASE("word_with_duplicated_character_in_mixed_case") { const bool actual = isogram::is_isogram("Alphabet"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("word_with_duplicated_character_in_mixed_case_lowercase_first") -{ +TEST_CASE("word_with_duplicated_character_in_mixed_case_lowercase_first") { const bool actual = isogram::is_isogram("alphAbet"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("hypothetical_isogrammic_word_with_hyphen") -{ +TEST_CASE("hypothetical_isogrammic_word_with_hyphen") { const bool actual = isogram::is_isogram("thumbscrew-japingly"); - const bool expected {true}; + const bool expected{true}; REQUIRE(expected == actual); } -TEST_CASE("hypothetical_word_with_duplicated_character_following_hyphen") -{ +TEST_CASE("hypothetical_word_with_duplicated_character_following_hyphen") { const bool actual = isogram::is_isogram("thumbscrew-jappingly"); - - const bool expected {false}; + + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("isogram_with_duplicated_hyphen") -{ +TEST_CASE("isogram_with_duplicated_hyphen") { const bool actual = isogram::is_isogram("six-year-old"); - const bool expected {true}; + const bool expected{true}; REQUIRE(expected == actual); } -TEST_CASE("made_up_name_that_is_an_isogram") -{ +TEST_CASE("made_up_name_that_is_an_isogram") { const bool actual = isogram::is_isogram("Emily Jung Schwartzkopf"); - const bool expected {true}; + const bool expected{true}; REQUIRE(expected == actual); } -TEST_CASE("duplicated_character_in_the_middle") -{ +TEST_CASE("duplicated_character_in_the_middle") { const bool actual = isogram::is_isogram("accentor"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("same_first_and_last_characters") -{ +TEST_CASE("same_first_and_last_characters") { const bool actual = isogram::is_isogram("angola"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } -TEST_CASE("word_with_duplicated_character_and_with_two_hyphens") -{ +TEST_CASE("word_with_duplicated_character_and_with_two_hyphens") { const bool actual = isogram::is_isogram("up-to-date"); - const bool expected {false}; + const bool expected{false}; REQUIRE(expected == actual); } diff --git a/exercises/practice/kindergarten-garden/.meta/example.cpp b/exercises/practice/kindergarten-garden/.meta/example.cpp index caf61e625..89c1d1a5f 100644 --- a/exercises/practice/kindergarten-garden/.meta/example.cpp +++ b/exercises/practice/kindergarten-garden/.meta/example.cpp @@ -1,7 +1,7 @@ -#include "kindergarten_garden.h" - #include +#include "kindergarten_garden.h" + namespace kindergarten_garden { std::array plants(std::string_view diagram, diff --git a/exercises/practice/kindergarten-garden/.meta/example.h b/exercises/practice/kindergarten-garden/.meta/example.h index a4d7cace7..1496b5445 100644 --- a/exercises/practice/kindergarten-garden/.meta/example.h +++ b/exercises/practice/kindergarten-garden/.meta/example.h @@ -5,7 +5,12 @@ namespace kindergarten_garden { -enum class Plants : char { grass = 'G', clover = 'C', radishes = 'R', violets = 'V' }; +enum class Plants : char { + grass = 'G', + clover = 'C', + radishes = 'R', + violets = 'V' +}; std::array plants(std::string_view diagram, std::string_view student); diff --git a/exercises/practice/kindergarten-garden/kindergarten_garden.cpp b/exercises/practice/kindergarten-garden/kindergarten_garden.cpp index 251fb2bff..7fb836362 100644 --- a/exercises/practice/kindergarten-garden/kindergarten_garden.cpp +++ b/exercises/practice/kindergarten-garden/kindergarten_garden.cpp @@ -1,5 +1,3 @@ #include "kindergarten_garden.h" -namespace kindergarten_garden { - -} // namespace kindergarten_garden +namespace kindergarten_garden {} // namespace kindergarten_garden diff --git a/exercises/practice/kindergarten-garden/kindergarten_garden.h b/exercises/practice/kindergarten-garden/kindergarten_garden.h index c37503f34..f24151ceb 100644 --- a/exercises/practice/kindergarten-garden/kindergarten_garden.h +++ b/exercises/practice/kindergarten-garden/kindergarten_garden.h @@ -1,5 +1,3 @@ #pragma once -namespace kindergarten_garden { - -} // namespace kindergarten_garden +namespace kindergarten_garden {} // namespace kindergarten_garden diff --git a/exercises/practice/kindergarten-garden/kindergarten_garden_test.cpp b/exercises/practice/kindergarten-garden/kindergarten_garden_test.cpp index 60afc959c..ccc3bc8c2 100644 --- a/exercises/practice/kindergarten-garden/kindergarten_garden_test.cpp +++ b/exercises/practice/kindergarten-garden/kindergarten_garden_test.cpp @@ -7,96 +7,186 @@ // improves error messages with triangle flavor enum text instead of integers: CATCH_REGISTER_ENUM(kindergarten_garden::Plants, - kindergarten_garden::Plants::clover, - kindergarten_garden::Plants::grass, - kindergarten_garden::Plants::violets, - kindergarten_garden::Plants::radishes) + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::radishes) -TEST_CASE("garden with single student", "[1fc316ed-17ab-4fba-88ef-3ae78296b692]") { - std::array expected{kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("RC\nGG", "Alice") == expected); +TEST_CASE("garden with single student", + "[1fc316ed-17ab-4fba-88ef-3ae78296b692]") { + std::array expected{ + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants("RC\nGG", "Alice") == expected); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("different garden with single student", "[acd19dc1-2200-4317-bc2a-08f021276b40]") { - std::array expected{kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VC\nRC", "Alice") == expected); +TEST_CASE("different garden with single student", + "[acd19dc1-2200-4317-bc2a-08f021276b40]") { + std::array expected{ + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants("VC\nRC", "Alice") == expected); } -TEST_CASE("garden with two students", "[c376fcc8-349c-446c-94b0-903947315757]") { - std::array expected{kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VVCG\nVVRC", "Bob") == expected); +TEST_CASE("garden with two students", + "[c376fcc8-349c-446c-94b0-903947315757]") { + std::array expected{ + kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants("VVCG\nVVRC", "Bob") == expected); } TEST_CASE("second student's garden", "[2d620f45-9617-4924-9d27-751c80d17db9]") { - std::array expected{kindergarten_garden::Plants::clover, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::clover}; + std::array expected{ + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::clover}; REQUIRE(kindergarten_garden::plants("VVCCGG\nVVCCGG", "Bob") == expected); } TEST_CASE("third student's garden", "[57712331-4896-4364-89f8-576421d69c44]") { - std::array expected{kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("VVCCGG\nVVCCGG", "Charlie") == expected); + std::array expected{ + kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants("VVCCGG\nVVCCGG", "Charlie") == + expected); } -TEST_CASE("for Alice, first student's garden", "[149b4290-58e1-40f2-8ae4-8b87c46e765b]") { - std::array expected{kindergarten_garden::Plants::violets, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::radishes}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Alice") == expected); +TEST_CASE("for Alice, first student's garden", + "[149b4290-58e1-40f2-8ae4-8b87c46e765b]") { + std::array expected{ + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::radishes}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Alice") == expected); } -TEST_CASE("for Bob, second student's garden", "[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e]") { - std::array expected{kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Bob") == expected); +TEST_CASE("for Bob, second student's garden", + "[ba25dbbc-10bd-4a37-b18e-f89ecd098a5e]") { + std::array expected{ + kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Bob") == + expected); } TEST_CASE("for Charlie", "[566b621b-f18e-4c5f-873e-be30544b838c]") { - std::array expected{kindergarten_garden::Plants::violets, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Charlie") == expected); + std::array expected{ + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Charlie") == expected); } TEST_CASE("for David", "[3ad3df57-dd98-46fc-9269-1877abf612aa]") { - std::array expected{kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::radishes}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "David") == expected); + std::array expected{ + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::radishes}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "David") == expected); } TEST_CASE("for Eve", "[0f0a55d1-9710-46ed-a0eb-399ba8c72db2]") { - std::array expected{kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Eve") == expected); + std::array expected{ + kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Eve") == + expected); } TEST_CASE("for Fred", "[a7e80c90-b140-4ea1-aee3-f4625365c9a4]") { - std::array expected{kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Fred") == expected); + std::array expected{ + kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Fred") == + expected); } TEST_CASE("for Ginny", "[9d94b273-2933-471b-86e8-dba68694c615]") { - std::array expected{kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Ginny") == expected); + std::array expected{ + kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Ginny") == expected); } TEST_CASE("for Harriet", "[f55bc6c2-ade8-4844-87c4-87196f1b7258]") { - std::array expected{kindergarten_garden::Plants::violets, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::radishes, kindergarten_garden::Plants::violets}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Harriet") == expected); + std::array expected{ + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::radishes, + kindergarten_garden::Plants::violets}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Harriet") == expected); } TEST_CASE("for Ileana", "[759070a3-1bb1-4dd4-be2c-7cce1d7679ae]") { - std::array expected{kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Ileana") == expected); + std::array expected{ + kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Ileana") == expected); } TEST_CASE("for Joseph", "[78578123-2755-4d4a-9c7d-e985b8dda1c6]") { - std::array expected{kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Joseph") == expected); + std::array expected{ + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Joseph") == expected); } -TEST_CASE("for Kincaid, second to last student's garden", "[6bb66df7-f433-41ab-aec2-3ead6e99f65b]") { - std::array expected{kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::grass}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Kincaid") == expected); +TEST_CASE("for Kincaid, second to last student's garden", + "[6bb66df7-f433-41ab-aec2-3ead6e99f65b]") { + std::array expected{ + kindergarten_garden::Plants::grass, kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::grass}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Kincaid") == expected); } -TEST_CASE("for Larry, last student's garden", "[d7edec11-6488-418a-94e6-ed509e0fa7eb]") { - std::array expected{kindergarten_garden::Plants::grass, kindergarten_garden::Plants::violets, kindergarten_garden::Plants::clover, kindergarten_garden::Plants::violets}; - REQUIRE(kindergarten_garden::plants("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", "Larry") == expected); +TEST_CASE("for Larry, last student's garden", + "[d7edec11-6488-418a-94e6-ed509e0fa7eb]") { + std::array expected{ + kindergarten_garden::Plants::grass, + kindergarten_garden::Plants::violets, + kindergarten_garden::Plants::clover, + kindergarten_garden::Plants::violets}; + REQUIRE(kindergarten_garden::plants( + "VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV", + "Larry") == expected); } #endif diff --git a/exercises/practice/knapsack/.meta/example.cpp b/exercises/practice/knapsack/.meta/example.cpp index 4a1fe734f..f4cd53f97 100644 --- a/exercises/practice/knapsack/.meta/example.cpp +++ b/exercises/practice/knapsack/.meta/example.cpp @@ -1,17 +1,14 @@ #include "knapsack.h" -namespace knapsack -{ +namespace knapsack { -int maximum_value(int maximum_weight, const std::vector& items) -{ +int maximum_value(int maximum_weight, const std::vector& items) { std::vector dp(maximum_weight + 1); - for (auto item: items) + for (auto item : items) for (int weight = maximum_weight; weight >= item.weight; --weight) - dp[weight] = std::max( - dp[weight], - dp[weight - item.weight] + item.value); + dp[weight] = + std::max(dp[weight], dp[weight - item.weight] + item.value); return dp[maximum_weight]; } -} // namespace knapsack +} // namespace knapsack diff --git a/exercises/practice/knapsack/.meta/example.h b/exercises/practice/knapsack/.meta/example.h index f0b49a62e..20a5f99c7 100644 --- a/exercises/practice/knapsack/.meta/example.h +++ b/exercises/practice/knapsack/.meta/example.h @@ -3,17 +3,15 @@ #include -namespace knapsack -{ +namespace knapsack { -struct Item -{ +struct Item { int weight; int value; }; int maximum_value(int maximum_weight, const std::vector& items); -} // namespace knapsack +} // namespace knapsack -#endif // KNAPSACK_H +#endif // KNAPSACK_H diff --git a/exercises/practice/knapsack/knapsack.cpp b/exercises/practice/knapsack/knapsack.cpp index 6e213bb57..99275956d 100644 --- a/exercises/practice/knapsack/knapsack.cpp +++ b/exercises/practice/knapsack/knapsack.cpp @@ -1,7 +1,3 @@ #include "knapsack.h" -namespace knapsack -{ - -} // namespace knapsack - +namespace knapsack {} // namespace knapsack diff --git a/exercises/practice/knapsack/knapsack.h b/exercises/practice/knapsack/knapsack.h index 19f4f0d38..c731efa9a 100644 --- a/exercises/practice/knapsack/knapsack.h +++ b/exercises/practice/knapsack/knapsack.h @@ -1,15 +1,13 @@ #ifndef KNAPSACK_H #define KNAPSACK_H -namespace knapsack -{ +namespace knapsack { -struct Item -{ +struct Item { int weight; int value; }; -} // namespace knapsack +} // namespace knapsack -#endif // KNAPSACK_H +#endif // KNAPSACK_H diff --git a/exercises/practice/knapsack/knapsack_test.cpp b/exercises/practice/knapsack/knapsack_test.cpp index 712e1f16e..158777f11 100644 --- a/exercises/practice/knapsack/knapsack_test.cpp +++ b/exercises/practice/knapsack/knapsack_test.cpp @@ -1,4 +1,5 @@ #include "knapsack.h" + #include #ifdef EXERCISM_TEST_SUITE #include @@ -6,8 +7,7 @@ #include "test/catch.hpp" #endif -TEST_CASE("no items", "[maximumValue][3993a824-c20e-493d-b3c9-ee8a7753ee59]") -{ +TEST_CASE("no items", "[maximumValue][3993a824-c20e-493d-b3c9-ee8a7753ee59]") { int max_weight = 100; const std::vector items{}; REQUIRE(knapsack::maximum_value(max_weight, items) == 0); @@ -15,53 +15,50 @@ TEST_CASE("no items", "[maximumValue][3993a824-c20e-493d-b3c9-ee8a7753ee59]") #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("one item, too heavy", "[maximumValue][1d39e98c-6249-4a8b-912f-87cb12e506b0]") -{ +TEST_CASE("one item, too heavy", + "[maximumValue][1d39e98c-6249-4a8b-912f-87cb12e506b0]") { int max_weight = 10; const std::vector items{{100, 1}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 0); } -TEST_CASE("five items (cannot be greedy by weight)", "[maximumValue][833ea310-6323-44f2-9d27-a278740ffbd8]") -{ +TEST_CASE("five items (cannot be greedy by weight)", + "[maximumValue][833ea310-6323-44f2-9d27-a278740ffbd8]") { int max_weight = 10; const std::vector items{ - {2, 5}, {2, 5}, {2, 5}, {2, 5}, {10, 21}}; + {2, 5}, {2, 5}, {2, 5}, {2, 5}, {10, 21}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 21); } -TEST_CASE("five items (cannot be greedy by value)", "[maximumValue][277cdc52-f835-4c7d-872b-bff17bab2456]") -{ +TEST_CASE("five items (cannot be greedy by value)", + "[maximumValue][277cdc52-f835-4c7d-872b-bff17bab2456]") { int max_weight = 10; const std::vector items{ - {2, 20}, {2, 20}, {2, 20}, {2, 20}, {10, 50}}; + {2, 20}, {2, 20}, {2, 20}, {2, 20}, {10, 50}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 80); } -TEST_CASE("example knapsack", "[maximumValue][81d8e679-442b-4f7a-8a59-7278083916c9]") -{ +TEST_CASE("example knapsack", + "[maximumValue][81d8e679-442b-4f7a-8a59-7278083916c9]") { int max_weight = 10; - const std::vector items{ - {5, 10}, {4, 40}, {6, 30}, {4, 50}}; + const std::vector items{{5, 10}, {4, 40}, {6, 30}, {4, 50}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 90); } -TEST_CASE("8 items", "[maximumValue][f23a2449-d67c-4c26-bf3e-cde020f27ecc]") -{ +TEST_CASE("8 items", "[maximumValue][f23a2449-d67c-4c26-bf3e-cde020f27ecc]") { int max_weight = 104; - const std::vector items{ - {25, 350}, {35, 400}, {45, 450}, {5, 20}, {25, 70}, - {3, 8}, {2, 5}, {2, 5}}; + const std::vector items{{25, 350}, {35, 400}, {45, 450}, + {5, 20}, {25, 70}, {3, 8}, + {2, 5}, {2, 5}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 900); } -TEST_CASE("15 items", "[maximumValue][7c682ae9-c385-4241-a197-d2fa02c81a11]") -{ +TEST_CASE("15 items", "[maximumValue][7c682ae9-c385-4241-a197-d2fa02c81a11]") { int max_weight = 750; const std::vector items{ - {70, 135}, {73, 139}, {77, 149}, {80, 150}, {82, 156}, - {87, 163}, {90, 173}, {94, 184}, {98, 192}, {106, 201}, - {110, 210}, {113, 214}, {115, 221}, {118, 229}, {120, 240}}; + {70, 135}, {73, 139}, {77, 149}, {80, 150}, {82, 156}, + {87, 163}, {90, 173}, {94, 184}, {98, 192}, {106, 201}, + {110, 210}, {113, 214}, {115, 221}, {118, 229}, {120, 240}}; REQUIRE(knapsack::maximum_value(max_weight, items) == 1458); } diff --git a/exercises/practice/largest-series-product/.meta/example.cpp b/exercises/practice/largest-series-product/.meta/example.cpp index 6f208602d..4d20d61e9 100644 --- a/exercises/practice/largest-series-product/.meta/example.cpp +++ b/exercises/practice/largest-series-product/.meta/example.cpp @@ -1,36 +1,39 @@ -#include "largest_series_product.h" -#include #include -#include +#include #include +#include + +#include "largest_series_product.h" namespace largest_series_product { - int largest_product(const std::string& digits, int span) { - if (span == 0) { - return 1; - } +int largest_product(const std::string& digits, int span) { + if (span == 0) { + return 1; + } - if(span < 0) { - throw std::domain_error("span must not be negative"); - } + if (span < 0) { + throw std::domain_error("span must not be negative"); + } - if (digits.size() < static_cast(span)) { - throw std::domain_error("span must be smaller than string length"); - } + if (digits.size() < static_cast(span)) { + throw std::domain_error("span must be smaller than string length"); + } - if (!std::regex_match(digits, std::regex("\\d*"))) { - throw std::domain_error("digits input must only contain digits"); - } + if (!std::regex_match(digits, std::regex("\\d*"))) { + throw std::domain_error("digits input must only contain digits"); + } - int max = 0; - for(size_t i = 0; i < digits.size() - span + 1; ++i) { - auto start_iter = digits.begin() + i; - auto end_iter = digits.begin() + i + span; - auto val = std::accumulate(std::next(start_iter), end_iter, (*start_iter) - '0', [](int value, char current_val){ - return value *= (current_val - '0'); - }); - max = std::max(max, val); - } - return max; + int max = 0; + for (size_t i = 0; i < digits.size() - span + 1; ++i) { + auto start_iter = digits.begin() + i; + auto end_iter = digits.begin() + i + span; + auto val = std::accumulate(std::next(start_iter), end_iter, + (*start_iter) - '0', + [](int value, char current_val) { + return value *= (current_val - '0'); + }); + max = std::max(max, val); } -} // namespace largest_series_product + return max; +} +} // namespace largest_series_product diff --git a/exercises/practice/largest-series-product/.meta/example.h b/exercises/practice/largest-series-product/.meta/example.h index 0c6b61b4b..932d7ac40 100644 --- a/exercises/practice/largest-series-product/.meta/example.h +++ b/exercises/practice/largest-series-product/.meta/example.h @@ -5,8 +5,8 @@ namespace largest_series_product { - int largest_product(const std::string& digits, int span); +int largest_product(const std::string& digits, int span); -} // namespace largest_series_product +} // namespace largest_series_product -#endif // LARGEST_SERIES_PRODUCT_H +#endif // LARGEST_SERIES_PRODUCT_H diff --git a/exercises/practice/largest-series-product/largest_series_product.cpp b/exercises/practice/largest-series-product/largest_series_product.cpp index 8d6113845..e2a2c4f6a 100644 --- a/exercises/practice/largest-series-product/largest_series_product.cpp +++ b/exercises/practice/largest-series-product/largest_series_product.cpp @@ -1,5 +1,3 @@ #include "largest_series_product.h" -namespace largest_series_product { - -} // largest_series_product \ No newline at end of file +namespace largest_series_product {} // namespace largest_series_product \ No newline at end of file diff --git a/exercises/practice/largest-series-product/largest_series_product.h b/exercises/practice/largest-series-product/largest_series_product.h index 2001a49de..3e2f260e5 100644 --- a/exercises/practice/largest-series-product/largest_series_product.h +++ b/exercises/practice/largest-series-product/largest_series_product.h @@ -1,8 +1,6 @@ #if !defined(LARGEST_SERIES_PRODUCT_H) #define LARGEST_SERIES_PRODUCT_H -namespace largest_series_product { +namespace largest_series_product {} // namespace largest_series_product -} // largest_series_product - -#endif // LARGEST_SERIES_PRODUCT_H \ No newline at end of file +#endif // LARGEST_SERIES_PRODUCT_H \ No newline at end of file diff --git a/exercises/practice/largest-series-product/largest_series_product_test.cpp b/exercises/practice/largest-series-product/largest_series_product_test.cpp index 3a9a5e4c6..925148b1a 100644 --- a/exercises/practice/largest-series-product/largest_series_product_test.cpp +++ b/exercises/practice/largest-series-product/largest_series_product_test.cpp @@ -5,71 +5,63 @@ #include "test/catch.hpp" #endif - -TEST_CASE("finds_the_largest_product_if_span_equals_length") -{ +TEST_CASE("finds_the_largest_product_if_span_equals_length") { REQUIRE(largest_series_product::largest_product("29", 2) == 18); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("can_find_the_largest_product_of_2_with_numbers_in_order") -{ +TEST_CASE("can_find_the_largest_product_of_2_with_numbers_in_order") { REQUIRE(largest_series_product::largest_product("0123456789", 2) == 72); } -TEST_CASE("can_find_the_largest_product_of_2") -{ +TEST_CASE("can_find_the_largest_product_of_2") { REQUIRE(largest_series_product::largest_product("576802143", 2) == 48); } -TEST_CASE("can_find_the_largest_product_of_3_with_numbers_in_order") -{ +TEST_CASE("can_find_the_largest_product_of_3_with_numbers_in_order") { REQUIRE(largest_series_product::largest_product("0123456789", 3) == 504); } -TEST_CASE("can_find_the_largest_product_of_3") -{ +TEST_CASE("can_find_the_largest_product_of_3") { REQUIRE(largest_series_product::largest_product("1027839564", 3) == 270); } -TEST_CASE("can_find_the_largest_product_of_5_with_numbers_in_order") -{ +TEST_CASE("can_find_the_largest_product_of_5_with_numbers_in_order") { REQUIRE(largest_series_product::largest_product("0123456789", 5) == 15120); } -TEST_CASE("can_get_the_largest_product_of_a_big_number") -{ - REQUIRE(largest_series_product::largest_product("73167176531330624919225119674426574742355349194934", 6) == 23520); +TEST_CASE("can_get_the_largest_product_of_a_big_number") { + REQUIRE(largest_series_product::largest_product( + "73167176531330624919225119674426574742355349194934", 6) == + 23520); } -TEST_CASE("reports_zero_if_the_only_digits_are_zero") -{ +TEST_CASE("reports_zero_if_the_only_digits_are_zero") { REQUIRE(largest_series_product::largest_product("0000", 2) == 0); } -TEST_CASE("reports_zero_if_all_spans_include_zero") -{ +TEST_CASE("reports_zero_if_all_spans_include_zero") { REQUIRE(largest_series_product::largest_product("99099", 3) == 0); } -TEST_CASE("rejects_span_longer_than_string_length") -{ - REQUIRE_THROWS_AS(largest_series_product::largest_product("123", 4), std::domain_error); +TEST_CASE("rejects_span_longer_than_string_length") { + REQUIRE_THROWS_AS(largest_series_product::largest_product("123", 4), + std::domain_error); } -TEST_CASE("rejects_empty_string_and_nonzero_span") -{ - REQUIRE_THROWS_AS(largest_series_product::largest_product("", 1), std::domain_error); +TEST_CASE("rejects_empty_string_and_nonzero_span") { + REQUIRE_THROWS_AS(largest_series_product::largest_product("", 1), + std::domain_error); } -TEST_CASE("rejects_invalid_character_in_digits") -{ - REQUIRE_THROWS_AS(largest_series_product::largest_product("1234a5", 2), std::domain_error); +TEST_CASE("rejects_invalid_character_in_digits") { + REQUIRE_THROWS_AS(largest_series_product::largest_product("1234a5", 2), + std::domain_error); } -TEST_CASE("rejects_negative_span") -{ - REQUIRE_THROWS_AS(largest_series_product::largest_product("12345", -1), std::domain_error); +TEST_CASE("rejects_negative_span") { + REQUIRE_THROWS_AS(largest_series_product::largest_product("12345", -1), + std::domain_error); } #endif diff --git a/exercises/practice/leap/.articles/performance/benchmark/leap_benchmark.cpp b/exercises/practice/leap/.articles/performance/benchmark/leap_benchmark.cpp index d02975c08..04e13fe51 100644 --- a/exercises/practice/leap/.articles/performance/benchmark/leap_benchmark.cpp +++ b/exercises/practice/leap/.articles/performance/benchmark/leap_benchmark.cpp @@ -9,14 +9,15 @@ #include "boost/date_time/gregorian/gregorian_types.hpp" -static std::vector generate_data(size_t size) -{ +static std::vector generate_data(size_t size) { std::random_device rd; std::mt19937 generator(rd()); std::uniform_int_distribution<> distribution(1400, 9999); std::vector data(size); - std::generate(data.begin(), data.end(), [&distribution, &generator]() { return distribution(generator); }); + std::generate(data.begin(), data.end(), [&distribution, &generator]() { + return distribution(generator); + }); return data; } @@ -25,46 +26,49 @@ const std::vector data{generate_data(limit)}; bool result = true; static void BM_Leap_boolean_chain(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { - result = (data.at(i) % 4 == 0) && (data.at(i) % 100 != 0 || data.at(i) % 400 == 0); + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { + result = (data.at(i) % 4 == 0) && + (data.at(i) % 100 != 0 || data.at(i) % 400 == 0); } } } BENCHMARK(BM_Leap_boolean_chain); static void BM_Leap_boolean_chain_inverse(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { - result = (data.at(i) % 400 == 0) || (data.at(i) % 100 != 0 && data.at(i) % 4 == 0); + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { + result = (data.at(i) % 400 == 0) || + (data.at(i) % 100 != 0 && data.at(i) % 4 == 0); } } } BENCHMARK(BM_Leap_boolean_chain_inverse); static void BM_Leap_ternary(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { - result = data.at(i) % 100 == 0 ? data.at(i) % 400 == 0 : data.at(i) % 4 == 0; + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { + result = data.at(i) % 100 == 0 ? data.at(i) % 400 == 0 + : data.at(i) % 4 == 0; } } } BENCHMARK(BM_Leap_ternary); static void BM_Leap_chrono(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { result = std::chrono::year{data.at(i)}.is_leap(); } } } BENCHMARK(BM_Leap_chrono); - static void BM_Leap_boost(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { - result = boost::gregorian::gregorian_calendar::is_leap_year(data.at(i)); + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { + result = + boost::gregorian::gregorian_calendar::is_leap_year(data.at(i)); } } } @@ -72,8 +76,8 @@ BENCHMARK(BM_Leap_boost); // How much does the iteration of the array cost? static void BM_empty_read(benchmark::State& state) { - for(auto _ : state) { - for (size_t i = 0; i < limit; ++i) { + for (auto _ : state) { + for (size_t i = 0; i < limit; ++i) { result = true; } } diff --git a/exercises/practice/leap/.meta/example.h b/exercises/practice/leap/.meta/example.h index 9a8980a27..3d4bd23af 100644 --- a/exercises/practice/leap/.meta/example.h +++ b/exercises/practice/leap/.meta/example.h @@ -1,14 +1,12 @@ #if !defined(LEAP_H) #define LEAP_H -namespace leap -{ +namespace leap { -inline bool is_leap_year(int year) -{ +inline bool is_leap_year(int year) { return (year % 100) ? (year % 4 == 0) : (year % 400 == 0); } -} +} // namespace leap #endif diff --git a/exercises/practice/leap/leap.cpp b/exercises/practice/leap/leap.cpp index 9d9d36040..0dd86014e 100644 --- a/exercises/practice/leap/leap.cpp +++ b/exercises/practice/leap/leap.cpp @@ -1,5 +1,3 @@ #include "leap.h" -namespace leap { - -} // namespace leap +namespace leap {} // namespace leap diff --git a/exercises/practice/leap/leap.h b/exercises/practice/leap/leap.h index fda7e0932..6698b8bbd 100644 --- a/exercises/practice/leap/leap.h +++ b/exercises/practice/leap/leap.h @@ -1,8 +1,6 @@ #if !defined(LEAP_H) #define LEAP_H -namespace leap { +namespace leap {} // namespace leap -} // namespace leap - -#endif // LEAP_H \ No newline at end of file +#endif // LEAP_H \ No newline at end of file diff --git a/exercises/practice/leap/leap_test.cpp b/exercises/practice/leap/leap_test.cpp index 61ec8e76a..9b5d4fb28 100644 --- a/exercises/practice/leap/leap_test.cpp +++ b/exercises/practice/leap/leap_test.cpp @@ -5,34 +5,24 @@ #include "test/catch.hpp" #endif -TEST_CASE("not_divisible_by_4") -{ - REQUIRE(!leap::is_leap_year(2015)); -} +TEST_CASE("not_divisible_by_4") { REQUIRE(!leap::is_leap_year(2015)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("divisible_by_2_not_divisible_by_4") -{ +TEST_CASE("divisible_by_2_not_divisible_by_4") { REQUIRE(!leap::is_leap_year(1970)); } -TEST_CASE("divisible_by_4_not_divisible_by_100") -{ +TEST_CASE("divisible_by_4_not_divisible_by_100") { REQUIRE(leap::is_leap_year(1996)); } -TEST_CASE("divisible_by_100_not_divisible_by_400") -{ +TEST_CASE("divisible_by_100_not_divisible_by_400") { REQUIRE(!leap::is_leap_year(2100)); } -TEST_CASE("divisible_by_400") -{ - REQUIRE(leap::is_leap_year(2000)); -} +TEST_CASE("divisible_by_400") { REQUIRE(leap::is_leap_year(2000)); } -TEST_CASE("divisible_by_200_not_divisible_by_400") -{ +TEST_CASE("divisible_by_200_not_divisible_by_400") { REQUIRE(!leap::is_leap_year(1800)); } #endif diff --git a/exercises/practice/linked-list/.meta/example.cpp b/exercises/practice/linked-list/.meta/example.cpp index 82f34e7e7..b47fb02a2 100644 --- a/exercises/practice/linked-list/.meta/example.cpp +++ b/exercises/practice/linked-list/.meta/example.cpp @@ -1,5 +1,3 @@ #include "linked_list.h" -namespace linked_list { - -} // namespace linked_list +namespace linked_list {} // namespace linked_list diff --git a/exercises/practice/linked-list/linked_list.cpp b/exercises/practice/linked-list/linked_list.cpp index dc245ddd5..045e94100 100644 --- a/exercises/practice/linked-list/linked_list.cpp +++ b/exercises/practice/linked-list/linked_list.cpp @@ -1,5 +1,3 @@ #include "linked_list.h" -namespace linked_list { - -} // namespace linked_list \ No newline at end of file +namespace linked_list {} // namespace linked_list \ No newline at end of file diff --git a/exercises/practice/linked-list/linked_list.h b/exercises/practice/linked-list/linked_list.h index b2fe81718..d4eb8ebc5 100644 --- a/exercises/practice/linked-list/linked_list.h +++ b/exercises/practice/linked-list/linked_list.h @@ -1,5 +1,3 @@ #pragma once -namespace linked_list { - -} // namespace linked_list +namespace linked_list {} // namespace linked_list diff --git a/exercises/practice/linked-list/linked_list_test.cpp b/exercises/practice/linked-list/linked_list_test.cpp index 91be8f3fc..889c07a46 100644 --- a/exercises/practice/linked-list/linked_list_test.cpp +++ b/exercises/practice/linked-list/linked_list_test.cpp @@ -11,7 +11,8 @@ This track implements `erase` instead. The tests have been renamed accordingly. */ -TEST_CASE("pop gets element from the list", "[7f7e3987-b954-41b8-8084-99beca08752c]") { +TEST_CASE("pop gets element from the list", + "[7f7e3987-b954-41b8-8084-99beca08752c]") { linked_list::List llist{}; llist.push(7); REQUIRE(7 == llist.pop()); @@ -19,7 +20,8 @@ TEST_CASE("pop gets element from the list", "[7f7e3987-b954-41b8-8084-99beca0875 #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("push/pop respectively add/remove at the end of the list", "[c3f67e5d-cfa2-4c3e-a18f-7ce999c3c885]") { +TEST_CASE("push/pop respectively add/remove at the end of the list", + "[c3f67e5d-cfa2-4c3e-a18f-7ce999c3c885]") { linked_list::List llist{}; llist.push(11); llist.push(13); @@ -27,13 +29,15 @@ TEST_CASE("push/pop respectively add/remove at the end of the list", "[c3f67e5d- REQUIRE(11 == llist.pop()); } -TEST_CASE("shift gets an element from the list", "[00ea24ce-4f5c-4432-abb4-cc6e85462657]") { +TEST_CASE("shift gets an element from the list", + "[00ea24ce-4f5c-4432-abb4-cc6e85462657]") { linked_list::List llist{}; llist.push(17); REQUIRE(17 == llist.shift()); } -TEST_CASE("shift gets first element from the list", "[37962ee0-3324-4a29-b588-5a4c861e6564]") { +TEST_CASE("shift gets first element from the list", + "[37962ee0-3324-4a29-b588-5a4c861e6564]") { linked_list::List llist{}; llist.push(23); llist.push(5); @@ -41,7 +45,8 @@ TEST_CASE("shift gets first element from the list", "[37962ee0-3324-4a29-b588-5a REQUIRE(5 == llist.shift()); } -TEST_CASE("unshift adds element at start of the list", "[30a3586b-e9dc-43fb-9a73-2770cec2c718]") { +TEST_CASE("unshift adds element at start of the list", + "[30a3586b-e9dc-43fb-9a73-2770cec2c718]") { linked_list::List llist{}; llist.unshift(23); llist.unshift(5); @@ -49,7 +54,8 @@ TEST_CASE("unshift adds element at start of the list", "[30a3586b-e9dc-43fb-9a73 REQUIRE(23 == llist.shift()); } -TEST_CASE("pop, push, shift, and unshift can be used in any order", "[042f71e4-a8a7-4cf0-8953-7e4f3a21c42d]") { +TEST_CASE("pop, push, shift, and unshift can be used in any order", + "[042f71e4-a8a7-4cf0-8953-7e4f3a21c42d]") { linked_list::List llist{}; llist.push(1); llist.push(2); @@ -75,7 +81,8 @@ TEST_CASE("count a list with items", "[fc055689-5cbe-4cd9-b994-02e2abbb40a5]") { REQUIRE(2 == llist.count()); } -TEST_CASE("count is correct after mutation", "[8272cef5-130d-40ea-b7f6-5ffd0790d650]") { +TEST_CASE("count is correct after mutation", + "[8272cef5-130d-40ea-b7f6-5ffd0790d650]") { linked_list::List llist{}; llist.push(31); REQUIRE(1 == llist.count()); @@ -87,7 +94,8 @@ TEST_CASE("count is correct after mutation", "[8272cef5-130d-40ea-b7f6-5ffd0790d REQUIRE(0 == llist.count()); } -TEST_CASE("popping to empty doesn't break the list", "[229b8f7a-bd8a-4798-b64f-0dc0bb356d95]") { +TEST_CASE("popping to empty doesn't break the list", + "[229b8f7a-bd8a-4798-b64f-0dc0bb356d95]") { linked_list::List llist{}; llist.push(41); llist.push(59); @@ -98,7 +106,8 @@ TEST_CASE("popping to empty doesn't break the list", "[229b8f7a-bd8a-4798-b64f-0 REQUIRE(47 == llist.pop()); } -TEST_CASE("shifting to empty doesn't break the list", "[4e1948b4-514e-424b-a3cf-a1ebbfa2d1ad]") { +TEST_CASE("shifting to empty doesn't break the list", + "[4e1948b4-514e-424b-a3cf-a1ebbfa2d1ad]") { linked_list::List llist{}; llist.push(41); llist.push(59); @@ -116,7 +125,8 @@ TEST_CASE("erases the only element", "[e8f7c600-d597-4f79-949d-8ad8bae895a6]") { REQUIRE(0 == llist.count()); } -TEST_CASE("erases the element with the specified value from the list", "[fd65e422-51f3-45c0-9fd0-c33da638f89b]") { +TEST_CASE("erases the element with the specified value from the list", + "[fd65e422-51f3-45c0-9fd0-c33da638f89b]") { linked_list::List llist{}; llist.push(71); llist.push(83); @@ -127,8 +137,12 @@ TEST_CASE("erases the element with the specified value from the list", "[fd65e42 REQUIRE(71 == llist.shift()); } -TEST_CASE("erases the element with the specified value from the list, re-assigns tail", "[59db191a-b17f-4ab7-9c5c-60711ec1d013]") { - linked_list::List llist{}; +TEST_CASE( + // clang-format off + "erases the element with the specified value from the list, re-assigns tail", + // clang-format on + "[59db191a-b17f-4ab7-9c5c-60711ec1d013]") { + linked_list::List llist{}; llist.push(71); llist.push(83); llist.push(79); @@ -138,8 +152,12 @@ TEST_CASE("erases the element with the specified value from the list, re-assigns REQUIRE(71 == llist.pop()); } -TEST_CASE("erases the element with the specified value from the list, re-assigns head", "[58242222-5d39-415b-951d-8128247f8993]") { - linked_list::List llist{}; +TEST_CASE( + // clang-format off + "erases the element with the specified value from the list, re-assigns head", + // clang-format on + "[58242222-5d39-415b-951d-8128247f8993]") { + linked_list::List llist{}; llist.push(71); llist.push(83); llist.push(79); @@ -149,8 +167,9 @@ TEST_CASE("erases the element with the specified value from the list, re-assigns REQUIRE(79 == llist.shift()); } -TEST_CASE("erases the first of two elements", "[ee3729ee-3405-4bd2-9bad-de0d4aa5d647]") { - linked_list::List llist{}; +TEST_CASE("erases the first of two elements", + "[ee3729ee-3405-4bd2-9bad-de0d4aa5d647]") { + linked_list::List llist{}; llist.push(97); llist.push(101); llist.erase(97); @@ -158,8 +177,9 @@ TEST_CASE("erases the first of two elements", "[ee3729ee-3405-4bd2-9bad-de0d4aa5 REQUIRE(101 == llist.pop()); } -TEST_CASE("erases the second of two elements", "[47e3b3b4-b82c-4c23-8c1a-ceb9b17cb9fb]") { - linked_list::List llist{}; +TEST_CASE("erases the second of two elements", + "[47e3b3b4-b82c-4c23-8c1a-ceb9b17cb9fb]") { + linked_list::List llist{}; llist.push(97); llist.push(101); llist.erase(101); @@ -167,15 +187,17 @@ TEST_CASE("erases the second of two elements", "[47e3b3b4-b82c-4c23-8c1a-ceb9b17 REQUIRE(97 == llist.pop()); } -TEST_CASE("erase does not modify the list if the element is not found", "[7b420958-f285-4922-b8f9-10d9dcab5179]") { - linked_list::List llist{}; +TEST_CASE("erase does not modify the list if the element is not found", + "[7b420958-f285-4922-b8f9-10d9dcab5179]") { + linked_list::List llist{}; llist.push(89); llist.erase(103); REQUIRE(1 == llist.count()); } -TEST_CASE("erases only the first occurrence", "[7e04828f-6082-44e3-a059-201c63252a76]") { - linked_list::List llist{}; +TEST_CASE("erases only the first occurrence", + "[7e04828f-6082-44e3-a059-201c63252a76]") { + linked_list::List llist{}; llist.push(73); llist.push(9); llist.push(9); diff --git a/exercises/practice/list-ops/.meta/example.cpp b/exercises/practice/list-ops/.meta/example.cpp index 432302db5..3b4dfc0cd 100644 --- a/exercises/practice/list-ops/.meta/example.cpp +++ b/exercises/practice/list-ops/.meta/example.cpp @@ -1,5 +1,3 @@ #include "list_ops.h" -namespace list_ops { - -} // namespace list_ops +namespace list_ops {} // namespace list_ops diff --git a/exercises/practice/list-ops/list_ops.cpp b/exercises/practice/list-ops/list_ops.cpp index 432302db5..3b4dfc0cd 100644 --- a/exercises/practice/list-ops/list_ops.cpp +++ b/exercises/practice/list-ops/list_ops.cpp @@ -1,5 +1,3 @@ #include "list_ops.h" -namespace list_ops { - -} // namespace list_ops +namespace list_ops {} // namespace list_ops diff --git a/exercises/practice/list-ops/list_ops.h b/exercises/practice/list-ops/list_ops.h index 2d9fd5770..88004c616 100644 --- a/exercises/practice/list-ops/list_ops.h +++ b/exercises/practice/list-ops/list_ops.h @@ -1,5 +1,3 @@ #pragma once -namespace list_ops { - -} // namespace list_ops +namespace list_ops {} // namespace list_ops diff --git a/exercises/practice/list-ops/list_ops_test.cpp b/exercises/practice/list-ops/list_ops_test.cpp index 265964537..353d80bfd 100644 --- a/exercises/practice/list-ops/list_ops_test.cpp +++ b/exercises/practice/list-ops/list_ops_test.cpp @@ -5,198 +5,214 @@ #include "test/catch.hpp" #endif - TEST_CASE("append: empty lists", "[485b9452-bf94-40f7-a3db-c3cf4850066a]") { - std::vector left{}; - std::vector right{}; - list_ops::append(left, right); + std::vector left{}; + std::vector right{}; + list_ops::append(left, right); - std::vector expected{}; - REQUIRE(left == expected); + std::vector expected{}; + REQUIRE(left == expected); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("append: list to empty list", "[2c894696-b609-4569-b149-8672134d340a]") { - std::vector left{}; - std::vector right{1, 2, 3, 4}; - list_ops::append(left, right); +TEST_CASE("append: list to empty list", + "[2c894696-b609-4569-b149-8672134d340a]") { + std::vector left{}; + std::vector right{1, 2, 3, 4}; + list_ops::append(left, right); - std::vector expected{1, 2, 3, 4}; - REQUIRE(left == expected); + std::vector expected{1, 2, 3, 4}; + REQUIRE(left == expected); } -TEST_CASE("append: empty list to list", "[e842efed-3bf6-4295-b371-4d67a4fdf19c]") { - std::vector left{1, 2, 3, 4}; - std::vector right{}; - list_ops::append(left, right); +TEST_CASE("append: empty list to list", + "[e842efed-3bf6-4295-b371-4d67a4fdf19c]") { + std::vector left{1, 2, 3, 4}; + std::vector right{}; + list_ops::append(left, right); - std::vector expected{1, 2, 3, 4}; - REQUIRE(left == expected); + std::vector expected{1, 2, 3, 4}; + REQUIRE(left == expected); } TEST_CASE("append: non-empty lists", "[71dcf5eb-73ae-4a0e-b744-a52ee387922f]") { - std::vector left{1, 2}; - std::vector right{2, 3, 4, 5}; - list_ops::append(left, right); + std::vector left{1, 2}; + std::vector right{2, 3, 4, 5}; + list_ops::append(left, right); - std::vector expected{1, 2, 2, 3, 4, 5}; - REQUIRE(left == expected); + std::vector expected{1, 2, 2, 3, 4, 5}; + REQUIRE(left == expected); } TEST_CASE("concat: empty list", "[28444355-201b-4af2-a2f6-5550227bde21]") { - std::vector> input{}; - auto result {list_ops::concat(input)}; + std::vector> input{}; + auto result{list_ops::concat(input)}; - std::vector expected{}; - REQUIRE(result == expected); + std::vector expected{}; + REQUIRE(result == expected); } TEST_CASE("concat: list of lists", "[331451c1-9573-42a1-9869-2d06e3b389a9]") { - std::vector> input{{1, 2}, {3}, {}, {4, 5, 6}}; - auto result {list_ops::concat(input)}; + std::vector> input{{1, 2}, {3}, {}, {4, 5, 6}}; + auto result{list_ops::concat(input)}; - std::vector expected{1, 2, 3, 4, 5, 6}; - REQUIRE(result == expected); + std::vector expected{1, 2, 3, 4, 5, 6}; + REQUIRE(result == expected); } -TEST_CASE("concat: list of nested lists", "[d6ecd72c-197f-40c3-89a4-aa1f45827e09]") { - std::vector>> input{{{1}, {2}}, {{3}}, {{}}, {{4, 5, 6}}}; - auto result {list_ops::concat(input)}; +TEST_CASE("concat: list of nested lists", + "[d6ecd72c-197f-40c3-89a4-aa1f45827e09]") { + std::vector>> input{ + {{1}, {2}}, {{3}}, {{}}, {{4, 5, 6}}}; + auto result{list_ops::concat(input)}; - std::vector> expected{{1}, {2}, {3}, {}, {4, 5, 6}}; - REQUIRE(result == expected); + std::vector> expected{{1}, {2}, {3}, {}, {4, 5, 6}}; + REQUIRE(result == expected); } TEST_CASE("filter: empty list", "[0524fba8-3e0f-4531-ad2b-f7a43da86a16]") { - std::vector input{}; - auto lambda_func = [] (int x) { return x % 2 == 1;}; - auto result {list_ops::filter(input, lambda_func)}; + std::vector input{}; + auto lambda_func = [](int x) { return x % 2 == 1; }; + auto result{list_ops::filter(input, lambda_func)}; - std::vector expected{}; - REQUIRE(result == expected); + std::vector expected{}; + REQUIRE(result == expected); } TEST_CASE("filter: non-empty list", "[88494bd5-f520-4edb-8631-88e415b62d24]") { - std::vector input{1, 2, 3, 5}; - auto lambda_func = [] (int x) { return x % 2 == 1;}; - auto result {list_ops::filter(input, lambda_func)}; + std::vector input{1, 2, 3, 5}; + auto lambda_func = [](int x) { return x % 2 == 1; }; + auto result{list_ops::filter(input, lambda_func)}; - std::vector expected{1, 3, 5}; - REQUIRE(result == expected); + std::vector expected{1, 3, 5}; + REQUIRE(result == expected); } TEST_CASE("length: empty list", "[1cf0b92d-8d96-41d5-9c21-7b3c37cb6aad]") { - std::vector input{}; - auto result {list_ops::length(input)}; - size_t expected{0}; + std::vector input{}; + auto result{list_ops::length(input)}; + size_t expected{0}; - REQUIRE(result == expected); + REQUIRE(result == expected); } TEST_CASE("length: non-empty list", "[d7b8d2d9-2d16-44c4-9a19-6e5f237cb71e]") { - std::vector input{1, 2, 3, 4}; - auto result {list_ops::length(input)}; - size_t expected{4}; + std::vector input{1, 2, 3, 4}; + auto result{list_ops::length(input)}; + size_t expected{4}; - REQUIRE(result == expected); + REQUIRE(result == expected); } TEST_CASE("map: empty list", "[c0bc8962-30e2-4bec-9ae4-668b8ecd75aa]") { - std::vector input{}; - auto lambda_func = [] (int x) { return x + 1;}; - auto result {list_ops::map(input, lambda_func)}; + std::vector input{}; + auto lambda_func = [](int x) { return x + 1; }; + auto result{list_ops::map(input, lambda_func)}; - std::vector expected{}; - REQUIRE(result == expected); + std::vector expected{}; + REQUIRE(result == expected); } TEST_CASE("map: non-empty list", "[11e71a95-e78b-4909-b8e4-60cdcaec0e91]") { - std::vector input{1, 3, 5, 7}; - auto lambda_func = [] (int x) { return x + 1;}; - auto result {list_ops::map(input, lambda_func)}; + std::vector input{1, 3, 5, 7}; + auto lambda_func = [](int x) { return x + 1; }; + auto result{list_ops::map(input, lambda_func)}; - std::vector expected{2, 4, 6, 8}; - REQUIRE(result == expected); + std::vector expected{2, 4, 6, 8}; + REQUIRE(result == expected); } TEST_CASE("foldl: empty list", "[36549237-f765-4a4c-bfd9-5d3a8f7b07d2]") { - std::vector input{}; - auto lambda_func = [] (int x, int y) { return x * y;}; - auto result {list_ops::foldl(input, 2, lambda_func)}; + std::vector input{}; + auto lambda_func = [](int x, int y) { return x * y; }; + auto result{list_ops::foldl(input, 2, lambda_func)}; - int expected{2}; - REQUIRE(result == expected); + int expected{2}; + REQUIRE(result == expected); } -TEST_CASE("foldl: direction independent function applied to non-empty list", "[7a626a3c-03ec-42bc-9840-53f280e13067]") { - std::vector input{1, 2, 3, 4}; - auto lambda_func = [] (int x, int y) { return x + y;}; - auto result {list_ops::foldl(input, 5, lambda_func)}; +TEST_CASE("foldl: direction independent function applied to non-empty list", + "[7a626a3c-03ec-42bc-9840-53f280e13067]") { + std::vector input{1, 2, 3, 4}; + auto lambda_func = [](int x, int y) { return x + y; }; + auto result{list_ops::foldl(input, 5, lambda_func)}; - int expected{15}; - REQUIRE(result == expected); + int expected{15}; + REQUIRE(result == expected); } -TEST_CASE("foldl: direction dependent function applied to non-empty list", "[d7fcad99-e88e-40e1-a539-4c519681f390]") { - std::vector input{1.0, 2.0, 3.0, 4.0}; - auto lambda_func = [] (double acc, double el) { return el / acc;}; - auto result {list_ops::foldl(input, 24.0, lambda_func)}; +TEST_CASE("foldl: direction dependent function applied to non-empty list", + "[d7fcad99-e88e-40e1-a539-4c519681f390]") { + std::vector input{1.0, 2.0, 3.0, 4.0}; + auto lambda_func = [](double acc, double el) { return el / acc; }; + auto result{list_ops::foldl(input, 24.0, lambda_func)}; - double expected{64.0}; - REQUIRE(result == expected); + double expected{64.0}; + REQUIRE(result == expected); } TEST_CASE("foldr: empty list", "[17214edb-20ba-42fc-bda8-000a5ab525b0]") { - std::vector input{}; - auto lambda_func = [] (int acc, int el) { return el * acc;}; - auto result {list_ops::foldr(input, 2, lambda_func)}; + std::vector input{}; + auto lambda_func = [](int acc, int el) { return el * acc; }; + auto result{list_ops::foldr(input, 2, lambda_func)}; - int expected{2}; - REQUIRE(result == expected); + int expected{2}; + REQUIRE(result == expected); } -TEST_CASE("foldr: direction independent function applied to non-empty list", "[e1c64db7-9253-4a3d-a7c4-5273b9e2a1bd]") { - std::vector input{1, 2, 3, 4}; - auto lambda_func = [] (int acc, int el) { return el + acc;}; - auto result {list_ops::foldr(input, 5, lambda_func)}; +TEST_CASE("foldr: direction independent function applied to non-empty list", + "[e1c64db7-9253-4a3d-a7c4-5273b9e2a1bd]") { + std::vector input{1, 2, 3, 4}; + auto lambda_func = [](int acc, int el) { return el + acc; }; + auto result{list_ops::foldr(input, 5, lambda_func)}; - int expected{15}; - REQUIRE(result == expected); + int expected{15}; + REQUIRE(result == expected); } -TEST_CASE("foldr: direction dependent function applied to non-empty list", "[8066003b-f2ff-437e-9103-66e6df474844]") { - std::vector input{1.0, 2.0, 3.0, 4.0}; - auto lambda_func = [] (double acc, double el) { return el / acc;}; - auto result {list_ops::foldr(input, 24.0, lambda_func)}; +TEST_CASE("foldr: direction dependent function applied to non-empty list", + "[8066003b-f2ff-437e-9103-66e6df474844]") { + std::vector input{1.0, 2.0, 3.0, 4.0}; + auto lambda_func = [](double acc, double el) { return el / acc; }; + auto result{list_ops::foldr(input, 24.0, lambda_func)}; - double expected{9.0}; - REQUIRE(result == expected); + double expected{9.0}; + REQUIRE(result == expected); } TEST_CASE("reverse: empty list", "[94231515-050e-4841-943d-d4488ab4ee30]") { - std::vector input{}; - auto result {list_ops::reverse(input)}; + std::vector input{}; + auto result{list_ops::reverse(input)}; - std::vector expected{}; - REQUIRE(result == expected); + std::vector expected{}; + REQUIRE(result == expected); } TEST_CASE("reverse: non-empty list", "[fcc03d1e-42e0-4712-b689-d54ad761f360]") { - std::vector input{1, 3, 5, 7}; - auto result {list_ops::reverse(input)}; - - std::vector expected{7, 5, 3, 1}; - REQUIRE(result == expected); -} - -TEST_CASE("reverse: list of lists is not flattened", "[40872990-b5b8-4cb8-9085-d91fc0d05d26]") { - std::vector> input{{1, 2}, {3}, {}, {4, 5, 6}}; - auto result {list_ops::reverse(input)}; - - std::vector> expected{{4, 5, 6,}, {}, {3}, {1, 2}}; - REQUIRE(result == expected); - //REQUIRE({[4, 5, 6], [], [3], [1, 2]} == list_ops::reverse({[1, 2], [3], [], [4, 5, 6]})); + std::vector input{1, 3, 5, 7}; + auto result{list_ops::reverse(input)}; + + std::vector expected{7, 5, 3, 1}; + REQUIRE(result == expected); +} + +TEST_CASE("reverse: list of lists is not flattened", + "[40872990-b5b8-4cb8-9085-d91fc0d05d26]") { + std::vector> input{{1, 2}, {3}, {}, {4, 5, 6}}; + auto result{list_ops::reverse(input)}; + + std::vector> expected{{ + 4, + 5, + 6, + }, + {}, + {3}, + {1, 2}}; + REQUIRE(result == expected); + // REQUIRE({[4, 5, 6], [], [3], [1, 2]} == list_ops::reverse({[1, 2], [3], + // [], [4, 5, 6]})); } #endif diff --git a/exercises/practice/luhn/luhn.cpp b/exercises/practice/luhn/luhn.cpp index b2279a919..4ded7b19b 100644 --- a/exercises/practice/luhn/luhn.cpp +++ b/exercises/practice/luhn/luhn.cpp @@ -1,5 +1,3 @@ #include "luhn.h" -namespace luhn { - -} // namespace luhn +namespace luhn {} // namespace luhn diff --git a/exercises/practice/luhn/luhn.h b/exercises/practice/luhn/luhn.h index 0bda8e340..eefcd4b27 100644 --- a/exercises/practice/luhn/luhn.h +++ b/exercises/practice/luhn/luhn.h @@ -1,8 +1,6 @@ #if !defined(LUHN_H) #define LUHN_H -namespace luhn { +namespace luhn {} // namespace luhn -} // namespace luhn - -#endif // LUHN_H \ No newline at end of file +#endif // LUHN_H \ No newline at end of file diff --git a/exercises/practice/luhn/luhn_test.cpp b/exercises/practice/luhn/luhn_test.cpp index 79f58fc53..31f1bd1d2 100644 --- a/exercises/practice/luhn/luhn_test.cpp +++ b/exercises/practice/luhn/luhn_test.cpp @@ -5,95 +5,116 @@ #include "test/catch.hpp" #endif - -TEST_CASE("single digit strings can not be valid", "[792a7082-feb7-48c7-b88b-bbfec160865e]") { - REQUIRE(false == luhn::valid("1")); +TEST_CASE("single digit strings can not be valid", + "[792a7082-feb7-48c7-b88b-bbfec160865e]") { + REQUIRE(false == luhn::valid("1")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("a single zero is invalid", "[698a7924-64d4-4d89-8daa-32e1aadc271e]") { - REQUIRE(false == luhn::valid("0")); +TEST_CASE("a single zero is invalid", + "[698a7924-64d4-4d89-8daa-32e1aadc271e]") { + REQUIRE(false == luhn::valid("0")); } -TEST_CASE("a simple valid SIN that remains valid if reversed", "[73c2f62b-9b10-4c9f-9a04-83cee7367965]") { - REQUIRE(true == luhn::valid("059")); +TEST_CASE("a simple valid SIN that remains valid if reversed", + "[73c2f62b-9b10-4c9f-9a04-83cee7367965]") { + REQUIRE(true == luhn::valid("059")); } -TEST_CASE("a simple valid SIN that becomes invalid if reversed", "[9369092e-b095-439f-948d-498bd076be11]") { - REQUIRE(true == luhn::valid("59")); +TEST_CASE("a simple valid SIN that becomes invalid if reversed", + "[9369092e-b095-439f-948d-498bd076be11]") { + REQUIRE(true == luhn::valid("59")); } TEST_CASE("a valid Canadian SIN", "[8f9f2350-1faf-4008-ba84-85cbb93ffeca]") { - REQUIRE(true == luhn::valid("055 444 285")); + REQUIRE(true == luhn::valid("055 444 285")); } TEST_CASE("invalid Canadian SIN", "[1cdcf269-6560-44fc-91f6-5819a7548737]") { - REQUIRE(false == luhn::valid("055 444 286")); + REQUIRE(false == luhn::valid("055 444 286")); } TEST_CASE("invalid credit card", "[656c48c1-34e8-4e60-9a5a-aad8a367810a]") { - REQUIRE(false == luhn::valid("8273 1232 7352 0569")); + REQUIRE(false == luhn::valid("8273 1232 7352 0569")); } -TEST_CASE("invalid long number with an even remainder", "[20e67fad-2121-43ed-99a8-14b5b856adb9]") { - REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9012")); +TEST_CASE("invalid long number with an even remainder", + "[20e67fad-2121-43ed-99a8-14b5b856adb9]") { + REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9012")); } -TEST_CASE("invalid long number with a remainder divisible by 5", "[7e7c9fc1-d994-457c-811e-d390d52fba5e]") { - REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9013")); +TEST_CASE("invalid long number with a remainder divisible by 5", + "[7e7c9fc1-d994-457c-811e-d390d52fba5e]") { + REQUIRE(false == luhn::valid("1 2345 6789 1234 5678 9013")); } -TEST_CASE("valid number with an even number of digits", "[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]") { - REQUIRE(true == luhn::valid("095 245 88")); +TEST_CASE("valid number with an even number of digits", + "[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]") { + REQUIRE(true == luhn::valid("095 245 88")); } -TEST_CASE("valid number with an odd number of spaces", "[ef081c06-a41f-4761-8492-385e13c8202d]") { - REQUIRE(true == luhn::valid("234 567 891 234")); +TEST_CASE("valid number with an odd number of spaces", + "[ef081c06-a41f-4761-8492-385e13c8202d]") { + REQUIRE(true == luhn::valid("234 567 891 234")); } -TEST_CASE("valid strings with a non-digit added at the end become invalid", "[bef66f64-6100-4cbb-8f94-4c9713c5e5b2]") { - REQUIRE(false == luhn::valid("059a")); +TEST_CASE("valid strings with a non-digit added at the end become invalid", + "[bef66f64-6100-4cbb-8f94-4c9713c5e5b2]") { + REQUIRE(false == luhn::valid("059a")); } -TEST_CASE("valid strings with punctuation included become invalid", "[2177e225-9ce7-40f6-b55d-fa420e62938e]") { - REQUIRE(false == luhn::valid("055-444-285")); +TEST_CASE("valid strings with punctuation included become invalid", + "[2177e225-9ce7-40f6-b55d-fa420e62938e]") { + REQUIRE(false == luhn::valid("055-444-285")); } -TEST_CASE("valid strings with symbols included become invalid", "[ebf04f27-9698-45e1-9afe-7e0851d0fe8d]") { - REQUIRE(false == luhn::valid("055# 444$ 285")); +TEST_CASE("valid strings with symbols included become invalid", + "[ebf04f27-9698-45e1-9afe-7e0851d0fe8d]") { + REQUIRE(false == luhn::valid("055# 444$ 285")); } -TEST_CASE("single zero with space is invalid", "[08195c5e-ce7f-422c-a5eb-3e45fece68ba]") { - REQUIRE(false == luhn::valid(" 0")); +TEST_CASE("single zero with space is invalid", + "[08195c5e-ce7f-422c-a5eb-3e45fece68ba]") { + REQUIRE(false == luhn::valid(" 0")); } -TEST_CASE("more than a single zero is valid", "[12e63a3c-f866-4a79-8c14-b359fc386091]") { - REQUIRE(true == luhn::valid("0000 0")); +TEST_CASE("more than a single zero is valid", + "[12e63a3c-f866-4a79-8c14-b359fc386091]") { + REQUIRE(true == luhn::valid("0000 0")); } -TEST_CASE("input digit 9 is correctly converted to output digit 9", "[ab56fa80-5de8-4735-8a4a-14dae588663e]") { - REQUIRE(true == luhn::valid("091")); +TEST_CASE("input digit 9 is correctly converted to output digit 9", + "[ab56fa80-5de8-4735-8a4a-14dae588663e]") { + REQUIRE(true == luhn::valid("091")); } -TEST_CASE("very long input is valid", "[b9887ee8-8337-46c5-bc45-3bcab51bc36f]") { - REQUIRE(true == luhn::valid("9999999999 9999999999 9999999999 9999999999")); +TEST_CASE("very long input is valid", + "[b9887ee8-8337-46c5-bc45-3bcab51bc36f]") { + REQUIRE(true == luhn::valid("9999999999 9999999999 9999999999 9999999999")); } -TEST_CASE("valid luhn with an odd number of digits and non zero first digit", "[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]") { - REQUIRE(true == luhn::valid("109")); +TEST_CASE("valid luhn with an odd number of digits and non zero first digit", + "[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]") { + REQUIRE(true == luhn::valid("109")); } -TEST_CASE("using ascii value for non-doubled non-digit isn't allowed", "[39a06a5a-5bad-4e0f-b215-b042d46209b1]") { - REQUIRE(false == luhn::valid("055b 444 285")); +TEST_CASE("using ascii value for non-doubled non-digit isn't allowed", + "[39a06a5a-5bad-4e0f-b215-b042d46209b1]") { + REQUIRE(false == luhn::valid("055b 444 285")); } -TEST_CASE("using ascii value for doubled non-digit isn't allowed", "[f94cf191-a62f-4868-bc72-7253114aa157]") { - REQUIRE(false == luhn::valid(":9")); +TEST_CASE("using ascii value for doubled non-digit isn't allowed", + "[f94cf191-a62f-4868-bc72-7253114aa157]") { + REQUIRE(false == luhn::valid(":9")); } -TEST_CASE("non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed", "[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]") { - REQUIRE(false == luhn::valid("59%59")); +TEST_CASE( + // clang-format off + "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed", + // clang-format on + "[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]") { + REQUIRE(false == luhn::valid("59%59")); } #endif diff --git a/exercises/practice/matching-brackets/.meta/example.cpp b/exercises/practice/matching-brackets/.meta/example.cpp index fe5c0c9a1..37000ef4b 100644 --- a/exercises/practice/matching-brackets/.meta/example.cpp +++ b/exercises/practice/matching-brackets/.meta/example.cpp @@ -1,20 +1,19 @@ -#include "matching_brackets.h" #include +#include "matching_brackets.h" + using namespace std; namespace matching_brackets { -bool check(string const& expression) -{ +bool check(string const& expression) { const string open("({["); const string close(")}]"); stack st; for (const char c : expression) { if (open.find(c) != string::npos) { st.push(c); - } - else if (close.find(c) != string::npos) { + } else if (close.find(c) != string::npos) { if (st.empty() || st.top() != open[close.find(c)]) { return false; } @@ -24,5 +23,4 @@ bool check(string const& expression) return st.empty(); } -} - +} // namespace matching_brackets diff --git a/exercises/practice/matching-brackets/.meta/example.h b/exercises/practice/matching-brackets/.meta/example.h index 7d0d7c4a3..ad037c703 100644 --- a/exercises/practice/matching-brackets/.meta/example.h +++ b/exercises/practice/matching-brackets/.meta/example.h @@ -1,10 +1,9 @@ #if !defined(MATCHING_BRACKETS_H) -#define MATCHING_BRACKETS_H +#define MATCHING_BRACKETS_H #include -namespace matching_brackets -{ +namespace matching_brackets { bool check(std::string const& expression); diff --git a/exercises/practice/matching-brackets/matching_brackets.cpp b/exercises/practice/matching-brackets/matching_brackets.cpp index 6d5983ed9..6dfacdef5 100644 --- a/exercises/practice/matching-brackets/matching_brackets.cpp +++ b/exercises/practice/matching-brackets/matching_brackets.cpp @@ -1,5 +1,3 @@ #include "matching_brackets.h" -namespace matching_brackets { - -} // namespace matching_brackets +namespace matching_brackets {} // namespace matching_brackets diff --git a/exercises/practice/matching-brackets/matching_brackets.h b/exercises/practice/matching-brackets/matching_brackets.h index 5cfbaacf2..15c5267c3 100644 --- a/exercises/practice/matching-brackets/matching_brackets.h +++ b/exercises/practice/matching-brackets/matching_brackets.h @@ -1,8 +1,6 @@ #if !defined(MATCHING_BRACKETS_H) #define MATCHING_BRACKETS_H -namespace matching_brackets { +namespace matching_brackets {} // namespace matching_brackets -} // namespace matching_brackets - -#endif // MATCHING_BRACKETS_H \ No newline at end of file +#endif // MATCHING_BRACKETS_H \ No newline at end of file diff --git a/exercises/practice/matching-brackets/matching_brackets_test.cpp b/exercises/practice/matching-brackets/matching_brackets_test.cpp index 4687390b0..c0b4f715a 100644 --- a/exercises/practice/matching-brackets/matching_brackets_test.cpp +++ b/exercises/practice/matching-brackets/matching_brackets_test.cpp @@ -5,74 +5,54 @@ #include "test/catch.hpp" #endif -TEST_CASE("paired_square_brackets") -{ - REQUIRE(matching_brackets::check("[]")); -} +TEST_CASE("paired_square_brackets") { REQUIRE(matching_brackets::check("[]")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("empty_string") -{ - REQUIRE(matching_brackets::check("")); -} +TEST_CASE("empty_string") { REQUIRE(matching_brackets::check("")); } -TEST_CASE("unpaired_brackets") -{ - REQUIRE(!matching_brackets::check("[[")); -} +TEST_CASE("unpaired_brackets") { REQUIRE(!matching_brackets::check("[[")); } -TEST_CASE("wrong_ordered_brackets") -{ +TEST_CASE("wrong_ordered_brackets") { REQUIRE(!matching_brackets::check("}{")); } -TEST_CASE("wrong_closing_bracket") -{ - REQUIRE(!matching_brackets::check("{]")); -} +TEST_CASE("wrong_closing_bracket") { REQUIRE(!matching_brackets::check("{]")); } -TEST_CASE("paired_with_whitespace") -{ +TEST_CASE("paired_with_whitespace") { REQUIRE(matching_brackets::check("{ }")); } -TEST_CASE("simple_nested_brackets") -{ +TEST_CASE("simple_nested_brackets") { REQUIRE(matching_brackets::check("{[]}")); } -TEST_CASE("several_paired_brackets") -{ +TEST_CASE("several_paired_brackets") { REQUIRE(matching_brackets::check("{}[]")); } -TEST_CASE("paired_nested_brackets") -{ +TEST_CASE("paired_nested_brackets") { REQUIRE(matching_brackets::check("([{}({}[])])")); } -TEST_CASE("unopened_closing_brackets") -{ +TEST_CASE("unopened_closing_brackets") { REQUIRE(!matching_brackets::check("{[)][]}")); } -TEST_CASE("unpaired_nested_brackets") -{ +TEST_CASE("unpaired_nested_brackets") { REQUIRE(!matching_brackets::check("([{])")); } -TEST_CASE("paired_wrong_nested_brackets") -{ +TEST_CASE("paired_wrong_nested_brackets") { REQUIRE(!matching_brackets::check("[({]})")); } -TEST_CASE("math_expression") -{ +TEST_CASE("math_expression") { REQUIRE(matching_brackets::check("(((185 + 223.85) * 15) - 543)/2")); } -TEST_CASE("complex_latex_expression") -{ - REQUIRE(matching_brackets::check("\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)")); +TEST_CASE("complex_latex_expression") { + REQUIRE(matching_brackets::check( + "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... " + "x^2 \\end{array}\\right)")); } #endif diff --git a/exercises/practice/meetup/.meta/example.h b/exercises/practice/meetup/.meta/example.h index 65ba6a234..99ab8c603 100644 --- a/exercises/practice/meetup/.meta/example.h +++ b/exercises/practice/meetup/.meta/example.h @@ -3,234 +3,190 @@ #include -namespace meetup -{ +namespace meetup { -class scheduler -{ -public: +class scheduler { + public: scheduler(boost::gregorian::date::month_type month, - boost::gregorian::date::year_type year) - : year_(year), - month_(month) - {} + boost::gregorian::date::year_type year) + : year_(year), month_(month) {} - boost::gregorian::date monteenth() const - { + boost::gregorian::date monteenth() const { return teenth_day(boost::date_time::weekdays::Monday); } - boost::gregorian::date tuesteenth() const - { + boost::gregorian::date tuesteenth() const { return teenth_day(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date wednesteenth() const - { + boost::gregorian::date wednesteenth() const { return teenth_day(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date thursteenth() const - { + boost::gregorian::date thursteenth() const { return teenth_day(boost::date_time::weekdays::Thursday); } - boost::gregorian::date friteenth() const - { + boost::gregorian::date friteenth() const { return teenth_day(boost::date_time::weekdays::Friday); } - boost::gregorian::date saturteenth() const - { + boost::gregorian::date saturteenth() const { return teenth_day(boost::date_time::weekdays::Saturday); } - boost::gregorian::date sunteenth() const - { + boost::gregorian::date sunteenth() const { return teenth_day(boost::date_time::weekdays::Sunday); } - boost::gregorian::date first_monday() const - { + boost::gregorian::date first_monday() const { return first_weekday(boost::date_time::weekdays::Monday); } - boost::gregorian::date first_tuesday() const - { + boost::gregorian::date first_tuesday() const { return first_weekday(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date first_wednesday() const - { + boost::gregorian::date first_wednesday() const { return first_weekday(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date first_thursday() const - { + boost::gregorian::date first_thursday() const { return first_weekday(boost::date_time::weekdays::Thursday); } - boost::gregorian::date first_friday() const - { + boost::gregorian::date first_friday() const { return first_weekday(boost::date_time::weekdays::Friday); } - boost::gregorian::date first_saturday() const - { + boost::gregorian::date first_saturday() const { return first_weekday(boost::date_time::weekdays::Saturday); } - boost::gregorian::date first_sunday() const - { + boost::gregorian::date first_sunday() const { return first_weekday(boost::date_time::weekdays::Sunday); } - boost::gregorian::date second_monday() const - { + boost::gregorian::date second_monday() const { return second_weekday(boost::date_time::weekdays::Monday); } - boost::gregorian::date second_tuesday() const - { + boost::gregorian::date second_tuesday() const { return second_weekday(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date second_wednesday() const - { + boost::gregorian::date second_wednesday() const { return second_weekday(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date second_thursday() const - { + boost::gregorian::date second_thursday() const { return second_weekday(boost::date_time::weekdays::Thursday); } - boost::gregorian::date second_friday() const - { + boost::gregorian::date second_friday() const { return second_weekday(boost::date_time::weekdays::Friday); } - boost::gregorian::date second_saturday() const - { + boost::gregorian::date second_saturday() const { return second_weekday(boost::date_time::weekdays::Saturday); } - boost::gregorian::date second_sunday() const - { + boost::gregorian::date second_sunday() const { return second_weekday(boost::date_time::weekdays::Sunday); } - boost::gregorian::date third_monday() const - { + boost::gregorian::date third_monday() const { return third_weekday(boost::date_time::weekdays::Monday); } - boost::gregorian::date third_tuesday() const - { + boost::gregorian::date third_tuesday() const { return third_weekday(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date third_wednesday() const - { + boost::gregorian::date third_wednesday() const { return third_weekday(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date third_thursday() const - { + boost::gregorian::date third_thursday() const { return third_weekday(boost::date_time::weekdays::Thursday); } - boost::gregorian::date third_friday() const - { + boost::gregorian::date third_friday() const { return third_weekday(boost::date_time::weekdays::Friday); } - boost::gregorian::date third_saturday() const - { + boost::gregorian::date third_saturday() const { return third_weekday(boost::date_time::weekdays::Saturday); } - boost::gregorian::date third_sunday() const - { + boost::gregorian::date third_sunday() const { return third_weekday(boost::date_time::weekdays::Sunday); } - boost::gregorian::date fourth_monday() const - { + boost::gregorian::date fourth_monday() const { return fourth_weekday(boost::date_time::weekdays::Monday); } - boost::gregorian::date fourth_tuesday() const - { + boost::gregorian::date fourth_tuesday() const { return fourth_weekday(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date fourth_wednesday() const - { + boost::gregorian::date fourth_wednesday() const { return fourth_weekday(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date fourth_thursday() const - { + boost::gregorian::date fourth_thursday() const { return fourth_weekday(boost::date_time::weekdays::Thursday); } - boost::gregorian::date fourth_friday() const - { + boost::gregorian::date fourth_friday() const { return fourth_weekday(boost::date_time::weekdays::Friday); } - boost::gregorian::date fourth_saturday() const - { + boost::gregorian::date fourth_saturday() const { return fourth_weekday(boost::date_time::weekdays::Saturday); } - boost::gregorian::date fourth_sunday() const - { + boost::gregorian::date fourth_sunday() const { return fourth_weekday(boost::date_time::weekdays::Sunday); } - boost::gregorian::date last_monday() const - { + boost::gregorian::date last_monday() const { return last_weekday(boost::date_time::weekdays::Monday); } - boost::gregorian::date last_tuesday() const - { + boost::gregorian::date last_tuesday() const { return last_weekday(boost::date_time::weekdays::Tuesday); } - boost::gregorian::date last_wednesday() const - { + boost::gregorian::date last_wednesday() const { return last_weekday(boost::date_time::weekdays::Wednesday); } - boost::gregorian::date last_thursday() const - { + boost::gregorian::date last_thursday() const { return last_weekday(boost::date_time::weekdays::Thursday); } - boost::gregorian::date last_friday() const - { + boost::gregorian::date last_friday() const { return last_weekday(boost::date_time::weekdays::Friday); } - boost::gregorian::date last_saturday() const - { + boost::gregorian::date last_saturday() const { return last_weekday(boost::date_time::weekdays::Saturday); } - boost::gregorian::date last_sunday() const - { + boost::gregorian::date last_sunday() const { return last_weekday(boost::date_time::weekdays::Sunday); } -private: - boost::gregorian::date teenth_day(boost::date_time::weekdays day) const - { - return boost::gregorian::first_day_of_the_week_after(day).get_date({year_, month_, 12}); + private: + boost::gregorian::date teenth_day(boost::date_time::weekdays day) const { + return boost::gregorian::first_day_of_the_week_after(day).get_date( + {year_, month_, 12}); } - boost::gregorian::date first_weekday(boost::date_time::weekdays day) const - { - return boost::gregorian::first_day_of_the_week_in_month(day, month_).get_date(year_); + boost::gregorian::date first_weekday(boost::date_time::weekdays day) const { + return boost::gregorian::first_day_of_the_week_in_month(day, month_) + .get_date(year_); } boost::gregorian::date nth_weekday( boost::gregorian::nth_day_of_the_week_in_month::week_num n, - boost::date_time::weekdays day) const - { - return boost::gregorian::nth_day_of_the_week_in_month(n, day, month_).get_date(year_); + boost::date_time::weekdays day) const { + return boost::gregorian::nth_day_of_the_week_in_month(n, day, month_) + .get_date(year_); } - boost::gregorian::date second_weekday(boost::date_time::weekdays day) const - { - return nth_weekday(boost::gregorian::nth_day_of_the_week_in_month::second, day); + boost::gregorian::date second_weekday( + boost::date_time::weekdays day) const { + return nth_weekday( + boost::gregorian::nth_day_of_the_week_in_month::second, day); } - boost::gregorian::date third_weekday(boost::date_time::weekdays day) const - { - return nth_weekday(boost::gregorian::nth_day_of_the_week_in_month::third, day); + boost::gregorian::date third_weekday(boost::date_time::weekdays day) const { + return nth_weekday( + boost::gregorian::nth_day_of_the_week_in_month::third, day); } - boost::gregorian::date fourth_weekday(boost::date_time::weekdays day) const - { - return nth_weekday(boost::gregorian::nth_day_of_the_week_in_month::fourth, day); + boost::gregorian::date fourth_weekday( + boost::date_time::weekdays day) const { + return nth_weekday( + boost::gregorian::nth_day_of_the_week_in_month::fourth, day); } - boost::gregorian::date last_weekday(boost::date_time::weekdays day) const - { - return boost::gregorian::last_day_of_the_week_in_month(day, month_).get_date(year_); + boost::gregorian::date last_weekday(boost::date_time::weekdays day) const { + return boost::gregorian::last_day_of_the_week_in_month(day, month_) + .get_date(year_); } const boost::gregorian::date::year_type year_; const boost::gregorian::date::month_type month_; }; -} +} // namespace meetup #endif diff --git a/exercises/practice/meetup/meetup.cpp b/exercises/practice/meetup/meetup.cpp index 11d5857f2..959268d25 100644 --- a/exercises/practice/meetup/meetup.cpp +++ b/exercises/practice/meetup/meetup.cpp @@ -1,5 +1,3 @@ #include "meetup.h" -namespace meetup { - -} // namespace meetup +namespace meetup {} // namespace meetup diff --git a/exercises/practice/meetup/meetup.h b/exercises/practice/meetup/meetup.h index 939b108ee..c71127069 100644 --- a/exercises/practice/meetup/meetup.h +++ b/exercises/practice/meetup/meetup.h @@ -1,8 +1,6 @@ #if !defined(MEETUP_H) #define MEETUP_H -namespace meetup { +namespace meetup {} // namespace meetup -} // namespace meetup - -#endif // MEETUP_H \ No newline at end of file +#endif // MEETUP_H \ No newline at end of file diff --git a/exercises/practice/meetup/meetup_test.cpp b/exercises/practice/meetup/meetup_test.cpp index 2c4f99fe4..57ae3acf4 100644 --- a/exercises/practice/meetup/meetup_test.cpp +++ b/exercises/practice/meetup/meetup_test.cpp @@ -1,4 +1,5 @@ #include "meetup.h" + #include #ifdef EXERCISM_TEST_SUITE #include @@ -12,8 +13,7 @@ // See for // documentation on boost::gregorian::date -TEST_CASE("monteenth_of_May_2013") -{ +TEST_CASE("monteenth_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 13}; @@ -21,712 +21,623 @@ TEST_CASE("monteenth_of_May_2013") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("monteenth_of_August_2013") -{ +TEST_CASE("monteenth_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 19}; REQUIRE(expected == meetup.monteenth()); } -TEST_CASE("monteenth_of_September_2013") -{ +TEST_CASE("monteenth_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 16}; REQUIRE(expected == meetup.monteenth()); } -TEST_CASE("tuesteenth_of_March_2013") -{ +TEST_CASE("tuesteenth_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 19}; REQUIRE(expected == meetup.tuesteenth()); } -TEST_CASE("tuesteenth_of_April_2013") -{ +TEST_CASE("tuesteenth_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 16}; REQUIRE(expected == meetup.tuesteenth()); } -TEST_CASE("tuesteenth_of_August_2013") -{ +TEST_CASE("tuesteenth_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 13}; REQUIRE(expected == meetup.tuesteenth()); } -TEST_CASE("wednesteenth_of_January_2013") -{ +TEST_CASE("wednesteenth_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 16}; REQUIRE(expected == meetup.wednesteenth()); } -TEST_CASE("wednesteenth_of_February_2013") -{ +TEST_CASE("wednesteenth_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 13}; REQUIRE(expected == meetup.wednesteenth()); } -TEST_CASE("wednesteenth_of_June_2013") -{ +TEST_CASE("wednesteenth_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 19}; REQUIRE(expected == meetup.wednesteenth()); } -TEST_CASE("thursteenth_of_May_2013") -{ +TEST_CASE("thursteenth_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 16}; REQUIRE(expected == meetup.thursteenth()); } -TEST_CASE("thursteenth_of_June_2013") -{ +TEST_CASE("thursteenth_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 13}; REQUIRE(expected == meetup.thursteenth()); } -TEST_CASE("thursteenth_of_September_2013") -{ +TEST_CASE("thursteenth_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 19}; REQUIRE(expected == meetup.thursteenth()); } -TEST_CASE("friteenth_of_April_2013") -{ +TEST_CASE("friteenth_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 19}; REQUIRE(expected == meetup.friteenth()); } -TEST_CASE("friteenth_of_Aug_2013") -{ +TEST_CASE("friteenth_of_Aug_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 16}; REQUIRE(expected == meetup.friteenth()); } -TEST_CASE("friteenth_of_September_2013") -{ +TEST_CASE("friteenth_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 13}; REQUIRE(expected == meetup.friteenth()); } -TEST_CASE("saturteenth_of_February_2013") -{ +TEST_CASE("saturteenth_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 16}; REQUIRE(expected == meetup.saturteenth()); } -TEST_CASE("saturteenth_of_October_2013") -{ +TEST_CASE("saturteenth_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 19}; REQUIRE(expected == meetup.saturteenth()); } -TEST_CASE("sunteenth_of_May_2013") -{ +TEST_CASE("sunteenth_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 19}; REQUIRE(expected == meetup.sunteenth()); } -TEST_CASE("sunteenth_of_June_2013") -{ +TEST_CASE("sunteenth_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 16}; REQUIRE(expected == meetup.sunteenth()); } -TEST_CASE("sunteenth_of_October_2013") -{ +TEST_CASE("sunteenth_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 13}; REQUIRE(expected == meetup.sunteenth()); } -TEST_CASE("first_Monday_of_March_2013") -{ +TEST_CASE("first_Monday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 4}; REQUIRE(expected == meetup.first_monday()); } -TEST_CASE("first_Monday_of_April_2013") -{ +TEST_CASE("first_Monday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 1}; REQUIRE(expected == meetup.first_monday()); } -TEST_CASE("first_Tuesday_of_May_2013") -{ +TEST_CASE("first_Tuesday_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 7}; REQUIRE(expected == meetup.first_tuesday()); } -TEST_CASE("first_Tuesday_of_June_2013") -{ +TEST_CASE("first_Tuesday_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 4}; REQUIRE(expected == meetup.first_tuesday()); } -TEST_CASE("first_Wednesday_of_July_2013") -{ +TEST_CASE("first_Wednesday_of_July_2013") { const meetup::scheduler meetup{boost::gregorian::Jul, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jul, 3}; REQUIRE(expected == meetup.first_wednesday()); } -TEST_CASE("first_Wednesday_of_August_2013") -{ +TEST_CASE("first_Wednesday_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 7}; REQUIRE(expected == meetup.first_wednesday()); } -TEST_CASE("first_Thursday_of_September_2013") -{ +TEST_CASE("first_Thursday_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 5}; REQUIRE(expected == meetup.first_thursday()); } -TEST_CASE("first_Thursday_of_October_2013") -{ +TEST_CASE("first_Thursday_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 3}; REQUIRE(expected == meetup.first_thursday()); } -TEST_CASE("first_Friday_of_November_2013") -{ +TEST_CASE("first_Friday_of_November_2013") { const meetup::scheduler meetup{boost::gregorian::Nov, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Nov, 1}; REQUIRE(expected == meetup.first_friday()); } -TEST_CASE("first_Friday_of_December_2013") -{ +TEST_CASE("first_Friday_of_December_2013") { const meetup::scheduler meetup{boost::gregorian::Dec, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Dec, 6}; REQUIRE(expected == meetup.first_friday()); } -TEST_CASE("first_Saturday_of_January_2013") -{ +TEST_CASE("first_Saturday_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 5}; REQUIRE(expected == meetup.first_saturday()); } -TEST_CASE("first_Saturday_of_February_2013") -{ +TEST_CASE("first_Saturday_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 2}; REQUIRE(expected == meetup.first_saturday()); } -TEST_CASE("first_Sunday_of_March_2013") -{ +TEST_CASE("first_Sunday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 3}; REQUIRE(expected == meetup.first_sunday()); } -TEST_CASE("first_Sunday_of_April_2013") -{ +TEST_CASE("first_Sunday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 7}; REQUIRE(expected == meetup.first_sunday()); } -TEST_CASE("second_Monday_of_March_2013") -{ +TEST_CASE("second_Monday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 11}; REQUIRE(expected == meetup.second_monday()); } -TEST_CASE("second_Monday_of_April_2013") -{ +TEST_CASE("second_Monday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 8}; REQUIRE(expected == meetup.second_monday()); } -TEST_CASE("second_Tuesday_of_May_2013") -{ +TEST_CASE("second_Tuesday_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 14}; REQUIRE(expected == meetup.second_tuesday()); } -TEST_CASE("second_Tuesday_of_June_2013") -{ +TEST_CASE("second_Tuesday_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 11}; REQUIRE(expected == meetup.second_tuesday()); } -TEST_CASE("second_Wednesday_of_July_2013") -{ +TEST_CASE("second_Wednesday_of_July_2013") { const meetup::scheduler meetup{boost::gregorian::Jul, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jul, 10}; REQUIRE(expected == meetup.second_wednesday()); } -TEST_CASE("second_Wednesday_of_August_2013") -{ +TEST_CASE("second_Wednesday_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 14}; REQUIRE(expected == meetup.second_wednesday()); } -TEST_CASE("second_Thursday_of_September_2013") -{ +TEST_CASE("second_Thursday_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 12}; REQUIRE(expected == meetup.second_thursday()); } -TEST_CASE("second_Thursday_of_October_2013") -{ +TEST_CASE("second_Thursday_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 10}; REQUIRE(expected == meetup.second_thursday()); } -TEST_CASE("second_Friday_of_November_2013") -{ +TEST_CASE("second_Friday_of_November_2013") { const meetup::scheduler meetup{boost::gregorian::Nov, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Nov, 8}; REQUIRE(expected == meetup.second_friday()); } -TEST_CASE("second_Friday_of_December_2013") -{ +TEST_CASE("second_Friday_of_December_2013") { const meetup::scheduler meetup{boost::gregorian::Dec, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Dec, 13}; REQUIRE(expected == meetup.second_friday()); } -TEST_CASE("second_Saturday_of_January_2013") -{ +TEST_CASE("second_Saturday_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 12}; REQUIRE(expected == meetup.second_saturday()); } -TEST_CASE("second_Saturday_of_February_2013") -{ +TEST_CASE("second_Saturday_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 9}; REQUIRE(expected == meetup.second_saturday()); } -TEST_CASE("second_Sunday_of_March_2013") -{ +TEST_CASE("second_Sunday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 10}; REQUIRE(expected == meetup.second_sunday()); } -TEST_CASE("second_Sunday_of_April_2013") -{ +TEST_CASE("second_Sunday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 14}; REQUIRE(expected == meetup.second_sunday()); } -TEST_CASE("third_Monday_of_March_2013") -{ +TEST_CASE("third_Monday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 18}; REQUIRE(expected == meetup.third_monday()); } -TEST_CASE("third_Monday_of_April_2013") -{ +TEST_CASE("third_Monday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 15}; REQUIRE(expected == meetup.third_monday()); } -TEST_CASE("third_Tuesday_of_May_2013") -{ +TEST_CASE("third_Tuesday_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 21}; REQUIRE(expected == meetup.third_tuesday()); } -TEST_CASE("third_Tuesday_of_June_2013") -{ +TEST_CASE("third_Tuesday_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 18}; REQUIRE(expected == meetup.third_tuesday()); } -TEST_CASE("third_Wednesday_of_July_2013") -{ +TEST_CASE("third_Wednesday_of_July_2013") { const meetup::scheduler meetup{boost::gregorian::Jul, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jul, 17}; REQUIRE(expected == meetup.third_wednesday()); } -TEST_CASE("third_Wednesday_of_August_2013") -{ +TEST_CASE("third_Wednesday_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 21}; REQUIRE(expected == meetup.third_wednesday()); } -TEST_CASE("third_Thursday_of_September_2013") -{ +TEST_CASE("third_Thursday_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 19}; REQUIRE(expected == meetup.third_thursday()); } -TEST_CASE("third_Thursday_of_October_2013") -{ +TEST_CASE("third_Thursday_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 17}; REQUIRE(expected == meetup.third_thursday()); } -TEST_CASE("third_Friday_of_November_2013") -{ +TEST_CASE("third_Friday_of_November_2013") { const meetup::scheduler meetup{boost::gregorian::Nov, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Nov, 15}; REQUIRE(expected == meetup.third_friday()); } -TEST_CASE("third_Friday_of_December_2013") -{ +TEST_CASE("third_Friday_of_December_2013") { const meetup::scheduler meetup{boost::gregorian::Dec, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Dec, 20}; REQUIRE(expected == meetup.third_friday()); } -TEST_CASE("third_Saturday_of_January_2013") -{ +TEST_CASE("third_Saturday_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 19}; REQUIRE(expected == meetup.third_saturday()); } -TEST_CASE("third_Saturday_of_February_2013") -{ +TEST_CASE("third_Saturday_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 16}; REQUIRE(expected == meetup.third_saturday()); } -TEST_CASE("third_Sunday_of_March_2013") -{ +TEST_CASE("third_Sunday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 17}; REQUIRE(expected == meetup.third_sunday()); } -TEST_CASE("third_Sunday_of_April_2013") -{ +TEST_CASE("third_Sunday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 21}; REQUIRE(expected == meetup.third_sunday()); } -TEST_CASE("fourth_Monday_of_March_2013") -{ +TEST_CASE("fourth_Monday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 25}; REQUIRE(expected == meetup.fourth_monday()); } -TEST_CASE("fourth_Monday_of_April_2013") -{ +TEST_CASE("fourth_Monday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 22}; REQUIRE(expected == meetup.fourth_monday()); } -TEST_CASE("fourth_Tuesday_of_May_2013") -{ +TEST_CASE("fourth_Tuesday_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 28}; REQUIRE(expected == meetup.fourth_tuesday()); } -TEST_CASE("fourth_Tuesday_of_June_2013") -{ +TEST_CASE("fourth_Tuesday_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 25}; REQUIRE(expected == meetup.fourth_tuesday()); } -TEST_CASE("fourth_Wednesday_of_July_2013") -{ +TEST_CASE("fourth_Wednesday_of_July_2013") { const meetup::scheduler meetup{boost::gregorian::Jul, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jul, 24}; REQUIRE(expected == meetup.fourth_wednesday()); } -TEST_CASE("fourth_Wednesday_of_August_2013") -{ +TEST_CASE("fourth_Wednesday_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 28}; REQUIRE(expected == meetup.fourth_wednesday()); } -TEST_CASE("fourth_Thursday_of_September_2013") -{ +TEST_CASE("fourth_Thursday_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 26}; REQUIRE(expected == meetup.fourth_thursday()); } -TEST_CASE("fourth_Thursday_of_October_2013") -{ +TEST_CASE("fourth_Thursday_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 24}; REQUIRE(expected == meetup.fourth_thursday()); } -TEST_CASE("fourth_Friday_of_November_2013") -{ +TEST_CASE("fourth_Friday_of_November_2013") { const meetup::scheduler meetup{boost::gregorian::Nov, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Nov, 22}; REQUIRE(expected == meetup.fourth_friday()); } -TEST_CASE("fourth_Friday_of_December_2013") -{ +TEST_CASE("fourth_Friday_of_December_2013") { const meetup::scheduler meetup{boost::gregorian::Dec, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Dec, 27}; REQUIRE(expected == meetup.fourth_friday()); } -TEST_CASE("fourth_Saturday_of_January_2013") -{ +TEST_CASE("fourth_Saturday_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 26}; REQUIRE(expected == meetup.fourth_saturday()); } -TEST_CASE("fourth_Saturday_of_February_2013") -{ +TEST_CASE("fourth_Saturday_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 23}; REQUIRE(expected == meetup.fourth_saturday()); } -TEST_CASE("fourth_Sunday_of_March_2013") -{ +TEST_CASE("fourth_Sunday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 24}; REQUIRE(expected == meetup.fourth_sunday()); } -TEST_CASE("fourth_Sunday_of_April_2013") -{ +TEST_CASE("fourth_Sunday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 28}; REQUIRE(expected == meetup.fourth_sunday()); } -TEST_CASE("last_Monday_of_March_2013") -{ +TEST_CASE("last_Monday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 25}; REQUIRE(expected == meetup.last_monday()); } -TEST_CASE("last_Monday_of_April_2013") -{ +TEST_CASE("last_Monday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 29}; REQUIRE(expected == meetup.last_monday()); } -TEST_CASE("last_Tuesday_of_May_2013") -{ +TEST_CASE("last_Tuesday_of_May_2013") { const meetup::scheduler meetup{boost::gregorian::May, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::May, 28}; REQUIRE(expected == meetup.last_tuesday()); } -TEST_CASE("last_Tuesday_of_June_2013") -{ +TEST_CASE("last_Tuesday_of_June_2013") { const meetup::scheduler meetup{boost::gregorian::Jun, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jun, 25}; REQUIRE(expected == meetup.last_tuesday()); } -TEST_CASE("last_Wednesday_of_July_2013") -{ +TEST_CASE("last_Wednesday_of_July_2013") { const meetup::scheduler meetup{boost::gregorian::Jul, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jul, 31}; REQUIRE(expected == meetup.last_wednesday()); } -TEST_CASE("last_Wednesday_of_August_2013") -{ +TEST_CASE("last_Wednesday_of_August_2013") { const meetup::scheduler meetup{boost::gregorian::Aug, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Aug, 28}; REQUIRE(expected == meetup.last_wednesday()); } -TEST_CASE("last_Thursday_of_September_2013") -{ +TEST_CASE("last_Thursday_of_September_2013") { const meetup::scheduler meetup{boost::gregorian::Sep, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Sep, 26}; REQUIRE(expected == meetup.last_thursday()); } -TEST_CASE("last_Thursday_of_October_2013") -{ +TEST_CASE("last_Thursday_of_October_2013") { const meetup::scheduler meetup{boost::gregorian::Oct, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Oct, 31}; REQUIRE(expected == meetup.last_thursday()); } -TEST_CASE("last_Friday_of_November_2013") -{ +TEST_CASE("last_Friday_of_November_2013") { const meetup::scheduler meetup{boost::gregorian::Nov, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Nov, 29}; REQUIRE(expected == meetup.last_friday()); } -TEST_CASE("last_Friday_of_December_2013") -{ +TEST_CASE("last_Friday_of_December_2013") { const meetup::scheduler meetup{boost::gregorian::Dec, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Dec, 27}; REQUIRE(expected == meetup.last_friday()); } -TEST_CASE("last_Saturday_of_January_2013") -{ +TEST_CASE("last_Saturday_of_January_2013") { const meetup::scheduler meetup{boost::gregorian::Jan, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Jan, 26}; REQUIRE(expected == meetup.last_saturday()); } -TEST_CASE("last_Saturday_of_February_2013") -{ +TEST_CASE("last_Saturday_of_February_2013") { const meetup::scheduler meetup{boost::gregorian::Feb, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Feb, 23}; REQUIRE(expected == meetup.last_saturday()); } -TEST_CASE("last_Sunday_of_March_2013") -{ +TEST_CASE("last_Sunday_of_March_2013") { const meetup::scheduler meetup{boost::gregorian::Mar, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Mar, 31}; REQUIRE(expected == meetup.last_sunday()); } -TEST_CASE("last_Sunday_of_April_2013") -{ +TEST_CASE("last_Sunday_of_April_2013") { const meetup::scheduler meetup{boost::gregorian::Apr, 2013}; const boost::gregorian::date expected{2013, boost::gregorian::Apr, 28}; diff --git a/exercises/practice/minesweeper/.meta/example.cpp b/exercises/practice/minesweeper/.meta/example.cpp index 5152d4404..74003dc31 100644 --- a/exercises/practice/minesweeper/.meta/example.cpp +++ b/exercises/practice/minesweeper/.meta/example.cpp @@ -1,42 +1,54 @@ #include "minesweeper.h" namespace minesweeper { - int score(const std::vector& minefield, size_t row, size_t column) { - int mines{}; - // north - if(row > 0 && minefield.at(row - 1).at(column) == '*') ++mines; - // north-east - if(row > 0 && column < minefield.at(0).size() - 1 && minefield.at(row - 1).at(column + 1) == '*') ++mines; - // north-west - if(row > 0 && column > 0 && minefield.at(row - 1).at(column - 1) == '*') ++mines; - // east - if(column < minefield.at(0).size() - 1 && minefield.at(row).at(column + 1) == '*') ++mines; - // west - if(column > 0 && minefield.at(row).at(column - 1) == '*') ++mines; - // south - if(row < minefield.size() - 1 && minefield.at(row + 1).at(column) == '*') ++mines; - // south-east - if(row < minefield.size() - 1 && column < minefield.at(0).size() - 1 && minefield.at(row + 1).at(column + 1) == '*') ++mines; - // south-west - if(row < minefield.size() - 1 && column > 0 && minefield.at(row + 1).at(column - 1) == '*') ++mines; - return mines; - } +int score(const std::vector& minefield, size_t row, + size_t column) { + int mines{}; + // north + if (row > 0 && minefield.at(row - 1).at(column) == '*') ++mines; + // north-east + if (row > 0 && column < minefield.at(0).size() - 1 && + minefield.at(row - 1).at(column + 1) == '*') + ++mines; + // north-west + if (row > 0 && column > 0 && minefield.at(row - 1).at(column - 1) == '*') + ++mines; + // east + if (column < minefield.at(0).size() - 1 && + minefield.at(row).at(column + 1) == '*') + ++mines; + // west + if (column > 0 && minefield.at(row).at(column - 1) == '*') ++mines; + // south + if (row < minefield.size() - 1 && minefield.at(row + 1).at(column) == '*') + ++mines; + // south-east + if (row < minefield.size() - 1 && column < minefield.at(0).size() - 1 && + minefield.at(row + 1).at(column + 1) == '*') + ++mines; + // south-west + if (row < minefield.size() - 1 && column > 0 && + minefield.at(row + 1).at(column - 1) == '*') + ++mines; + return mines; +} - std::vector annotate(const std::vector& minefield) { - std::vector annotation{}; - for(size_t row{}; row < minefield.size(); ++row) { - std::string annotaded_line{}; - for(size_t column{}; column < minefield.at(0).size(); ++column) { - if (minefield.at(row).at(column) == '*') { - annotaded_line += '*'; - } else { - int score_number = score(minefield, row, column); - char score_char = (score_number == 0) ? ' ' : char(score_number) + '0'; - annotaded_line += score_char; - } +std::vector annotate(const std::vector& minefield) { + std::vector annotation{}; + for (size_t row{}; row < minefield.size(); ++row) { + std::string annotaded_line{}; + for (size_t column{}; column < minefield.at(0).size(); ++column) { + if (minefield.at(row).at(column) == '*') { + annotaded_line += '*'; + } else { + int score_number = score(minefield, row, column); + char score_char = + (score_number == 0) ? ' ' : char(score_number) + '0'; + annotaded_line += score_char; } - annotation.emplace_back(annotaded_line); } - return annotation; + annotation.emplace_back(annotaded_line); } + return annotation; +} } // namespace minesweeper diff --git a/exercises/practice/minesweeper/.meta/example.h b/exercises/practice/minesweeper/.meta/example.h index 76ece7a39..e95d93934 100644 --- a/exercises/practice/minesweeper/.meta/example.h +++ b/exercises/practice/minesweeper/.meta/example.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include namespace minesweeper { - std::vector annotate(const std::vector& minefield); +std::vector annotate(const std::vector& minefield); } // namespace minesweeper diff --git a/exercises/practice/minesweeper/minesweeper.cpp b/exercises/practice/minesweeper/minesweeper.cpp index 949afc15b..95e3a2565 100644 --- a/exercises/practice/minesweeper/minesweeper.cpp +++ b/exercises/practice/minesweeper/minesweeper.cpp @@ -1,5 +1,3 @@ #include "minesweeper.h" -namespace minesweeper { - -} // namespace minesweeper +namespace minesweeper {} // namespace minesweeper diff --git a/exercises/practice/minesweeper/minesweeper.h b/exercises/practice/minesweeper/minesweeper.h index 4d7a0b817..4fcad977d 100644 --- a/exercises/practice/minesweeper/minesweeper.h +++ b/exercises/practice/minesweeper/minesweeper.h @@ -1,5 +1,3 @@ #pragma once -namespace minesweeper { - -} // namespace minesweeper +namespace minesweeper {} // namespace minesweeper diff --git a/exercises/practice/minesweeper/minesweeper_test.cpp b/exercises/practice/minesweeper/minesweeper_test.cpp index 9cae6e06d..93bcbd70c 100644 --- a/exercises/practice/minesweeper/minesweeper_test.cpp +++ b/exercises/practice/minesweeper/minesweeper_test.cpp @@ -6,72 +6,81 @@ #endif /* - The expected outputs are represented as arrays of strings to - improve readability in this JSON file. - Your track may choose whether to present the input as a single - string (concatenating all the lines) or as the list. + The expected outputs are represented as arrays of strings to + improve readability in this JSON file. + Your track may choose whether to present the input as a single + string (concatenating all the lines) or as the list. */ TEST_CASE("no rows", "[0c5ec4bd-dea7-4138-8651-1203e1cb9f44]") { - const std::vector expected{}; - REQUIRE(expected == minesweeper::annotate({})); + const std::vector expected{}; + REQUIRE(expected == minesweeper::annotate({})); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("no columns", "[650ac4c0-ad6b-4b41-acde-e4ea5852c3b8]") { - const std::vector expected{""}; - REQUIRE(expected == minesweeper::annotate({""})); + const std::vector expected{""}; + REQUIRE(expected == minesweeper::annotate({""})); } TEST_CASE("no mines", "[6fbf8f6d-a03b-42c9-9a58-b489e9235478]") { - const std::vector expected{" ", " ", " "}; - REQUIRE(expected == minesweeper::annotate({" ", " ", " "})); + const std::vector expected{" ", " ", " "}; + REQUIRE(expected == minesweeper::annotate({" ", " ", " "})); } -TEST_CASE("minefield with only mines", "[61aff1c4-fb31-4078-acad-cd5f1e635655]") { - const std::vector expected{"***", "***", "***"}; - REQUIRE(expected == minesweeper::annotate({"***", "***", "***"})); +TEST_CASE("minefield with only mines", + "[61aff1c4-fb31-4078-acad-cd5f1e635655]") { + const std::vector expected{"***", "***", "***"}; + REQUIRE(expected == minesweeper::annotate({"***", "***", "***"})); } -TEST_CASE("mine surrounded by spaces", "[84167147-c504-4896-85d7-246b01dea7c5]") { - const std::vector expected{"111", "1*1", "111"}; - REQUIRE(expected == minesweeper::annotate({" ", " * ", " "})); +TEST_CASE("mine surrounded by spaces", + "[84167147-c504-4896-85d7-246b01dea7c5]") { + const std::vector expected{"111", "1*1", "111"}; + REQUIRE(expected == minesweeper::annotate({" ", " * ", " "})); } -TEST_CASE("space surrounded by mines", "[cb878f35-43e3-4c9d-93d9-139012cccc4a]") { - const std::vector expected{"***", "*8*", "***"}; - REQUIRE(expected == minesweeper::annotate({"***", "* *", "***"})); +TEST_CASE("space surrounded by mines", + "[cb878f35-43e3-4c9d-93d9-139012cccc4a]") { + const std::vector expected{"***", "*8*", "***"}; + REQUIRE(expected == minesweeper::annotate({"***", "* *", "***"})); } TEST_CASE("horizontal line", "[7037f483-ddb4-4b35-b005-0d0f4ef4606f]") { - const std::vector expected{"1*2*1"}; - REQUIRE(expected == minesweeper::annotate({" * * "})); + const std::vector expected{"1*2*1"}; + REQUIRE(expected == minesweeper::annotate({" * * "})); } -TEST_CASE("horizontal line, mines at edges", "[e359820f-bb8b-4eda-8762-47b64dba30a6]") { - const std::vector expected{"*1 1*"}; - REQUIRE(expected == minesweeper::annotate({"* *"})); +TEST_CASE("horizontal line, mines at edges", + "[e359820f-bb8b-4eda-8762-47b64dba30a6]") { + const std::vector expected{"*1 1*"}; + REQUIRE(expected == minesweeper::annotate({"* *"})); } TEST_CASE("vertical line", "[c5198b50-804f-47e9-ae02-c3b42f7ce3ab]") { - const std::vector expected{"1", "*", "2", "*", "1"}; - REQUIRE(expected == minesweeper::annotate({" ", "*", " ", "*", " "})); + const std::vector expected{"1", "*", "2", "*", "1"}; + REQUIRE(expected == minesweeper::annotate({" ", "*", " ", "*", " "})); } -TEST_CASE("vertical line, mines at edges", "[0c79a64d-703d-4660-9e90-5adfa5408939]") { - const std::vector expected{"*", "1", " ", "1", "*"}; - REQUIRE(expected == minesweeper::annotate({"*", " ", " ", " ", "*"})); +TEST_CASE("vertical line, mines at edges", + "[0c79a64d-703d-4660-9e90-5adfa5408939]") { + const std::vector expected{"*", "1", " ", "1", "*"}; + REQUIRE(expected == minesweeper::annotate({"*", " ", " ", " ", "*"})); } TEST_CASE("cross", "[4b098563-b7f3-401c-97c6-79dd1b708f34]") { - const std::vector expected{" 2*2 ", "25*52", "*****", "25*52", " 2*2 "}; - REQUIRE(expected == minesweeper::annotate({" * ", " * ", "*****", " * ", " * "})); + const std::vector expected{" 2*2 ", "25*52", "*****", "25*52", + " 2*2 "}; + REQUIRE(expected == minesweeper::annotate( + {" * ", " * ", "*****", " * ", " * "})); } TEST_CASE("large minefield", "[04a260f1-b40a-4e89-839e-8dd8525abe0e]") { - const std::vector expected{"1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111"}; - REQUIRE(expected == minesweeper::annotate({" * * ", " * ", " * ", " * *", " * * ", " "})); + const std::vector expected{"1*22*1", "12*322", " 123*2", + "112*4*", "1*22*2", "111111"}; + REQUIRE(expected == minesweeper::annotate({" * * ", " * ", " * ", + " * *", " * * ", " "})); } #endif diff --git a/exercises/practice/nth-prime/.meta/example.cpp b/exercises/practice/nth-prime/.meta/example.cpp index 5e4c6ab9e..a0d629636 100644 --- a/exercises/practice/nth-prime/.meta/example.cpp +++ b/exercises/practice/nth-prime/.meta/example.cpp @@ -1,11 +1,10 @@ -#include "nth_prime.h" #include #include -namespace -{ -bool is_prime(int n) -{ +#include "nth_prime.h" + +namespace { +bool is_prime(int n) { for (int probe = static_cast(std::sqrt(n)); probe > 1; --probe) { if (n % probe == 0) { return false; @@ -13,10 +12,9 @@ bool is_prime(int n) } return true; } -} +} // namespace -int nth_prime::nth(int n) -{ +int nth_prime::nth(int n) { if (n < 1) { throw std::domain_error("Out of range"); } diff --git a/exercises/practice/nth-prime/.meta/example.h b/exercises/practice/nth-prime/.meta/example.h index 291f4486f..98cf20f99 100644 --- a/exercises/practice/nth-prime/.meta/example.h +++ b/exercises/practice/nth-prime/.meta/example.h @@ -1,8 +1,7 @@ #if !defined(NTH_PRIME_H) #define NTH_PRIME_H -namespace nth_prime -{ +namespace nth_prime { int nth(int n); } diff --git a/exercises/practice/nth-prime/nth_prime.cpp b/exercises/practice/nth-prime/nth_prime.cpp index 00176d89d..bcc78cc87 100644 --- a/exercises/practice/nth-prime/nth_prime.cpp +++ b/exercises/practice/nth-prime/nth_prime.cpp @@ -1,5 +1,3 @@ #include "nth_prime.h" -namespace nth_prime { - -} // namespace nth_prime +namespace nth_prime {} // namespace nth_prime diff --git a/exercises/practice/nth-prime/nth_prime.h b/exercises/practice/nth-prime/nth_prime.h index d83b86dc6..434d605ff 100644 --- a/exercises/practice/nth-prime/nth_prime.h +++ b/exercises/practice/nth-prime/nth_prime.h @@ -1,8 +1,6 @@ #if !defined(NTH_PRIME_H) #define NTH_PRIME_H -namespace nth_prime { +namespace nth_prime {} // namespace nth_prime -} // namespace nth_prime - -#endif // NTH_PRIME_H \ No newline at end of file +#endif // NTH_PRIME_H \ No newline at end of file diff --git a/exercises/practice/nth-prime/nth_prime_test.cpp b/exercises/practice/nth-prime/nth_prime_test.cpp index 2f3a31eb6..c23e5d93c 100644 --- a/exercises/practice/nth-prime/nth_prime_test.cpp +++ b/exercises/practice/nth-prime/nth_prime_test.cpp @@ -6,29 +6,16 @@ #endif #include -TEST_CASE("first") -{ - REQUIRE(2 == nth_prime::nth(1)); -} +TEST_CASE("first") { REQUIRE(2 == nth_prime::nth(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("second") -{ - REQUIRE(3 == nth_prime::nth(2)); -} +TEST_CASE("second") { REQUIRE(3 == nth_prime::nth(2)); } -TEST_CASE("sixth") -{ - REQUIRE(13 == nth_prime::nth(6)); -} +TEST_CASE("sixth") { REQUIRE(13 == nth_prime::nth(6)); } -TEST_CASE("big_prime") -{ - REQUIRE(104743 == nth_prime::nth(10001)); -} +TEST_CASE("big_prime") { REQUIRE(104743 == nth_prime::nth(10001)); } -TEST_CASE("weird_case") -{ +TEST_CASE("weird_case") { REQUIRE_THROWS_AS(nth_prime::nth(0), std::domain_error); } #endif diff --git a/exercises/practice/nucleotide-count/.meta/example.cpp b/exercises/practice/nucleotide-count/.meta/example.cpp index acc69bda7..f061d52ff 100644 --- a/exercises/practice/nucleotide-count/.meta/example.cpp +++ b/exercises/practice/nucleotide-count/.meta/example.cpp @@ -1,11 +1,10 @@ -#include "nucleotide_count.h" #include -namespace nucleotide_count -{ +#include "nucleotide_count.h" + +namespace nucleotide_count { -std::map count(std::string_view dna) -{ +std::map count(std::string_view dna) { std::map counter{{'A', 0}, {'C', 0}, {'G', 0}, {'T', 0}}; for (auto nucleotide : dna) { auto it = counter.find(nucleotide); @@ -17,4 +16,4 @@ std::map count(std::string_view dna) return counter; } -} +} // namespace nucleotide_count diff --git a/exercises/practice/nucleotide-count/.meta/example.h b/exercises/practice/nucleotide-count/.meta/example.h index ac5cfd999..f40f94076 100644 --- a/exercises/practice/nucleotide-count/.meta/example.h +++ b/exercises/practice/nucleotide-count/.meta/example.h @@ -4,8 +4,7 @@ #include #include -namespace nucleotide_count -{ +namespace nucleotide_count { std::map count(std::string_view dna); diff --git a/exercises/practice/nucleotide-count/nucleotide_count.cpp b/exercises/practice/nucleotide-count/nucleotide_count.cpp index 88ec51285..441a8ab2b 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count.cpp @@ -1,5 +1,3 @@ #include "nucleotide_count.h" -namespace nucleotide_count { - -} // namespace nucleotide_count +namespace nucleotide_count {} // namespace nucleotide_count diff --git a/exercises/practice/nucleotide-count/nucleotide_count.h b/exercises/practice/nucleotide-count/nucleotide_count.h index 394067999..5a71e6b54 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count.h +++ b/exercises/practice/nucleotide-count/nucleotide_count.h @@ -1,8 +1,6 @@ #if !defined(NUCLEOTIDE_COUNT_H) #define NUCLEOTIDE_COUNT_H -namespace nucleotide_count { +namespace nucleotide_count {} // namespace nucleotide_count -} // namespace nucleotide_count - -#endif // NUCLEOTIDE_COUNT_H \ No newline at end of file +#endif // NUCLEOTIDE_COUNT_H \ No newline at end of file diff --git a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp index fc071258e..98ed583ee 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp @@ -7,9 +7,8 @@ #include #include -TEST_CASE("empty_strand") -{ - const std::map expected{ {'A', 0}, {'C', 0}, {'G', 0}, {'T', 0} }; +TEST_CASE("empty_strand") { + const std::map expected{{'A', 0}, {'C', 0}, {'G', 0}, {'T', 0}}; const auto actual = nucleotide_count::count(""); REQUIRE(expected == actual); @@ -17,32 +16,32 @@ TEST_CASE("empty_strand") #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("can_count_one_nucleotide_in_single_character_input") -{ - const std::map expected{ {'A', 0}, {'C', 0}, {'G', 1}, {'T', 0} }; +TEST_CASE("can_count_one_nucleotide_in_single_character_input") { + const std::map expected{{'A', 0}, {'C', 0}, {'G', 1}, {'T', 0}}; const auto actual = nucleotide_count::count("G"); REQUIRE(expected == actual); } -TEST_CASE("strand_with_repeated_nucleotide") -{ - const std::map expected{ {'A', 0}, {'C', 0}, {'G', 7}, {'T', 0} }; +TEST_CASE("strand_with_repeated_nucleotide") { + const std::map expected{{'A', 0}, {'C', 0}, {'G', 7}, {'T', 0}}; const auto actual = nucleotide_count::count("GGGGGGG"); REQUIRE(expected == actual); } -TEST_CASE("strand_with_multiple_nucleotides") -{ - const std::map expected{ {'A', 20}, {'C', 12}, {'G', 17}, {'T', 21} }; - const auto actual = nucleotide_count::count("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); +TEST_CASE("strand_with_multiple_nucleotides") { + const std::map expected{ + {'A', 20}, {'C', 12}, {'G', 17}, {'T', 21}}; + const auto actual = nucleotide_count::count( + "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAG" + "C"); REQUIRE(expected == actual); } -TEST_CASE("strand_with_invalid_nucleotides") -{ - REQUIRE_THROWS_AS(nucleotide_count::count("AGXXACT"), std::invalid_argument); +TEST_CASE("strand_with_invalid_nucleotides") { + REQUIRE_THROWS_AS(nucleotide_count::count("AGXXACT"), + std::invalid_argument); } #endif diff --git a/exercises/practice/pangram/.meta/example.cpp b/exercises/practice/pangram/.meta/example.cpp index d705f10f1..f64d11e84 100644 --- a/exercises/practice/pangram/.meta/example.cpp +++ b/exercises/practice/pangram/.meta/example.cpp @@ -1,35 +1,32 @@ -#include "pangram.h" #include -namespace -{ - -bool found_letter(char a, const std::string &s) -{ - for(auto c: s) { - if(tolower(c) ==a) { +#include "pangram.h" + +namespace { + +bool found_letter(char a, const std::string &s) { + for (auto c : s) { + if (tolower(c) == a) { return true; } } return false; } - -} -namespace pangram -{ - -bool is_pangram(const std::string &s) -{ - char letters[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; - for(char l : letters) - { - if(!found_letter(l, s)) - { +} // namespace + +namespace pangram { + +bool is_pangram(const std::string &s) { + char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', + 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; + for (char l : letters) { + if (!found_letter(l, s)) { return false; } } return true; } -} +} // namespace pangram diff --git a/exercises/practice/pangram/.meta/example.h b/exercises/practice/pangram/.meta/example.h index e173321e3..f3908f0c7 100644 --- a/exercises/practice/pangram/.meta/example.h +++ b/exercises/practice/pangram/.meta/example.h @@ -2,9 +2,8 @@ #define PANGRAM_H #include -namespace pangram -{ - +namespace pangram { + bool is_pangram(const std::string &s); } diff --git a/exercises/practice/pangram/pangram.cpp b/exercises/practice/pangram/pangram.cpp index 76a6bf9ca..3f3fcf30f 100644 --- a/exercises/practice/pangram/pangram.cpp +++ b/exercises/practice/pangram/pangram.cpp @@ -1,5 +1,3 @@ #include "pangram.h" -namespace pangram { - -} // namespace pangram +namespace pangram {} // namespace pangram diff --git a/exercises/practice/pangram/pangram.h b/exercises/practice/pangram/pangram.h index 8f06fd284..46a3535de 100644 --- a/exercises/practice/pangram/pangram.h +++ b/exercises/practice/pangram/pangram.h @@ -1,8 +1,6 @@ #if !defined(PANGRAM_H) #define PANGRAM_H -namespace pangram { +namespace pangram {} // namespace pangram -} // namespace pangram - -#endif // PANGRAM_H \ No newline at end of file +#endif // PANGRAM_H \ No newline at end of file diff --git a/exercises/practice/pangram/pangram_test.cpp b/exercises/practice/pangram/pangram_test.cpp index 703352622..cdb385737 100644 --- a/exercises/practice/pangram/pangram_test.cpp +++ b/exercises/practice/pangram/pangram_test.cpp @@ -5,49 +5,42 @@ #include "test/catch.hpp" #endif -TEST_CASE("sentence_empty") -{ - REQUIRE(!pangram::is_pangram("")); -} +TEST_CASE("sentence_empty") { REQUIRE(!pangram::is_pangram("")); } #ifdef EXERCISM_RUN_ALL_TESTS -TEST_CASE("pangram_with_only_lower_case") -{ +TEST_CASE("pangram_with_only_lower_case") { REQUIRE(pangram::is_pangram("the quick brown fox jumps over the lazy dog")); } -TEST_CASE("missing_character_x") -{ - REQUIRE(!pangram::is_pangram("a quick movement of the enemy will jeopardize five gunboats")); +TEST_CASE("missing_character_x") { + REQUIRE(!pangram::is_pangram( + "a quick movement of the enemy will jeopardize five gunboats")); } -TEST_CASE("another_missing_x") -{ - REQUIRE(!pangram::is_pangram("the quick brown fish jumps over the lazy dog")); +TEST_CASE("another_missing_x") { + REQUIRE( + !pangram::is_pangram("the quick brown fish jumps over the lazy dog")); } -TEST_CASE("pangram_with_underscores") -{ +TEST_CASE("pangram_with_underscores") { REQUIRE(pangram::is_pangram("the_quick_brown_fox_jumps_over_the_lazy_dog")); } -TEST_CASE("pangram_with_numbers") -{ - REQUIRE(pangram::is_pangram("the 1 quick brown fox jumps over the 2 lazy dogs")); +TEST_CASE("pangram_with_numbers") { + REQUIRE(pangram::is_pangram( + "the 1 quick brown fox jumps over the 2 lazy dogs")); } -TEST_CASE("missing_letters_replaced_with_numbers") -{ - REQUIRE(!pangram::is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")); +TEST_CASE("missing_letters_replaced_with_numbers") { + REQUIRE( + !pangram::is_pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")); } -TEST_CASE("pangram_with_mixed_case_and_punctuation") -{ +TEST_CASE("pangram_with_mixed_case_and_punctuation") { REQUIRE(pangram::is_pangram("\"Five quacking Zephyrs jolt my wax bed.\"")); } -TEST_CASE("a_to_m_and_A_to_M_are_26_different_characters_but_not_a_pangram") -{ +TEST_CASE("a_to_m_and_A_to_M_are_26_different_characters_but_not_a_pangram") { REQUIRE(!pangram::is_pangram("abcdefghijklm ABCDEFGHIJKLM")); } #endif diff --git a/exercises/practice/parallel-letter-frequency/.meta/example.cpp b/exercises/practice/parallel-letter-frequency/.meta/example.cpp index 16a2b11f2..1ea5115f2 100644 --- a/exercises/practice/parallel-letter-frequency/.meta/example.cpp +++ b/exercises/practice/parallel-letter-frequency/.meta/example.cpp @@ -1,8 +1,8 @@ -#include "parallel_letter_frequency.h" - #include #include +#include "parallel_letter_frequency.h" + // Apple Clang does not support C++17 parallel algorithms. #ifdef __apple_build_version__ #define PAR_UNSEQ diff --git a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.cpp b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.cpp index 464be298d..dfa68661e 100644 --- a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.cpp +++ b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.cpp @@ -1,5 +1,3 @@ #include "parallel_letter_frequency.h" -namespace parallel_letter_frequency { - -} +namespace parallel_letter_frequency {} diff --git a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.h b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.h index f2c414235..2cd676294 100644 --- a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.h +++ b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.h @@ -1,9 +1,6 @@ #if !defined(PARALLEL_LETTER_FREQUENCY_H) #define PARALLEL_LETTER_FREQUENCY_H -namespace parallel_letter_frequency { - -} +namespace parallel_letter_frequency {} #endif - diff --git a/exercises/practice/pascals-triangle/.meta/example.cpp b/exercises/practice/pascals-triangle/.meta/example.cpp index 27591b454..2068a66c6 100644 --- a/exercises/practice/pascals-triangle/.meta/example.cpp +++ b/exercises/practice/pascals-triangle/.meta/example.cpp @@ -1,20 +1,15 @@ #include "pascals_triangle.h" -namespace pascals_triangle -{ +namespace pascals_triangle { -std::vector> generate_rows(size_t n) -{ +std::vector> generate_rows(size_t n) { std::vector> res; - for (size_t i = 0; i < n; i++) - { - + for (size_t i = 0; i < n; i++) { std::vector rowNum; int val = 1; - for (size_t k = 0; k <= i; k++) - { + for (size_t k = 0; k <= i; k++) { rowNum.push_back(val); val = val * (i - k) / (k + 1); } @@ -25,4 +20,4 @@ std::vector> generate_rows(size_t n) return res; } -} +} // namespace pascals_triangle diff --git a/exercises/practice/pascals-triangle/.meta/example.h b/exercises/practice/pascals-triangle/.meta/example.h index 202966eee..a2a60201b 100644 --- a/exercises/practice/pascals-triangle/.meta/example.h +++ b/exercises/practice/pascals-triangle/.meta/example.h @@ -1,16 +1,15 @@ #if !defined(PASCALS_TRIANGLE_H) #define PASCALS_TRIANGLE_H -#include #include +#include -namespace pascals_triangle -{ +namespace pascals_triangle { using std::size_t; std::vector> generate_rows(size_t n); -} +} // namespace pascals_triangle #endif diff --git a/exercises/practice/pascals-triangle/pascals_triangle.cpp b/exercises/practice/pascals-triangle/pascals_triangle.cpp index 39c084194..cae9c269f 100644 --- a/exercises/practice/pascals-triangle/pascals_triangle.cpp +++ b/exercises/practice/pascals-triangle/pascals_triangle.cpp @@ -1,5 +1,3 @@ #include "pascals_triangle.h" -namespace pascals_triangle { - -} // namespace pascals_triangle +namespace pascals_triangle {} // namespace pascals_triangle diff --git a/exercises/practice/pascals-triangle/pascals_triangle.h b/exercises/practice/pascals-triangle/pascals_triangle.h index c3efca3d6..80d4796ea 100644 --- a/exercises/practice/pascals-triangle/pascals_triangle.h +++ b/exercises/practice/pascals-triangle/pascals_triangle.h @@ -1,8 +1,6 @@ #if !defined(PASCALS_TRIANGLE_H) #define PASCALS_TRIANGLE_H -namespace pascals_triangle { +namespace pascals_triangle {} // namespace pascals_triangle -} // namespace pascals_triangle - -#endif // PASCALS_TRIANGLE_H \ No newline at end of file +#endif // PASCALS_TRIANGLE_H \ No newline at end of file diff --git a/exercises/practice/pascals-triangle/pascals_triangle_test.cpp b/exercises/practice/pascals-triangle/pascals_triangle_test.cpp index 5e36edf0b..602745b10 100644 --- a/exercises/practice/pascals-triangle/pascals_triangle_test.cpp +++ b/exercises/practice/pascals-triangle/pascals_triangle_test.cpp @@ -5,113 +5,89 @@ #include "test/catch.hpp" #endif -TEST_CASE("zero_rows") -{ +TEST_CASE("zero_rows") { const std::vector> expected; - const std::vector> actual{pascals_triangle::generate_rows(0)}; + const std::vector> actual{ + pascals_triangle::generate_rows(0)}; REQUIRE(expected == actual); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("single_row") -{ - const std::vector> expected{ - {1} - }; +TEST_CASE("single_row") { + const std::vector> expected{{1}}; - const std::vector> actual{pascals_triangle::generate_rows(1)}; + const std::vector> actual{ + pascals_triangle::generate_rows(1)}; REQUIRE(expected == actual); } -TEST_CASE("two_rows") -{ - const std::vector> expected{ - {1}, - {1, 1} - }; +TEST_CASE("two_rows") { + const std::vector> expected{{1}, {1, 1}}; - const std::vector> actual{pascals_triangle::generate_rows(2)}; + const std::vector> actual{ + pascals_triangle::generate_rows(2)}; REQUIRE(expected == actual); } -TEST_CASE("three_rows") -{ - const std::vector> expected{ - {1}, - {1, 1}, - {1, 2, 1} - }; +TEST_CASE("three_rows") { + const std::vector> expected{{1}, {1, 1}, {1, 2, 1}}; - const std::vector> actual{pascals_triangle::generate_rows(3)}; + const std::vector> actual{ + pascals_triangle::generate_rows(3)}; REQUIRE(expected == actual); } -TEST_CASE("four_rows") -{ +TEST_CASE("four_rows") { const std::vector> expected{ - {1}, - {1, 1}, - {1, 2, 1}, - {1, 3, 3, 1} - }; + {1}, {1, 1}, {1, 2, 1}, {1, 3, 3, 1}}; - const std::vector> actual{pascals_triangle::generate_rows(4)}; + const std::vector> actual{ + pascals_triangle::generate_rows(4)}; REQUIRE(expected == actual); } -TEST_CASE("five_rows") -{ +TEST_CASE("five_rows") { const std::vector> expected{ - {1}, - {1, 1}, - {1, 2, 1}, - {1, 3, 3, 1}, - {1, 4, 6, 4, 1} - }; + {1}, {1, 1}, {1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 4, 1}}; - const std::vector> actual{pascals_triangle::generate_rows(5)}; + const std::vector> actual{ + pascals_triangle::generate_rows(5)}; REQUIRE(expected == actual); } -TEST_CASE("six_rows") -{ +TEST_CASE("six_rows") { const std::vector> expected{ - {1}, - {1, 1}, - {1, 2, 1}, - {1, 3, 3, 1}, - {1, 4, 6, 4, 1}, - {1, 5, 10, 10, 5, 1} - }; + {1}, {1, 1}, {1, 2, 1}, + {1, 3, 3, 1}, {1, 4, 6, 4, 1}, {1, 5, 10, 10, 5, 1}}; - const std::vector> actual{pascals_triangle::generate_rows(6)}; + const std::vector> actual{ + pascals_triangle::generate_rows(6)}; REQUIRE(expected == actual); } -TEST_CASE("ten_rows") -{ +TEST_CASE("ten_rows") { const std::vector> expected{ - {1}, - {1, 1}, - {1, 2, 1}, - {1, 3, 3, 1}, - {1, 4, 6, 4, 1}, - {1, 5, 10, 10, 5, 1}, - {1, 6, 15, 20, 15, 6, 1}, - {1, 7, 21, 35, 35, 21, 7, 1}, - {1, 8, 28, 56, 70, 56, 28, 8, 1}, - {1, 9, 36, 84, 126, 126, 84, 36, 9, 1} - }; - - const std::vector> actual{pascals_triangle::generate_rows(10)}; + {1}, + {1, 1}, + {1, 2, 1}, + {1, 3, 3, 1}, + {1, 4, 6, 4, 1}, + {1, 5, 10, 10, 5, 1}, + {1, 6, 15, 20, 15, 6, 1}, + {1, 7, 21, 35, 35, 21, 7, 1}, + {1, 8, 28, 56, 70, 56, 28, 8, 1}, + {1, 9, 36, 84, 126, 126, 84, 36, 9, 1}}; + + const std::vector> actual{ + pascals_triangle::generate_rows(10)}; REQUIRE(expected == actual); } diff --git a/exercises/practice/perfect-numbers/perfect_numbers_test.cpp b/exercises/practice/perfect-numbers/perfect_numbers_test.cpp index 1b8af5ea6..b7984b36e 100644 --- a/exercises/practice/perfect-numbers/perfect_numbers_test.cpp +++ b/exercises/practice/perfect-numbers/perfect_numbers_test.cpp @@ -7,62 +7,86 @@ // improves error messages with enum text instead of integers: CATCH_REGISTER_ENUM(perfect_numbers::classification, - perfect_numbers::classification::perfect, - perfect_numbers::classification::abundant, - perfect_numbers::classification::deficient) - -TEST_CASE("Smallest perfect number is classified correctly", "[163e8e86-7bfd-4ee2-bd68-d083dc3381a3]") { - REQUIRE(perfect_numbers::classification::perfect == perfect_numbers::classify(6)); + perfect_numbers::classification::perfect, + perfect_numbers::classification::abundant, + perfect_numbers::classification::deficient) + +TEST_CASE("Smallest perfect number is classified correctly", + "[163e8e86-7bfd-4ee2-bd68-d083dc3381a3]") { + REQUIRE(perfect_numbers::classification::perfect == + perfect_numbers::classify(6)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Medium perfect number is classified correctly", "[169a7854-0431-4ae0-9815-c3b6d967436d]") { - REQUIRE(perfect_numbers::classification::perfect == perfect_numbers::classify(28)); +TEST_CASE("Medium perfect number is classified correctly", + "[169a7854-0431-4ae0-9815-c3b6d967436d]") { + REQUIRE(perfect_numbers::classification::perfect == + perfect_numbers::classify(28)); } -TEST_CASE("Large perfect number is classified correctly", "[ee3627c4-7b36-4245-ba7c-8727d585f402]") { - REQUIRE(perfect_numbers::classification::perfect == perfect_numbers::classify(33550336)); +TEST_CASE("Large perfect number is classified correctly", + "[ee3627c4-7b36-4245-ba7c-8727d585f402]") { + REQUIRE(perfect_numbers::classification::perfect == + perfect_numbers::classify(33550336)); } -TEST_CASE("Smallest abundant number is classified correctly", "[80ef7cf8-9ea8-49b9-8b2d-d9cb3db3ed7e]") { - REQUIRE(perfect_numbers::classification::abundant == perfect_numbers::classify(12)); +TEST_CASE("Smallest abundant number is classified correctly", + "[80ef7cf8-9ea8-49b9-8b2d-d9cb3db3ed7e]") { + REQUIRE(perfect_numbers::classification::abundant == + perfect_numbers::classify(12)); } -TEST_CASE("Medium abundant number is classified correctly", "[3e300e0d-1a12-4f11-8c48-d1027165ab60]") { - REQUIRE(perfect_numbers::classification::abundant == perfect_numbers::classify(30)); +TEST_CASE("Medium abundant number is classified correctly", + "[3e300e0d-1a12-4f11-8c48-d1027165ab60]") { + REQUIRE(perfect_numbers::classification::abundant == + perfect_numbers::classify(30)); } -TEST_CASE("Large abundant number is classified correctly", "[ec7792e6-8786-449c-b005-ce6dd89a772b]") { - REQUIRE(perfect_numbers::classification::abundant == perfect_numbers::classify(33550335)); +TEST_CASE("Large abundant number is classified correctly", + "[ec7792e6-8786-449c-b005-ce6dd89a772b]") { + REQUIRE(perfect_numbers::classification::abundant == + perfect_numbers::classify(33550335)); } -TEST_CASE("Smallest prime deficient number is classified correctly", "[e610fdc7-2b6e-43c3-a51c-b70fb37413ba]") { - REQUIRE(perfect_numbers::classification::deficient == perfect_numbers::classify(2)); +TEST_CASE("Smallest prime deficient number is classified correctly", + "[e610fdc7-2b6e-43c3-a51c-b70fb37413ba]") { + REQUIRE(perfect_numbers::classification::deficient == + perfect_numbers::classify(2)); } -TEST_CASE("Smallest non-prime deficient number is classified correctly", "[0beb7f66-753a-443f-8075-ad7fbd9018f3]") { - REQUIRE(perfect_numbers::classification::deficient == perfect_numbers::classify(4)); +TEST_CASE("Smallest non-prime deficient number is classified correctly", + "[0beb7f66-753a-443f-8075-ad7fbd9018f3]") { + REQUIRE(perfect_numbers::classification::deficient == + perfect_numbers::classify(4)); } -TEST_CASE("Medium deficient number is classified correctly", "[1c802e45-b4c6-4962-93d7-1cad245821ef]") { - REQUIRE(perfect_numbers::classification::deficient == perfect_numbers::classify(32)); +TEST_CASE("Medium deficient number is classified correctly", + "[1c802e45-b4c6-4962-93d7-1cad245821ef]") { + REQUIRE(perfect_numbers::classification::deficient == + perfect_numbers::classify(32)); } -TEST_CASE("Large deficient number is classified correctly", "[47dd569f-9e5a-4a11-9a47-a4e91c8c28aa]") { - REQUIRE(perfect_numbers::classification::deficient == perfect_numbers::classify(33550337)); +TEST_CASE("Large deficient number is classified correctly", + "[47dd569f-9e5a-4a11-9a47-a4e91c8c28aa]") { + REQUIRE(perfect_numbers::classification::deficient == + perfect_numbers::classify(33550337)); } -TEST_CASE("Edge case (no factors other than itself) is classified correctly", "[a696dec8-6147-4d68-afad-d38de5476a56]") { - REQUIRE(perfect_numbers::classification::deficient == perfect_numbers::classify(1)); +TEST_CASE("Edge case (no factors other than itself) is classified correctly", + "[a696dec8-6147-4d68-afad-d38de5476a56]") { + REQUIRE(perfect_numbers::classification::deficient == + perfect_numbers::classify(1)); } -TEST_CASE("Zero is rejected (as it is not a positive integer)", "[72445cee-660c-4d75-8506-6c40089dc302]") { - REQUIRE_THROWS_AS(perfect_numbers::classify(0),std::domain_error); +TEST_CASE("Zero is rejected (as it is not a positive integer)", + "[72445cee-660c-4d75-8506-6c40089dc302]") { + REQUIRE_THROWS_AS(perfect_numbers::classify(0), std::domain_error); } -TEST_CASE("Negative integer is rejected (as it is not a positive integer)", "[2d72ce2c-6802-49ac-8ece-c790ba3dae13]") { - REQUIRE_THROWS_AS(perfect_numbers::classify(-1),std::domain_error); +TEST_CASE("Negative integer is rejected (as it is not a positive integer)", + "[2d72ce2c-6802-49ac-8ece-c790ba3dae13]") { + REQUIRE_THROWS_AS(perfect_numbers::classify(-1), std::domain_error); } #endif diff --git a/exercises/practice/phone-number/phone_number.cpp b/exercises/practice/phone-number/phone_number.cpp index bf7dd6d5a..e7a52af2d 100644 --- a/exercises/practice/phone-number/phone_number.cpp +++ b/exercises/practice/phone-number/phone_number.cpp @@ -1,5 +1,3 @@ #include "phone_number.h" -namespace phone_number { - -} // namespace phone_number +namespace phone_number {} // namespace phone_number diff --git a/exercises/practice/phone-number/phone_number.h b/exercises/practice/phone-number/phone_number.h index 1f25cdd14..f660ebaad 100644 --- a/exercises/practice/phone-number/phone_number.h +++ b/exercises/practice/phone-number/phone_number.h @@ -1,8 +1,6 @@ #if !defined(PHONE_NUMBER_H) #define PHONE_NUMBER_H -namespace phone_number { +namespace phone_number {} // namespace phone_number -} // namespace phone_number - -#endif // PHONE_NUMBER_H \ No newline at end of file +#endif // PHONE_NUMBER_H \ No newline at end of file diff --git a/exercises/practice/phone-number/phone_number_test.cpp b/exercises/practice/phone-number/phone_number_test.cpp index 04d042098..5a5e69f70 100644 --- a/exercises/practice/phone-number/phone_number_test.cpp +++ b/exercises/practice/phone-number/phone_number_test.cpp @@ -8,91 +8,104 @@ #include TEST_CASE("cleans_the_number") { - REQUIRE("2234567890" == phone_number::phone_number("(223) 456-7890").number()); + REQUIRE("2234567890" == + phone_number::phone_number("(223) 456-7890").number()); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("cleans_numbers_with_dots") { - REQUIRE("2234567890" == phone_number::phone_number("223.456.7890").number()); + REQUIRE("2234567890" == + phone_number::phone_number("223.456.7890").number()); } TEST_CASE("cleans_numbers_with_spaces") { - REQUIRE("2234567890" == phone_number::phone_number("223 456 7890 ").number()); + REQUIRE("2234567890" == + phone_number::phone_number("223 456 7890 ").number()); } TEST_CASE("has_an_area_code") { - REQUIRE("223" == phone_number::phone_number("+1 (223) 456-7890").area_code()); + REQUIRE("223" == + phone_number::phone_number("+1 (223) 456-7890").area_code()); } TEST_CASE("formats_a_number") { - const phone_number::phone_number phone("+1 (223) 456-7890"); - REQUIRE("(223) 456-7890" == std::string(phone)); + const phone_number::phone_number phone("+1 (223) 456-7890"); + REQUIRE("(223) 456-7890" == std::string(phone)); } TEST_CASE("invalid_when_9_digits") { - REQUIRE_THROWS_AS(phone_number::phone_number("123456789"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("123456789"), + std::domain_error); } TEST_CASE("invalid_when_11_digits_does_not_start_with_a_1") { - REQUIRE_THROWS_AS(phone_number::phone_number("22234567890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("22234567890"), + std::domain_error); } TEST_CASE("valid_when_11_digits_and_starting_with_1") { - REQUIRE("2234567890" == phone_number::phone_number("12234567890").number()); + REQUIRE("2234567890" == phone_number::phone_number("12234567890").number()); } -TEST_CASE( - "valid_when_11_digits_and_starting_with_1_even_with_punctuation") { - REQUIRE("2234567890" == phone_number::phone_number("+1 (223) 456-7890").number()); +TEST_CASE("valid_when_11_digits_and_starting_with_1_even_with_punctuation") { + REQUIRE("2234567890" == + phone_number::phone_number("+1 (223) 456-7890").number()); } TEST_CASE("invalid_when_more_than_11_digits") { - REQUIRE_THROWS_AS(phone_number::phone_number("321234567890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("321234567890"), + std::domain_error); } TEST_CASE("invalid_with_letters") { - REQUIRE_THROWS_AS(phone_number::phone_number("123-abc-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("123-abc-7890"), + std::domain_error); } TEST_CASE("invalid_with_punctuation") { - REQUIRE_THROWS_AS(phone_number::phone_number("123-@:!-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("123-@:!-7890"), + std::domain_error); } TEST_CASE("invalid_if_area_code_starts_with_0") { - REQUIRE_THROWS_AS(phone_number::phone_number("(023) 456-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("(023) 456-7890"), + std::domain_error); } TEST_CASE("invalid_if_area_code_starts_with_1") { - REQUIRE_THROWS_AS(phone_number::phone_number("(123) 456-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("(123) 456-7890"), + std::domain_error); } TEST_CASE("invalid_if_exchange_code_starts_with_0") { - REQUIRE_THROWS_AS(phone_number::phone_number("(223) 056-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("(223) 056-7890"), + std::domain_error); } TEST_CASE("invalid_if_exchange_code_starts_with_1") { - REQUIRE_THROWS_AS(phone_number::phone_number("(223) 156-7890"), std::domain_error); + REQUIRE_THROWS_AS(phone_number::phone_number("(223) 156-7890"), + std::domain_error); } -TEST_CASE( - "invalid_if_area_code_starts_with_0_on_valid_11_digit_number") { - REQUIRE_THROWS_AS(phone_number::phone_number("1 (023) 456-7890"), std::domain_error); +TEST_CASE("invalid_if_area_code_starts_with_0_on_valid_11_digit_number") { + REQUIRE_THROWS_AS(phone_number::phone_number("1 (023) 456-7890"), + std::domain_error); } -TEST_CASE( - "invalid_if_area_code_starts_with_1_on_valid_11_digit_number") { - REQUIRE_THROWS_AS(phone_number::phone_number("1 (123) 456-7890"), std::domain_error); +TEST_CASE("invalid_if_area_code_starts_with_1_on_valid_11_digit_number") { + REQUIRE_THROWS_AS(phone_number::phone_number("1 (123) 456-7890"), + std::domain_error); } -TEST_CASE( - "invalid_if_exchange_code_starts_with_0_on_valid_11_digit_number") { - REQUIRE_THROWS_AS(phone_number::phone_number("1 (223) 056-7890"), std::domain_error); +TEST_CASE("invalid_if_exchange_code_starts_with_0_on_valid_11_digit_number") { + REQUIRE_THROWS_AS(phone_number::phone_number("1 (223) 056-7890"), + std::domain_error); } -TEST_CASE( - "invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number") { - REQUIRE_THROWS_AS(phone_number::phone_number("1 (223) 156-7890"), std::domain_error); +TEST_CASE("invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number") { + REQUIRE_THROWS_AS(phone_number::phone_number("1 (223) 156-7890"), + std::domain_error); } #endif \ No newline at end of file diff --git a/exercises/practice/pig-latin/.meta/example.cpp b/exercises/practice/pig-latin/.meta/example.cpp index 9ac713270..68c99ce12 100644 --- a/exercises/practice/pig-latin/.meta/example.cpp +++ b/exercises/practice/pig-latin/.meta/example.cpp @@ -5,7 +5,8 @@ std::string translate_word(const std::string& word) { for (const std::string start : {"a", "e", "i", "o", "u", "yt", "xr"}) { if (word.substr(0, start.size()) == start) return word + "ay"; } - for (const std::string start : {"thr", "sch", "squ", "ch", "qu", "th", "rh"}) { + for (const std::string start : + {"thr", "sch", "squ", "ch", "qu", "th", "rh"}) { if (word.substr(0, start.size()) == start) return word.substr(start.size()) + start + "ay"; } @@ -17,7 +18,8 @@ std::string translate(const std::string& phrase) { std::string translation{}; for (size_t found = phrase.find(' '); found != std::string::npos; found = phrase.find(' ', start)) { - translation += translate_word(phrase.substr(start, found - start)) + " "; + translation += + translate_word(phrase.substr(start, found - start)) + " "; start = found + 1; } if (start != phrase.size()) diff --git a/exercises/practice/pig-latin/pig_latin.cpp b/exercises/practice/pig-latin/pig_latin.cpp index 84c2e17ad..3dce24019 100644 --- a/exercises/practice/pig-latin/pig_latin.cpp +++ b/exercises/practice/pig-latin/pig_latin.cpp @@ -1,5 +1,3 @@ #include "pig_latin.h" -namespace pig_latin { - -} // namespace pig_latin +namespace pig_latin {} // namespace pig_latin diff --git a/exercises/practice/pig-latin/pig_latin.h b/exercises/practice/pig-latin/pig_latin.h index ace0d2e70..6fe8818e7 100644 --- a/exercises/practice/pig-latin/pig_latin.h +++ b/exercises/practice/pig-latin/pig_latin.h @@ -1,5 +1,3 @@ #pragma once -namespace pig_latin { - -} // namespace pig_latin +namespace pig_latin {} // namespace pig_latin diff --git a/exercises/practice/pig-latin/pig_latin_test.cpp b/exercises/practice/pig-latin/pig_latin_test.cpp index 5368190c0..646723a4e 100644 --- a/exercises/practice/pig-latin/pig_latin_test.cpp +++ b/exercises/practice/pig-latin/pig_latin_test.cpp @@ -5,95 +5,100 @@ #include "test/catch.hpp" #endif - TEST_CASE("word beginning with a", "[11567f84-e8c6-4918-aedb-435f0b73db57]") { - REQUIRE("appleay" == pig_latin::translate("apple")); + REQUIRE("appleay" == pig_latin::translate("apple")); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("word beginning with e", "[f623f581-bc59-4f45-9032-90c3ca9d2d90]") { - REQUIRE("earay" == pig_latin::translate("ear")); + REQUIRE("earay" == pig_latin::translate("ear")); } TEST_CASE("word beginning with i", "[7dcb08b3-23a6-4e8a-b9aa-d4e859450d58]") { - REQUIRE("iglooay" == pig_latin::translate("igloo")); + REQUIRE("iglooay" == pig_latin::translate("igloo")); } TEST_CASE("word beginning with o", "[0e5c3bff-266d-41c8-909f-364e4d16e09c]") { - REQUIRE("objectay" == pig_latin::translate("object")); + REQUIRE("objectay" == pig_latin::translate("object")); } TEST_CASE("word beginning with u", "[614ba363-ca3c-4e96-ab09-c7320799723c]") { - REQUIRE("underay" == pig_latin::translate("under")); + REQUIRE("underay" == pig_latin::translate("under")); } -TEST_CASE("word beginning with a vowel and followed by a qu", "[bf2538c6-69eb-4fa7-a494-5a3fec911326]") { - REQUIRE("equalay" == pig_latin::translate("equal")); +TEST_CASE("word beginning with a vowel and followed by a qu", + "[bf2538c6-69eb-4fa7-a494-5a3fec911326]") { + REQUIRE("equalay" == pig_latin::translate("equal")); } TEST_CASE("word beginning with p", "[e5be8a01-2d8a-45eb-abb4-3fcc9582a303]") { - REQUIRE("igpay" == pig_latin::translate("pig")); + REQUIRE("igpay" == pig_latin::translate("pig")); } TEST_CASE("word beginning with k", "[d36d1e13-a7ed-464d-a282-8820cb2261ce]") { - REQUIRE("oalakay" == pig_latin::translate("koala")); + REQUIRE("oalakay" == pig_latin::translate("koala")); } TEST_CASE("word beginning with x", "[d838b56f-0a89-4c90-b326-f16ff4e1dddc]") { - REQUIRE("enonxay" == pig_latin::translate("xenon")); + REQUIRE("enonxay" == pig_latin::translate("xenon")); } -TEST_CASE("word beginning with q without a following u", "[bce94a7a-a94e-4e2b-80f4-b2bb02e40f71]") { - REQUIRE("atqay" == pig_latin::translate("qat")); +TEST_CASE("word beginning with q without a following u", + "[bce94a7a-a94e-4e2b-80f4-b2bb02e40f71]") { + REQUIRE("atqay" == pig_latin::translate("qat")); } TEST_CASE("word beginning with ch", "[c01e049a-e3e2-451c-bf8e-e2abb7e438b8]") { - REQUIRE("airchay" == pig_latin::translate("chair")); + REQUIRE("airchay" == pig_latin::translate("chair")); } TEST_CASE("word beginning with qu", "[9ba1669e-c43f-4b93-837a-cfc731fd1425]") { - REQUIRE("eenquay" == pig_latin::translate("queen")); + REQUIRE("eenquay" == pig_latin::translate("queen")); } -TEST_CASE("word beginning with qu and a preceding consonant", "[92e82277-d5e4-43d7-8dd3-3a3b316c41f7]") { - REQUIRE("aresquay" == pig_latin::translate("square")); +TEST_CASE("word beginning with qu and a preceding consonant", + "[92e82277-d5e4-43d7-8dd3-3a3b316c41f7]") { + REQUIRE("aresquay" == pig_latin::translate("square")); } TEST_CASE("word beginning with th", "[79ae4248-3499-4d5b-af46-5cb05fa073ac]") { - REQUIRE("erapythay" == pig_latin::translate("therapy")); + REQUIRE("erapythay" == pig_latin::translate("therapy")); } TEST_CASE("word beginning with thr", "[e0b3ae65-f508-4de3-8999-19c2f8e243e1]") { - REQUIRE("ushthray" == pig_latin::translate("thrush")); + REQUIRE("ushthray" == pig_latin::translate("thrush")); } TEST_CASE("word beginning with sch", "[20bc19f9-5a35-4341-9d69-1627d6ee6b43]") { - REQUIRE("oolschay" == pig_latin::translate("school")); + REQUIRE("oolschay" == pig_latin::translate("school")); } TEST_CASE("word beginning with yt", "[54b796cb-613d-4509-8c82-8fbf8fc0af9e]") { - REQUIRE("yttriaay" == pig_latin::translate("yttria")); + REQUIRE("yttriaay" == pig_latin::translate("yttria")); } TEST_CASE("word beginning with xr", "[8c37c5e1-872e-4630-ba6e-d20a959b67f6]") { - REQUIRE("xrayay" == pig_latin::translate("xray")); + REQUIRE("xrayay" == pig_latin::translate("xray")); } -TEST_CASE("y is treated like a consonant at the beginning of a word", "[a4a36d33-96f3-422c-a233-d4021460ff00]") { - REQUIRE("ellowyay" == pig_latin::translate("yellow")); +TEST_CASE("y is treated like a consonant at the beginning of a word", + "[a4a36d33-96f3-422c-a233-d4021460ff00]") { + REQUIRE("ellowyay" == pig_latin::translate("yellow")); } -TEST_CASE("y is treated like a vowel at the end of a consonant cluster", "[adc90017-1a12-4100-b595-e346105042c7]") { - REQUIRE("ythmrhay" == pig_latin::translate("rhythm")); +TEST_CASE("y is treated like a vowel at the end of a consonant cluster", + "[adc90017-1a12-4100-b595-e346105042c7]") { + REQUIRE("ythmrhay" == pig_latin::translate("rhythm")); } -TEST_CASE("y as second letter in two letter word", "[29b4ca3d-efe5-4a95-9a54-8467f2e5e59a]") { - REQUIRE("ymay" == pig_latin::translate("my")); +TEST_CASE("y as second letter in two letter word", + "[29b4ca3d-efe5-4a95-9a54-8467f2e5e59a]") { + REQUIRE("ymay" == pig_latin::translate("my")); } TEST_CASE("a whole phrase", "[44616581-5ce3-4a81-82d0-40c7ab13d2cf]") { - REQUIRE("ickquay astfay unray" == pig_latin::translate("quick fast run")); + REQUIRE("ickquay astfay unray" == pig_latin::translate("quick fast run")); } #endif diff --git a/exercises/practice/prime-factors/.meta/example.cpp b/exercises/practice/prime-factors/.meta/example.cpp index b9b83fc64..7d1df9f2b 100644 --- a/exercises/practice/prime-factors/.meta/example.cpp +++ b/exercises/practice/prime-factors/.meta/example.cpp @@ -1,11 +1,10 @@ -#include "prime_factors.h" #include -namespace prime_factors -{ +#include "prime_factors.h" + +namespace prime_factors { -std::vector of(int n) -{ +std::vector of(int n) { std::vector factors; const int end{static_cast(std::sqrt(n))}; for (int candidate{2}; candidate <= end; ++candidate) { @@ -21,4 +20,4 @@ std::vector of(int n) return factors; } -} +} // namespace prime_factors diff --git a/exercises/practice/prime-factors/.meta/example.h b/exercises/practice/prime-factors/.meta/example.h index bc4940f94..af7583f59 100644 --- a/exercises/practice/prime-factors/.meta/example.h +++ b/exercises/practice/prime-factors/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace prime_factors -{ +namespace prime_factors { std::vector of(int n); diff --git a/exercises/practice/prime-factors/prime_factors.cpp b/exercises/practice/prime-factors/prime_factors.cpp index 9a7479808..ee7fba20f 100644 --- a/exercises/practice/prime-factors/prime_factors.cpp +++ b/exercises/practice/prime-factors/prime_factors.cpp @@ -1,5 +1,3 @@ #include "prime_factors.h" -namespace prime_factors { - -} // namespace prime_factors +namespace prime_factors {} // namespace prime_factors diff --git a/exercises/practice/prime-factors/prime_factors.h b/exercises/practice/prime-factors/prime_factors.h index 845abe968..57e78cbba 100644 --- a/exercises/practice/prime-factors/prime_factors.h +++ b/exercises/practice/prime-factors/prime_factors.h @@ -1,8 +1,6 @@ #if !defined(PRIME_FACTORS_H) #define PRIME_FACTORS_H -namespace prime_factors { +namespace prime_factors {} // namespace prime_factors -} // namespace prime_factors - -#endif // PRIME_FACTORS_H \ No newline at end of file +#endif // PRIME_FACTORS_H \ No newline at end of file diff --git a/exercises/practice/prime-factors/prime_factors_test.cpp b/exercises/practice/prime-factors/prime_factors_test.cpp index fa1e29d47..abf1d56f8 100644 --- a/exercises/practice/prime-factors/prime_factors_test.cpp +++ b/exercises/practice/prime-factors/prime_factors_test.cpp @@ -5,8 +5,7 @@ #include "test/catch.hpp" #endif -TEST_CASE("_1_yields_empty") -{ +TEST_CASE("_1_yields_empty") { const std::vector expected{}; const std::vector actual{prime_factors::of(1)}; @@ -15,8 +14,7 @@ TEST_CASE("_1_yields_empty") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("_2_yields_2") -{ +TEST_CASE("_2_yields_2") { const std::vector expected{2}; const std::vector actual{prime_factors::of(2)}; @@ -24,8 +22,7 @@ TEST_CASE("_2_yields_2") REQUIRE(expected == actual); } -TEST_CASE("_3_yields_3") -{ +TEST_CASE("_3_yields_3") { const std::vector expected{3}; const std::vector actual{prime_factors::of(3)}; @@ -33,8 +30,7 @@ TEST_CASE("_3_yields_3") REQUIRE(expected == actual); } -TEST_CASE("_4_yields_2_2") -{ +TEST_CASE("_4_yields_2_2") { const std::vector expected{2, 2}; const std::vector actual{prime_factors::of(4)}; @@ -42,8 +38,7 @@ TEST_CASE("_4_yields_2_2") REQUIRE(expected == actual); } -TEST_CASE("_6_yields_2_3") -{ +TEST_CASE("_6_yields_2_3") { const std::vector expected{2, 3}; const std::vector actual{prime_factors::of(6)}; @@ -51,8 +46,7 @@ TEST_CASE("_6_yields_2_3") REQUIRE(expected == actual); } -TEST_CASE("_8_yields_2_2_2") -{ +TEST_CASE("_8_yields_2_2_2") { const std::vector expected{2, 2, 2}; const std::vector actual{prime_factors::of(8)}; @@ -60,8 +54,7 @@ TEST_CASE("_8_yields_2_2_2") REQUIRE(expected == actual); } -TEST_CASE("_9_yields_3_3") -{ +TEST_CASE("_9_yields_3_3") { const std::vector expected{3, 3}; const std::vector actual{prime_factors::of(9)}; @@ -69,8 +62,7 @@ TEST_CASE("_9_yields_3_3") REQUIRE(expected == actual); } -TEST_CASE("_27_yields_3_3_3") -{ +TEST_CASE("_27_yields_3_3_3") { const std::vector expected{3, 3, 3}; const std::vector actual{prime_factors::of(27)}; @@ -78,8 +70,7 @@ TEST_CASE("_27_yields_3_3_3") REQUIRE(expected == actual); } -TEST_CASE("_625_yields_5_5_5_5") -{ +TEST_CASE("_625_yields_5_5_5_5") { const std::vector expected{5, 5, 5, 5}; const std::vector actual{prime_factors::of(625)}; @@ -87,8 +78,7 @@ TEST_CASE("_625_yields_5_5_5_5") REQUIRE(expected == actual); } -TEST_CASE("_901255_yields_5_17_23_461") -{ +TEST_CASE("_901255_yields_5_17_23_461") { const std::vector expected{5, 17, 23, 461}; const std::vector actual{prime_factors::of(901255)}; diff --git a/exercises/practice/protein-translation/.meta/example.cpp b/exercises/practice/protein-translation/.meta/example.cpp index 3c3cebf83..539150af6 100644 --- a/exercises/practice/protein-translation/.meta/example.cpp +++ b/exercises/practice/protein-translation/.meta/example.cpp @@ -1,13 +1,13 @@ -#include "protein_translation.h" -#include -#include #include +#include #include +#include + +#include "protein_translation.h" using namespace std; vector protein_translation::proteins(string rna) { - unordered_map dic; dic["AUG"] = "Methionine"; dic["UUU"] = dic["UUC"] = "Phenylalanine"; @@ -19,7 +19,7 @@ vector protein_translation::proteins(string rna) { dic["UAA"] = dic["UAG"] = dic["UGA"] = "STOP"; vector polypeptide; - for (int i = 0; i < (int)rna.size()-2; i += 3) { + for (int i = 0; i < (int)rna.size() - 2; i += 3) { string codon = rna.substr(i, 3); auto it = dic.find(codon); if (it == dic.end() || it->second == "STOP") { diff --git a/exercises/practice/protein-translation/.meta/example.h b/exercises/practice/protein-translation/.meta/example.h index 7585df4d9..2de3d75d6 100644 --- a/exercises/practice/protein-translation/.meta/example.h +++ b/exercises/practice/protein-translation/.meta/example.h @@ -1,13 +1,13 @@ #if !defined(PROTEIN_TRANSLATION_H_) #define PROTEIN_TRANSLATION_H_ -#include #include +#include namespace protein_translation { std::vector proteins(std::string rna); -} // namespace protein_translation +} // namespace protein_translation #endif // !PROTEIN_TRANSLATION_H_ diff --git a/exercises/practice/protein-translation/protein_translation.cpp b/exercises/practice/protein-translation/protein_translation.cpp index 982f02e6a..b2388bb26 100644 --- a/exercises/practice/protein-translation/protein_translation.cpp +++ b/exercises/practice/protein-translation/protein_translation.cpp @@ -1,5 +1,3 @@ #include "protein_translation.h" -namespace protein_translation { - -} // namespace protein_translation +namespace protein_translation {} // namespace protein_translation diff --git a/exercises/practice/protein-translation/protein_translation.h b/exercises/practice/protein-translation/protein_translation.h index eefd8f26e..070271cee 100644 --- a/exercises/practice/protein-translation/protein_translation.h +++ b/exercises/practice/protein-translation/protein_translation.h @@ -1,8 +1,6 @@ #if !defined(PROTEIN_TRANSLATION_H) #define PROTEIN_TRANSLATION_H -namespace protein_translation { +namespace protein_translation {} // namespace protein_translation -} // namespace protein_translation - -#endif // PROTEIN_TRANSLATION_H +#endif // PROTEIN_TRANSLATION_H diff --git a/exercises/practice/protein-translation/protein_translation_test.cpp b/exercises/practice/protein-translation/protein_translation_test.cpp index a6d6ab0bc..76bb9a83a 100644 --- a/exercises/practice/protein-translation/protein_translation_test.cpp +++ b/exercises/practice/protein-translation/protein_translation_test.cpp @@ -3,132 +3,116 @@ #else #include "test/catch.hpp" #endif -#include "protein_translation.h" -#include #include +#include + +#include "protein_translation.h" using namespace std; // Secret-handshake exercise test case data version 1.2.1 -TEST_CASE("Methionine_RNA_sequence") -{ - REQUIRE(vector{"Methionine"} == protein_translation::proteins("AUG")); +TEST_CASE("Methionine_RNA_sequence") { + REQUIRE(vector{"Methionine"} == + protein_translation::proteins("AUG")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Phenylalanine_RNA_sequence_1") -{ - REQUIRE(vector{"Phenylalanine"} == protein_translation::proteins("UUU")); +TEST_CASE("Phenylalanine_RNA_sequence_1") { + REQUIRE(vector{"Phenylalanine"} == + protein_translation::proteins("UUU")); } -TEST_CASE("Phenylalanine_RNA_sequence_2") -{ - REQUIRE(vector{"Phenylalanine"} == protein_translation::proteins("UUC")); +TEST_CASE("Phenylalanine_RNA_sequence_2") { + REQUIRE(vector{"Phenylalanine"} == + protein_translation::proteins("UUC")); } -TEST_CASE("Leucine_RNA_sequence_1") -{ +TEST_CASE("Leucine_RNA_sequence_1") { REQUIRE(vector{"Leucine"} == protein_translation::proteins("UUA")); } -TEST_CASE("Leucine_RNA_sequence_2") -{ +TEST_CASE("Leucine_RNA_sequence_2") { REQUIRE(vector{"Leucine"} == protein_translation::proteins("UUG")); } -TEST_CASE("Serine_RNA_sequence_1") -{ +TEST_CASE("Serine_RNA_sequence_1") { REQUIRE(vector{"Serine"} == protein_translation::proteins("UCU")); } -TEST_CASE("Serine_RNA_sequence_2") -{ +TEST_CASE("Serine_RNA_sequence_2") { REQUIRE(vector{"Serine"} == protein_translation::proteins("UCC")); } -TEST_CASE("Serine_RNA_sequence_3") -{ +TEST_CASE("Serine_RNA_sequence_3") { REQUIRE(vector{"Serine"} == protein_translation::proteins("UCA")); } -TEST_CASE("Serine_RNA_sequence_4") -{ +TEST_CASE("Serine_RNA_sequence_4") { REQUIRE(vector{"Serine"} == protein_translation::proteins("UCG")); } -TEST_CASE("Tyrosine_RNA_sequence_1") -{ +TEST_CASE("Tyrosine_RNA_sequence_1") { REQUIRE(vector{"Tyrosine"} == protein_translation::proteins("UAU")); } -TEST_CASE("Tyrosine_RNA_sequence_2") -{ +TEST_CASE("Tyrosine_RNA_sequence_2") { REQUIRE(vector{"Tyrosine"} == protein_translation::proteins("UAC")); } -TEST_CASE("Cysteine_RNA_sequence_1") -{ +TEST_CASE("Cysteine_RNA_sequence_1") { REQUIRE(vector{"Cysteine"} == protein_translation::proteins("UGU")); } -TEST_CASE("Cysteine_RNA_sequence_2") -{ +TEST_CASE("Cysteine_RNA_sequence_2") { REQUIRE(vector{"Cysteine"} == protein_translation::proteins("UGC")); } -TEST_CASE("Tryptophan_RNA_sequence") -{ - REQUIRE(vector{"Tryptophan"} == protein_translation::proteins("UGG")); +TEST_CASE("Tryptophan_RNA_sequence") { + REQUIRE(vector{"Tryptophan"} == + protein_translation::proteins("UGG")); } -TEST_CASE("STOP_codon_RNA_sequence_1") -{ +TEST_CASE("STOP_codon_RNA_sequence_1") { REQUIRE(vector{} == protein_translation::proteins("UAA")); } -TEST_CASE("STOP_codon_RNA_sequence_2") -{ +TEST_CASE("STOP_codon_RNA_sequence_2") { REQUIRE(vector{} == protein_translation::proteins("UAG")); } -TEST_CASE("STOP_codon_RNA_sequence_3") -{ +TEST_CASE("STOP_codon_RNA_sequence_3") { REQUIRE(vector{} == protein_translation::proteins("UGA")); } -TEST_CASE("Translate_RNA_strand_into_correct_protein_list") -{ - REQUIRE(vector{"Methionine","Phenylalanine","Tryptophan"} - == protein_translation::proteins("AUGUUUUGG")); +TEST_CASE("Translate_RNA_strand_into_correct_protein_list") { + REQUIRE(vector{"Methionine", "Phenylalanine", "Tryptophan"} == + protein_translation::proteins("AUGUUUUGG")); } -TEST_CASE("Translation_stops_if_STOP_codon_at_beginning_of_sequence") -{ +TEST_CASE("Translation_stops_if_STOP_codon_at_beginning_of_sequence") { REQUIRE(vector{} == protein_translation::proteins("UAGUGG")); } -TEST_CASE("Translation_stops_if_STOP_codon_at_end_of_two-codon_sequence") -{ - REQUIRE(vector{"Tryptophan"} == protein_translation::proteins("UGGUAG")); +TEST_CASE("Translation_stops_if_STOP_codon_at_end_of_two-codon_sequence") { + REQUIRE(vector{"Tryptophan"} == + protein_translation::proteins("UGGUAG")); } -TEST_CASE("Translation_stops_if_STOP_codon_at_end_of_three-codon_sequence") -{ - REQUIRE(vector{"Methionine","Phenylalanine"} - == protein_translation::proteins("AUGUUUUAA")); +TEST_CASE("Translation_stops_if_STOP_codon_at_end_of_three-codon_sequence") { + REQUIRE(vector{"Methionine", "Phenylalanine"} == + protein_translation::proteins("AUGUUUUAA")); } -TEST_CASE("Translation_stops_if_STOP_codon_in_middle_of_three-codon_sequence") -{ - REQUIRE(vector{"Tryptophan"} == protein_translation::proteins("UGGUAGUGG")); +TEST_CASE("Translation_stops_if_STOP_codon_in_middle_of_three-codon_sequence") { + REQUIRE(vector{"Tryptophan"} == + protein_translation::proteins("UGGUAGUGG")); } -TEST_CASE("Translation_stops_if_STOP_codon_in_middle_of_six-codon_sequence") -{ - REQUIRE(vector{"Tryptophan","Cysteine","Tyrosine"} - == protein_translation::proteins("UGGUGUUAUUAAUGGUUU")); +TEST_CASE("Translation_stops_if_STOP_codon_in_middle_of_six-codon_sequence") { + REQUIRE(vector{"Tryptophan", "Cysteine", "Tyrosine"} == + protein_translation::proteins("UGGUGUUAUUAAUGGUUU")); } -#endif // !EXERCISM_RUN_ALL_TESTS +#endif // !EXERCISM_RUN_ALL_TESTS diff --git a/exercises/practice/queen-attack/.meta/example.cpp b/exercises/practice/queen-attack/.meta/example.cpp index ca42de609..2e609d5aa 100644 --- a/exercises/practice/queen-attack/.meta/example.cpp +++ b/exercises/practice/queen-attack/.meta/example.cpp @@ -1,28 +1,27 @@ -#include "queen_attack.h" - #include #include -namespace queen_attack -{ +#include "queen_attack.h" -chess_board::chess_board(const std::pair& white, const std::pair& black) - : white_{white}, - black_{black} -{ +namespace queen_attack { + +chess_board::chess_board(const std::pair& white, + const std::pair& black) + : white_{white}, black_{black} { if (white == black) { throw std::domain_error("Both queens cannot occupy the same position."); } - if (white.first < 0 || white.second < 0 || black.first < 0 || black.second < 0) { + if (white.first < 0 || white.second < 0 || black.first < 0 || + black.second < 0) { throw std::domain_error("Both queens must be placed on the board."); } - if (white.first > 7 || white.second > 7 || black.first > 7 || black.second > 7) { + if (white.first > 7 || white.second > 7 || black.first > 7 || + black.second > 7) { throw std::domain_error("Both queens must be placed on the board."); } } -chess_board::operator std::string() const -{ +chess_board::operator std::string() const { std::ostringstream board; for (int row = 0; row < 8; ++row) { for (int col = 0; col < 8; ++col) { @@ -43,12 +42,10 @@ chess_board::operator std::string() const return board.str(); } -bool chess_board::can_attack() const -{ - return (white_.first == black_.first) - || (white_.second == black_.second) - || ((white_.first - black_.first) == (white_.second - black_.second)) - || ((white_.first - black_.first) == (black_.second - white_.second)); +bool chess_board::can_attack() const { + return (white_.first == black_.first) || (white_.second == black_.second) || + ((white_.first - black_.first) == (white_.second - black_.second)) || + ((white_.first - black_.first) == (black_.second - white_.second)); } -} +} // namespace queen_attack diff --git a/exercises/practice/queen-attack/.meta/example.h b/exercises/practice/queen-attack/.meta/example.h index 8cc7f42f0..9057bc6b0 100644 --- a/exercises/practice/queen-attack/.meta/example.h +++ b/exercises/practice/queen-attack/.meta/example.h @@ -4,35 +4,27 @@ #include #include -namespace queen_attack -{ - -class chess_board -{ -public: - chess_board(const std::pair& white, const std::pair& black); - - chess_board() - {} - - std::pair white() const - { - return white_; - } - std::pair black() const - { - return black_; - } +namespace queen_attack { + +class chess_board { + public: + chess_board(const std::pair& white, + const std::pair& black); + + chess_board() {} + + std::pair white() const { return white_; } + std::pair black() const { return black_; } operator std::string() const; bool can_attack() const; -private: + private: const std::pair white_ = std::make_pair(0, 3); const std::pair black_ = std::make_pair(7, 3); }; -} +} // namespace queen_attack #endif diff --git a/exercises/practice/queen-attack/queen_attack.cpp b/exercises/practice/queen-attack/queen_attack.cpp index d86cbc7e3..13abba73d 100644 --- a/exercises/practice/queen-attack/queen_attack.cpp +++ b/exercises/practice/queen-attack/queen_attack.cpp @@ -1,5 +1,3 @@ #include "queen_attack.h" -namespace queen_attack { - -} // namespace queen_attack +namespace queen_attack {} // namespace queen_attack diff --git a/exercises/practice/queen-attack/queen_attack.h b/exercises/practice/queen-attack/queen_attack.h index 985ca53fd..a2ffa8b33 100644 --- a/exercises/practice/queen-attack/queen_attack.h +++ b/exercises/practice/queen-attack/queen_attack.h @@ -1,8 +1,6 @@ #if !defined(QUEEN_ATTACK_H) #define QUEEN_ATTACK_H -namespace queen_attack { +namespace queen_attack {} // namespace queen_attack -} // namespace queen_attack - -#endif // QUEEN_ATTACK_H \ No newline at end of file +#endif // QUEEN_ATTACK_H \ No newline at end of file diff --git a/exercises/practice/queen-attack/queen_attack_test.cpp b/exercises/practice/queen-attack/queen_attack_test.cpp index 9d2a7aa94..729fc978b 100644 --- a/exercises/practice/queen-attack/queen_attack_test.cpp +++ b/exercises/practice/queen-attack/queen_attack_test.cpp @@ -5,9 +5,7 @@ #include "test/catch.hpp" #endif - -TEST_CASE("newly_placed_queen_with_a_valid_position") -{ +TEST_CASE("newly_placed_queen_with_a_valid_position") { const auto white = std::make_pair(2, 2); const auto black = std::make_pair(0, 3); @@ -18,97 +16,99 @@ TEST_CASE("newly_placed_queen_with_a_valid_position") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("newly_placed_queen_must_have_positive_row") -{ +TEST_CASE("newly_placed_queen_must_have_positive_row") { const auto white = std::make_pair(-2, 2); const auto black = std::make_pair(0, 3); - REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), std::domain_error); + REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), + std::domain_error); } -TEST_CASE("newly_placed_queen_must_have_row_on_board") -{ +TEST_CASE("newly_placed_queen_must_have_row_on_board") { const auto white = std::make_pair(8, 4); const auto black = std::make_pair(0, 3); - REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), std::domain_error); + REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), + std::domain_error); } -TEST_CASE("newly_placed_queen_must_have_positive_column") -{ +TEST_CASE("newly_placed_queen_must_have_positive_column") { const auto white = std::make_pair(2, -2); const auto black = std::make_pair(0, 3); - REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), std::domain_error); + REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), + std::domain_error); } -TEST_CASE("newly_placed_queen_must_have_column_on_board") -{ +TEST_CASE("newly_placed_queen_must_have_column_on_board") { const auto white = std::make_pair(4, 8); const auto black = std::make_pair(0, 3); - REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), std::domain_error); + REQUIRE_THROWS_AS((queen_attack::chess_board{white, black}), + std::domain_error); } -TEST_CASE("queen_positions_must_be_distinct") -{ +TEST_CASE("queen_positions_must_be_distinct") { const auto pos = std::make_pair(3, 7); REQUIRE_THROWS_AS((queen_attack::chess_board{pos, pos}), std::domain_error); } -TEST_CASE("queens_cannot_attack") -{ - const queen_attack::chess_board board{std::make_pair(2, 4), std::make_pair(6, 6)}; +TEST_CASE("queens_cannot_attack") { + const queen_attack::chess_board board{std::make_pair(2, 4), + std::make_pair(6, 6)}; REQUIRE_FALSE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_same_row") -{ - const queen_attack::chess_board board{std::make_pair(2, 4), std::make_pair(2, 6)}; +TEST_CASE("queens_can_attack_on_same_row") { + const queen_attack::chess_board board{std::make_pair(2, 4), + std::make_pair(2, 6)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_same_column") -{ - const queen_attack::chess_board board{std::make_pair(4, 5), std::make_pair(2, 5)}; +TEST_CASE("queens_can_attack_on_same_column") { + const queen_attack::chess_board board{std::make_pair(4, 5), + std::make_pair(2, 5)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_first_diagonal") -{ - const queen_attack::chess_board board{std::make_pair(2, 2), std::make_pair(0, 4)}; +TEST_CASE("queens_can_attack_on_first_diagonal") { + const queen_attack::chess_board board{std::make_pair(2, 2), + std::make_pair(0, 4)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_second_diagonal") -{ - const queen_attack::chess_board board{std::make_pair(2, 2), std::make_pair(3, 1)}; +TEST_CASE("queens_can_attack_on_second_diagonal") { + const queen_attack::chess_board board{std::make_pair(2, 2), + std::make_pair(3, 1)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_third_diagonal") -{ - const queen_attack::chess_board board{std::make_pair(2, 2), std::make_pair(1, 1)}; +TEST_CASE("queens_can_attack_on_third_diagonal") { + const queen_attack::chess_board board{std::make_pair(2, 2), + std::make_pair(1, 1)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_can_attack_on_fourth_diagonal") -{ - const queen_attack::chess_board board{std::make_pair(1, 7), std::make_pair(0, 6)}; +TEST_CASE("queens_can_attack_on_fourth_diagonal") { + const queen_attack::chess_board board{std::make_pair(1, 7), + std::make_pair(0, 6)}; REQUIRE(board.can_attack()); } -TEST_CASE("queens_cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal") -{ - const queen_attack::chess_board board{std::make_pair(4, 1), std::make_pair(2, 5)}; +TEST_CASE( + // clang-format off + "queens_cannot_attack_if_falling_diagonals_are_only_the_same_when_reflected_across_the_longest_falling_diagonal") { + // clang-format on + const queen_attack::chess_board board{std::make_pair(4, 1), + std::make_pair(2, 5)}; REQUIRE_FALSE(board.can_attack()); } diff --git a/exercises/practice/raindrops/.meta/example.cpp b/exercises/practice/raindrops/.meta/example.cpp index f9c479c53..6c88e038b 100644 --- a/exercises/practice/raindrops/.meta/example.cpp +++ b/exercises/practice/raindrops/.meta/example.cpp @@ -1,13 +1,12 @@ -#include "raindrops.h" #include +#include "raindrops.h" + using namespace std; -namespace raindrops -{ +namespace raindrops { -string convert(int drops) -{ +string convert(int drops) { const int pling_factor{3}; const int plang_factor{5}; const int plong_factor{7}; @@ -27,4 +26,4 @@ string convert(int drops) return result.str(); } -} +} // namespace raindrops diff --git a/exercises/practice/raindrops/.meta/example.h b/exercises/practice/raindrops/.meta/example.h index 5e03472f5..57495477b 100644 --- a/exercises/practice/raindrops/.meta/example.h +++ b/exercises/practice/raindrops/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace raindrops -{ +namespace raindrops { std::string convert(int drops); diff --git a/exercises/practice/raindrops/raindrops.cpp b/exercises/practice/raindrops/raindrops.cpp index 921ecc919..e61d2f71e 100644 --- a/exercises/practice/raindrops/raindrops.cpp +++ b/exercises/practice/raindrops/raindrops.cpp @@ -1,5 +1,3 @@ #include "raindrops.h" -namespace raindrops { - -} // namespace raindrops +namespace raindrops {} // namespace raindrops diff --git a/exercises/practice/raindrops/raindrops.h b/exercises/practice/raindrops/raindrops.h index 083e826d9..782e51fb3 100644 --- a/exercises/practice/raindrops/raindrops.h +++ b/exercises/practice/raindrops/raindrops.h @@ -1,8 +1,6 @@ #if !defined(RAINDROPS_H) #define RAINDROPS_H -namespace raindrops { +namespace raindrops {} // namespace raindrops -} // namespace raindrops - -#endif // RAINDROPS_H \ No newline at end of file +#endif // RAINDROPS_H \ No newline at end of file diff --git a/exercises/practice/raindrops/raindrops_test.cpp b/exercises/practice/raindrops/raindrops_test.cpp index 92db5d307..e2adf4250 100644 --- a/exercises/practice/raindrops/raindrops_test.cpp +++ b/exercises/practice/raindrops/raindrops_test.cpp @@ -5,77 +5,58 @@ #include "test/catch.hpp" #endif -TEST_CASE("the_sound_for_1_is_1") -{ - REQUIRE("1" == raindrops::convert(1)); -} +TEST_CASE("the_sound_for_1_is_1") { REQUIRE("1" == raindrops::convert(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("the_sound_for_3_is_pling") -{ +TEST_CASE("the_sound_for_3_is_pling") { REQUIRE("Pling" == raindrops::convert(3)); } -TEST_CASE("the_sound_for_5_is_plang") -{ +TEST_CASE("the_sound_for_5_is_plang") { REQUIRE("Plang" == raindrops::convert(5)); } -TEST_CASE("the_sound_for_7_is_plong") -{ +TEST_CASE("the_sound_for_7_is_plong") { REQUIRE("Plong" == raindrops::convert(7)); } -TEST_CASE("the_sound_for_6_is_pling_as_it_has_a_factor_3") -{ +TEST_CASE("the_sound_for_6_is_pling_as_it_has_a_factor_3") { REQUIRE("Pling" == raindrops::convert(6)); } -TEST_CASE("2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base") -{ +TEST_CASE( + // clang-format off + "2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base") { + // clang-format on REQUIRE("8" == raindrops::convert(8)); } -TEST_CASE("the_sound_for_9_is_pling_as_it_has_a_factor_3") -{ +TEST_CASE("the_sound_for_9_is_pling_as_it_has_a_factor_3") { REQUIRE("Pling" == raindrops::convert(9)); } -TEST_CASE("the_sound_for_10_is_plang_as_it_has_a_factor_5") -{ +TEST_CASE("the_sound_for_10_is_plang_as_it_has_a_factor_5") { REQUIRE("Plang" == raindrops::convert(10)); } -TEST_CASE("the_sound_for_14_is_plong_as_it_has_a_factor_of_7") -{ +TEST_CASE("the_sound_for_14_is_plong_as_it_has_a_factor_of_7") { REQUIRE("Plong" == raindrops::convert(14)); } -TEST_CASE("the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5") -{ +TEST_CASE("the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5") { REQUIRE("PlingPlang" == raindrops::convert(15)); } -TEST_CASE("the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7") -{ +TEST_CASE("the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7") { REQUIRE("PlingPlong" == raindrops::convert(21)); } -TEST_CASE("the_sound_for_25_is_plang_as_it_has_a_factor_5") -{ +TEST_CASE("the_sound_for_25_is_plang_as_it_has_a_factor_5") { REQUIRE("Plang" == raindrops::convert(25)); } -TEST_CASE("the_sound_for_27_is_pling_as_it_has_a_factor_3") -{ +TEST_CASE("the_sound_for_27_is_pling_as_it_has_a_factor_3") { REQUIRE("Pling" == raindrops::convert(27)); } -TEST_CASE("the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7") -{ +TEST_CASE("the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7") { REQUIRE("PlangPlong" == raindrops::convert(35)); } -TEST_CASE("the_sound_for_49_is_plong_as_it_has_a_factor_7") -{ +TEST_CASE("the_sound_for_49_is_plong_as_it_has_a_factor_7") { REQUIRE("Plong" == raindrops::convert(49)); } -TEST_CASE("the_sound_for_52_is_52") -{ - REQUIRE("52" == raindrops::convert(52)); -} -TEST_CASE("the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7") -{ +TEST_CASE("the_sound_for_52_is_52") { REQUIRE("52" == raindrops::convert(52)); } +TEST_CASE("the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7") { REQUIRE("PlingPlangPlong" == raindrops::convert(105)); } -TEST_CASE("the_sound_for_3125_is_plang_as_it_has_a_factor_5") -{ +TEST_CASE("the_sound_for_3125_is_plang_as_it_has_a_factor_5") { REQUIRE("Plang" == raindrops::convert(3125)); } #endif diff --git a/exercises/practice/resistor-color-duo/.meta/example.cpp b/exercises/practice/resistor-color-duo/.meta/example.cpp index cc41ec74c..35121a15b 100644 --- a/exercises/practice/resistor-color-duo/.meta/example.cpp +++ b/exercises/practice/resistor-color-duo/.meta/example.cpp @@ -1,18 +1,20 @@ #include "resistor_color_duo.h" namespace resistor_color_duo { - const std::vector resistor_colors{"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"}; +const std::vector resistor_colors{ + "black", "brown", "red", "orange", "yellow", + "green", "blue", "violet", "grey", "white"}; - int color_code(const std::string& color) { - for(size_t i{}; i <= resistor_colors.size(); ++i) { - if(resistor_colors.at(i) == color) { - return i; - } +int color_code(const std::string& color) { + for (size_t i{}; i <= resistor_colors.size(); ++i) { + if (resistor_colors.at(i) == color) { + return i; } - return -1; } + return -1; +} - int value(const std::vector& colors) { - return color_code(colors.at(0)) * 10 + color_code(colors.at(1)); - } +int value(const std::vector& colors) { + return color_code(colors.at(0)) * 10 + color_code(colors.at(1)); +} } // namespace resistor_color_duo diff --git a/exercises/practice/resistor-color-duo/.meta/example.h b/exercises/practice/resistor-color-duo/.meta/example.h index 5f7ea1a7e..970308f33 100644 --- a/exercises/practice/resistor-color-duo/.meta/example.h +++ b/exercises/practice/resistor-color-duo/.meta/example.h @@ -1,8 +1,8 @@ #pragma once -#include -#include +#include +#include namespace resistor_color_duo { - int value(const std::vector& colors); +int value(const std::vector& colors); } // namespace resistor_color_duo diff --git a/exercises/practice/resistor-color-duo/resistor_color_duo.cpp b/exercises/practice/resistor-color-duo/resistor_color_duo.cpp index 0a2e9dd56..6279171a8 100644 --- a/exercises/practice/resistor-color-duo/resistor_color_duo.cpp +++ b/exercises/practice/resistor-color-duo/resistor_color_duo.cpp @@ -1,5 +1,3 @@ #include "resistor_color_duo.h" -namespace resistor_color_duo { - -} // namespace resistor_color_duo +namespace resistor_color_duo {} // namespace resistor_color_duo diff --git a/exercises/practice/resistor-color-duo/resistor_color_duo.h b/exercises/practice/resistor-color-duo/resistor_color_duo.h index 53088257e..b81fed96c 100644 --- a/exercises/practice/resistor-color-duo/resistor_color_duo.h +++ b/exercises/practice/resistor-color-duo/resistor_color_duo.h @@ -1,5 +1,3 @@ #pragma once -namespace resistor_color_duo { - -} // namespace resistor_color_duo +namespace resistor_color_duo {} // namespace resistor_color_duo diff --git a/exercises/practice/resistor-color-duo/resistor_color_duo_test.cpp b/exercises/practice/resistor-color-duo/resistor_color_duo_test.cpp index 8e31af155..d3502260e 100644 --- a/exercises/practice/resistor-color-duo/resistor_color_duo_test.cpp +++ b/exercises/practice/resistor-color-duo/resistor_color_duo_test.cpp @@ -5,35 +5,36 @@ #include "test/catch.hpp" #endif - TEST_CASE("Brown and black", "[ce11995a-5b93-4950-a5e9-93423693b2fc]") { - REQUIRE(10 == resistor_color_duo::value({"brown", "black"})); + REQUIRE(10 == resistor_color_duo::value({"brown", "black"})); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("Blue and grey", "[7bf82f7a-af23-48ba-a97d-38d59406a920]") { - REQUIRE(68 == resistor_color_duo::value({"blue", "grey"})); + REQUIRE(68 == resistor_color_duo::value({"blue", "grey"})); } TEST_CASE("Yellow and violet", "[f1886361-fdfd-4693-acf8-46726fe24e0c]") { - REQUIRE(47 == resistor_color_duo::value({"yellow", "violet"})); + REQUIRE(47 == resistor_color_duo::value({"yellow", "violet"})); } TEST_CASE("White and red", "[b7a6cbd2-ae3c-470a-93eb-56670b305640]") { - REQUIRE(92 == resistor_color_duo::value({"white", "red"})); + REQUIRE(92 == resistor_color_duo::value({"white", "red"})); } TEST_CASE("Orange and orange", "[77a8293d-2a83-4016-b1af-991acc12b9fe]") { - REQUIRE(33 == resistor_color_duo::value({"orange", "orange"})); + REQUIRE(33 == resistor_color_duo::value({"orange", "orange"})); } -TEST_CASE("Ignore additional colors", "[0c4fb44f-db7c-4d03-afa8-054350f156a8]") { - REQUIRE(51 == resistor_color_duo::value({"green", "brown", "orange"})); +TEST_CASE("Ignore additional colors", + "[0c4fb44f-db7c-4d03-afa8-054350f156a8]") { + REQUIRE(51 == resistor_color_duo::value({"green", "brown", "orange"})); } -TEST_CASE("Black and brown, one-digit", "[4a8ceec5-0ab4-4904-88a4-daf953a5e818]") { - REQUIRE(1 == resistor_color_duo::value({"black", "brown"})); +TEST_CASE("Black and brown, one-digit", + "[4a8ceec5-0ab4-4904-88a4-daf953a5e818]") { + REQUIRE(1 == resistor_color_duo::value({"black", "brown"})); } #endif diff --git a/exercises/practice/resistor-color/.meta/example.cpp b/exercises/practice/resistor-color/.meta/example.cpp index c9d62e3fe..0fc2f9755 100644 --- a/exercises/practice/resistor-color/.meta/example.cpp +++ b/exercises/practice/resistor-color/.meta/example.cpp @@ -1,18 +1,18 @@ #include "resistor_color.h" namespace resistor_color { - const std::vector resistor_colors{"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"}; +const std::vector resistor_colors{ + "black", "brown", "red", "orange", "yellow", + "green", "blue", "violet", "grey", "white"}; - int color_code(const std::string& color) { - for(size_t i{}; i <= resistor_colors.size(); ++i) { - if(resistor_colors.at(i) == color) { - return i; - } +int color_code(const std::string& color) { + for (size_t i{}; i <= resistor_colors.size(); ++i) { + if (resistor_colors.at(i) == color) { + return i; } - return -1; } + return -1; +} - std::vector colors() { - return resistor_colors; - } +std::vector colors() { return resistor_colors; } } // namespace resistor_color diff --git a/exercises/practice/resistor-color/.meta/example.h b/exercises/practice/resistor-color/.meta/example.h index b980e642d..6ac1ab536 100644 --- a/exercises/practice/resistor-color/.meta/example.h +++ b/exercises/practice/resistor-color/.meta/example.h @@ -4,6 +4,6 @@ #include namespace resistor_color { - int color_code(const std::string& color); - std::vector colors(); +int color_code(const std::string& color); +std::vector colors(); } // namespace resistor_color diff --git a/exercises/practice/resistor-color/resistor_color.cpp b/exercises/practice/resistor-color/resistor_color.cpp index 9edebab2c..d9cdc6f8b 100644 --- a/exercises/practice/resistor-color/resistor_color.cpp +++ b/exercises/practice/resistor-color/resistor_color.cpp @@ -1,5 +1,3 @@ #include "resistor_color.h" -namespace resistor_color { - -} // namespace resistor_color +namespace resistor_color {} // namespace resistor_color diff --git a/exercises/practice/resistor-color/resistor_color.h b/exercises/practice/resistor-color/resistor_color.h index 30dfeaff7..8678f7097 100644 --- a/exercises/practice/resistor-color/resistor_color.h +++ b/exercises/practice/resistor-color/resistor_color.h @@ -1,5 +1,3 @@ #pragma once -namespace resistor_color { - -} // namespace resistor_color +namespace resistor_color {} // namespace resistor_color diff --git a/exercises/practice/resistor-color/resistor_color_test.cpp b/exercises/practice/resistor-color/resistor_color_test.cpp index 57dc1498d..012d64a97 100644 --- a/exercises/practice/resistor-color/resistor_color_test.cpp +++ b/exercises/practice/resistor-color/resistor_color_test.cpp @@ -5,23 +5,23 @@ #include "test/catch.hpp" #endif - TEST_CASE("Black", "[49eb31c5-10a8-4180-9f7f-fea632ab87ef]") { - REQUIRE(0 == resistor_color::color_code("black")); + REQUIRE(0 == resistor_color::color_code("black")); } TEST_CASE("White", "[0a4df94b-92da-4579-a907-65040ce0b3fc]") { - REQUIRE(9 == resistor_color::color_code("white")); + REQUIRE(9 == resistor_color::color_code("white")); } TEST_CASE("Orange", "[5f81608d-f36f-4190-8084-f45116b6f380]") { - REQUIRE(3 == resistor_color::color_code("orange")); + REQUIRE(3 == resistor_color::color_code("orange")); } - TEST_CASE("Colors", "[581d68fa-f968-4be2-9f9d-880f2fb73cf7]") { - std::vector expected{"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"}; - REQUIRE(expected == resistor_color::colors()); + std::vector expected{"black", "brown", "red", "orange", + "yellow", "green", "blue", "violet", + "grey", "white"}; + REQUIRE(expected == resistor_color::colors()); } #if defined(EXERCISM_RUN_ALL_TESTS) diff --git a/exercises/practice/reverse-string/.meta/example.cpp b/exercises/practice/reverse-string/.meta/example.cpp index 826a83778..24f55d5ed 100644 --- a/exercises/practice/reverse-string/.meta/example.cpp +++ b/exercises/practice/reverse-string/.meta/example.cpp @@ -1,11 +1,9 @@ #include "reverse_string.h" -namespace reverse_string -{ +namespace reverse_string { -std::string reverse_string(const std::string& text) -{ +std::string reverse_string(const std::string& text) { return std::string(text.rbegin(), text.rend()); } -} +} // namespace reverse_string diff --git a/exercises/practice/reverse-string/.meta/example.h b/exercises/practice/reverse-string/.meta/example.h index 10c2f6a0f..07ffac7c2 100644 --- a/exercises/practice/reverse-string/.meta/example.h +++ b/exercises/practice/reverse-string/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace reverse_string -{ +namespace reverse_string { std::string reverse_string(const std::string& text); diff --git a/exercises/practice/reverse-string/reverse_string.cpp b/exercises/practice/reverse-string/reverse_string.cpp index ccf936651..1129fb69a 100644 --- a/exercises/practice/reverse-string/reverse_string.cpp +++ b/exercises/practice/reverse-string/reverse_string.cpp @@ -1,5 +1,3 @@ #include "reverse_string.h" -namespace reverse_string { - -} // namespace reverse_string +namespace reverse_string {} // namespace reverse_string diff --git a/exercises/practice/reverse-string/reverse_string.h b/exercises/practice/reverse-string/reverse_string.h index 2ac370d18..a462bf719 100644 --- a/exercises/practice/reverse-string/reverse_string.h +++ b/exercises/practice/reverse-string/reverse_string.h @@ -1,8 +1,6 @@ #if !defined(REVERSE_STRING_H) #define REVERSE_STRING_H -namespace reverse_string { +namespace reverse_string {} // namespace reverse_string -} // namespace reverse_string - -#endif // REVERSE_STRING_H \ No newline at end of file +#endif // REVERSE_STRING_H \ No newline at end of file diff --git a/exercises/practice/reverse-string/reverse_string_test.cpp b/exercises/practice/reverse-string/reverse_string_test.cpp index ca045f552..2dd7aac37 100644 --- a/exercises/practice/reverse-string/reverse_string_test.cpp +++ b/exercises/practice/reverse-string/reverse_string_test.cpp @@ -5,29 +5,24 @@ #include "test/catch.hpp" #endif -TEST_CASE("an_empty_string") -{ +TEST_CASE("an_empty_string") { REQUIRE("" == reverse_string::reverse_string("")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("a_word") -{ +TEST_CASE("a_word") { REQUIRE("tobor" == reverse_string::reverse_string("robot")); } -TEST_CASE("a_capitalized_word") -{ +TEST_CASE("a_capitalized_word") { REQUIRE("nemaR" == reverse_string::reverse_string("Ramen")); } -TEST_CASE("a_sentence_with_punctuation") -{ +TEST_CASE("a_sentence_with_punctuation") { REQUIRE("!yrgnuh m'I" == reverse_string::reverse_string("I'm hungry!")); } -TEST_CASE("a_palindrome") -{ - REQUIRE("racecar" == reverse_string::reverse_string("racecar")); +TEST_CASE("a_palindrome") { + REQUIRE("racecar" == reverse_string::reverse_string("racecar")); } #endif diff --git a/exercises/practice/rna-transcription/.meta/example.cpp b/exercises/practice/rna-transcription/.meta/example.cpp index 79692c0b6..fa2d4a7a7 100644 --- a/exercises/practice/rna-transcription/.meta/example.cpp +++ b/exercises/practice/rna-transcription/.meta/example.cpp @@ -1,14 +1,13 @@ -#include "rna_transcription.h" #include #include +#include "rna_transcription.h" + using namespace std; -namespace rna_transcription -{ +namespace rna_transcription { -char to_rna(const char nucleotide) -{ +char to_rna(const char nucleotide) { const string dna_nucleotides("CGAT"); const string rna_nucleotides("GCUA"); const auto pos = dna_nucleotides.find(nucleotide); @@ -18,12 +17,11 @@ char to_rna(const char nucleotide) return 0; } -string to_rna(string const& sequence) -{ +string to_rna(string const& sequence) { string transcription; transform(sequence.begin(), sequence.end(), back_inserter(transcription), - [](char c) { return to_rna(c); }); + [](char c) { return to_rna(c); }); return transcription; } -} +} // namespace rna_transcription diff --git a/exercises/practice/rna-transcription/.meta/example.h b/exercises/practice/rna-transcription/.meta/example.h index 9b09d2e46..84347f393 100644 --- a/exercises/practice/rna-transcription/.meta/example.h +++ b/exercises/practice/rna-transcription/.meta/example.h @@ -3,12 +3,11 @@ #include -namespace rna_transcription -{ +namespace rna_transcription { char to_rna(char nucleotide); std::string to_rna(std::string const& nucleotide); -} +} // namespace rna_transcription #endif diff --git a/exercises/practice/rna-transcription/rna_transcription.cpp b/exercises/practice/rna-transcription/rna_transcription.cpp index eb4fbecad..83d2c3631 100644 --- a/exercises/practice/rna-transcription/rna_transcription.cpp +++ b/exercises/practice/rna-transcription/rna_transcription.cpp @@ -1,5 +1,3 @@ #include "rna_transcription.h" -namespace rna_transcription { - -} // namespace rna_transcription +namespace rna_transcription {} // namespace rna_transcription diff --git a/exercises/practice/rna-transcription/rna_transcription.h b/exercises/practice/rna-transcription/rna_transcription.h index b5d3880a8..8f320bf82 100644 --- a/exercises/practice/rna-transcription/rna_transcription.h +++ b/exercises/practice/rna-transcription/rna_transcription.h @@ -1,8 +1,6 @@ #if !defined(RNA_TRANSCRIPTION_H) #define RNA_TRANSCRIPTION_H -namespace rna_transcription { +namespace rna_transcription {} // namespace rna_transcription -} // namespace rna_transcription - -#endif // RNA_TRANSCRIPTION_H \ No newline at end of file +#endif // RNA_TRANSCRIPTION_H \ No newline at end of file diff --git a/exercises/practice/rna-transcription/rna_transcription_test.cpp b/exercises/practice/rna-transcription/rna_transcription_test.cpp index 91bf0d22b..208a1e372 100644 --- a/exercises/practice/rna-transcription/rna_transcription_test.cpp +++ b/exercises/practice/rna-transcription/rna_transcription_test.cpp @@ -5,29 +5,24 @@ #include "test/catch.hpp" #endif -TEST_CASE("transcribes_cytidine_to_guanosine") -{ +TEST_CASE("transcribes_cytidine_to_guanosine") { REQUIRE('G' == rna_transcription::to_rna('C')); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("transcribes_guanosine_to_cytidine") -{ +TEST_CASE("transcribes_guanosine_to_cytidine") { REQUIRE('C' == rna_transcription::to_rna('G')); } -TEST_CASE("transcribes_adenosine_to_uracil") -{ +TEST_CASE("transcribes_adenosine_to_uracil") { REQUIRE('U' == rna_transcription::to_rna('A')); } -TEST_CASE("transcribes_thymidine_to_adenosine") -{ +TEST_CASE("transcribes_thymidine_to_adenosine") { REQUIRE('A' == rna_transcription::to_rna('T')); } -TEST_CASE("transcribes_all_dna_nucleotides_to_their_rna_complements") -{ +TEST_CASE("transcribes_all_dna_nucleotides_to_their_rna_complements") { REQUIRE("UGCACCAGAAUU" == rna_transcription::to_rna("ACGTGGTCTTAA")); } #endif diff --git a/exercises/practice/robot-name/.meta/example.cpp b/exercises/practice/robot-name/.meta/example.cpp index 0c078ea85..f97ff8106 100644 --- a/exercises/practice/robot-name/.meta/example.cpp +++ b/exercises/practice/robot-name/.meta/example.cpp @@ -1,18 +1,16 @@ -#include "robot_name.h" #include #include #include +#include "robot_name.h" + using namespace std; -namespace robot_name -{ +namespace robot_name { -namespace -{ +namespace { -string next_prefix(string const &prefix) -{ +string next_prefix(string const &prefix) { string next{prefix}; const string letters{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; if (prefix[1] == letters.back()) { @@ -27,8 +25,7 @@ string next_prefix(string const &prefix) return next; } -string generate_name() -{ +string generate_name() { static string prefix = "AA"; static int unit_number = 0; ostringstream buff; @@ -40,16 +37,10 @@ string generate_name() return buff.str(); } -} +} // namespace -robot::robot() - : name_(generate_name()) -{ -} +robot::robot() : name_(generate_name()) {} -void robot::reset() -{ - name_ = generate_name(); -} +void robot::reset() { name_ = generate_name(); } -} +} // namespace robot_name diff --git a/exercises/practice/robot-name/.meta/example.h b/exercises/practice/robot-name/.meta/example.h index 102e4819a..ef941b679 100644 --- a/exercises/practice/robot-name/.meta/example.h +++ b/exercises/practice/robot-name/.meta/example.h @@ -3,22 +3,20 @@ #include -namespace robot_name -{ +namespace robot_name { -class robot -{ -public: +class robot { + public: robot(); std::string const &name() const { return name_; } void reset(); -private: + private: std::string name_; }; -} +} // namespace robot_name #endif diff --git a/exercises/practice/robot-name/robot_name.cpp b/exercises/practice/robot-name/robot_name.cpp index bee605049..c18826f92 100644 --- a/exercises/practice/robot-name/robot_name.cpp +++ b/exercises/practice/robot-name/robot_name.cpp @@ -1,5 +1,3 @@ #include "robot_name.h" -namespace robot_name { - -} // namespace robot_name +namespace robot_name {} // namespace robot_name diff --git a/exercises/practice/robot-name/robot_name.h b/exercises/practice/robot-name/robot_name.h index 23aaf1e88..8563d4d1b 100644 --- a/exercises/practice/robot-name/robot_name.h +++ b/exercises/practice/robot-name/robot_name.h @@ -1,8 +1,6 @@ #if !defined(ROBOT_NAME_H) #define ROBOT_NAME_H -namespace robot_name { +namespace robot_name {} // namespace robot_name -} // namespace robot_name - -#endif // ROBOT_NAME_H \ No newline at end of file +#endif // ROBOT_NAME_H \ No newline at end of file diff --git a/exercises/practice/robot-name/robot_name_test.cpp b/exercises/practice/robot-name/robot_name_test.cpp index 115c33f0e..ef38ce17e 100644 --- a/exercises/practice/robot-name/robot_name_test.cpp +++ b/exercises/practice/robot-name/robot_name_test.cpp @@ -10,45 +10,38 @@ using namespace std; -namespace -{ +namespace { // Helper function to check the robot name matches the instructions. // // 2 uppercase letters followed by 3 digits. -static bool validate_name(const string& name) -{ - if (name.length() != 5) - return false; - return isupper(name[0]) && isupper(name[1]) && isdigit(name[2]) - && isdigit(name[3]) && isdigit(name[4]); -} +static bool validate_name(const string& name) { + if (name.length() != 5) return false; + return isupper(name[0]) && isupper(name[1]) && isdigit(name[2]) && + isdigit(name[3]) && isdigit(name[4]); } +} // namespace -TEST_CASE("has_a_name") -{ +TEST_CASE("has_a_name") { const robot_name::robot robot; REQUIRE(validate_name(robot.name())); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("name_is_the_same_each_time") -{ +TEST_CASE("name_is_the_same_each_time") { const robot_name::robot robot; REQUIRE(robot.name() == robot.name()); } -TEST_CASE("different_robots_have_different_names") -{ +TEST_CASE("different_robots_have_different_names") { const robot_name::robot robot_one; const robot_name::robot robot_two; REQUIRE(robot_one.name() != robot_two.name()); } -TEST_CASE("is_able_to_reset_name") -{ +TEST_CASE("is_able_to_reset_name") { robot_name::robot robot; const auto original_name = robot.name(); @@ -57,8 +50,7 @@ TEST_CASE("is_able_to_reset_name") REQUIRE(original_name != robot.name()); } -TEST_CASE("exhausting_digits_yields_different_names") -{ +TEST_CASE("exhausting_digits_yields_different_names") { robot_name::robot robot; unordered_set names; names.insert(robot.name()); diff --git a/exercises/practice/robot-simulator/.meta/example.cpp b/exercises/practice/robot-simulator/.meta/example.cpp index 06b56ce5e..26a668956 100644 --- a/exercises/practice/robot-simulator/.meta/example.cpp +++ b/exercises/practice/robot-simulator/.meta/example.cpp @@ -2,40 +2,27 @@ namespace robot_simulator { -Robot::Robot() : robot_position(std::make_pair(0, 0)), robot_bearing(Bearing::NORTH) -{ -} +Robot::Robot() + : robot_position(std::make_pair(0, 0)), robot_bearing(Bearing::NORTH) {} -Robot::Robot(std::pair p, Bearing b) : robot_position(p), robot_bearing(b) -{ -} +Robot::Robot(std::pair p, Bearing b) + : robot_position(p), robot_bearing(b) {} -Bearing Robot::get_bearing() const -{ - return robot_bearing; -} +Bearing Robot::get_bearing() const { return robot_bearing; } -std::pair Robot::get_position() const -{ - return robot_position; -} +std::pair Robot::get_position() const { return robot_position; } -void Robot::turn_right() -{ - switch(robot_bearing) - { - case Bearing::NORTH: - { +void Robot::turn_right() { + switch (robot_bearing) { + case Bearing::NORTH: { robot_bearing = Bearing::EAST; break; } - case Bearing::EAST: - { + case Bearing::EAST: { robot_bearing = Bearing::SOUTH; break; } - case Bearing::SOUTH: - { + case Bearing::SOUTH: { robot_bearing = Bearing::WEST; break; } @@ -44,81 +31,62 @@ void Robot::turn_right() } } -void Robot::turn_left() -{ - switch(robot_bearing) - { - case Bearing::NORTH: - { +void Robot::turn_left() { + switch (robot_bearing) { + case Bearing::NORTH: { robot_bearing = Bearing::WEST; break; } - case Bearing::WEST: - { + case Bearing::WEST: { robot_bearing = Bearing::SOUTH; break; } - case Bearing::SOUTH: - { + case Bearing::SOUTH: { robot_bearing = Bearing::EAST; break; } - case Bearing::EAST: - { + case Bearing::EAST: { robot_bearing = Bearing::NORTH; } } } -void Robot::advance() -{ - switch(robot_bearing) - { - case Bearing::NORTH: - { +void Robot::advance() { + switch (robot_bearing) { + case Bearing::NORTH: { robot_position.second++; break; } - case Bearing::WEST: - { + case Bearing::WEST: { robot_position.first--; break; } - case Bearing::SOUTH: - { + case Bearing::SOUTH: { robot_position.second--; break; } - case Bearing::EAST: - { + case Bearing::EAST: { robot_position.first++; } - } + } } -void Robot::execute_sequence(std::string const& sequence) -{ - for(char c : sequence) - { - switch(c) - { - case 'L': - { +void Robot::execute_sequence(std::string const& sequence) { + for (char c : sequence) { + switch (c) { + case 'L': { turn_left(); break; } - case 'R': - { + case 'R': { turn_right(); break; } - case 'A': - { + case 'A': { advance(); } } } } -} // namespace robot_simulator - +} // namespace robot_simulator diff --git a/exercises/practice/robot-simulator/.meta/example.h b/exercises/practice/robot-simulator/.meta/example.h index d8c10901a..6fc92cb86 100644 --- a/exercises/practice/robot-simulator/.meta/example.h +++ b/exercises/practice/robot-simulator/.meta/example.h @@ -5,11 +5,10 @@ namespace robot_simulator { -enum class Bearing {NORTH, WEST, SOUTH, EAST}; +enum class Bearing { NORTH, WEST, SOUTH, EAST }; -class Robot -{ -public: +class Robot { + public: Robot(); Robot(std::pair, Bearing); Robot(Robot const&) = delete; @@ -17,18 +16,18 @@ class Robot Robot(Robot const&&) = delete; Robot& operator=(Robot const&&) = delete; ~Robot() = default; - void turn_left(); + void turn_left(); void turn_right(); void advance(); void execute_sequence(std::string const&); std::pair get_position() const; Bearing get_bearing() const; -private: + + private: std::pair robot_position; Bearing robot_bearing; }; -} // namespace robot_simulator - -#endif // ROBOT_SIMULATOR +} // namespace robot_simulator +#endif // ROBOT_SIMULATOR diff --git a/exercises/practice/robot-simulator/robot_simulator.cpp b/exercises/practice/robot-simulator/robot_simulator.cpp index c1295d772..71313c193 100644 --- a/exercises/practice/robot-simulator/robot_simulator.cpp +++ b/exercises/practice/robot-simulator/robot_simulator.cpp @@ -1,5 +1,3 @@ #include "robot_simulator.h" -namespace robot_simulator { - -} // namespace robot_simulator +namespace robot_simulator {} // namespace robot_simulator diff --git a/exercises/practice/robot-simulator/robot_simulator.h b/exercises/practice/robot-simulator/robot_simulator.h index f3214ff0a..bc713f6be 100644 --- a/exercises/practice/robot-simulator/robot_simulator.h +++ b/exercises/practice/robot-simulator/robot_simulator.h @@ -1,8 +1,6 @@ #if !defined(ROBOT_SIMULATOR_H) #define ROBOT_SIMULATOR_H -namespace robot_simulator { +namespace robot_simulator {} // namespace robot_simulator -} // namespace robot_simulator - -#endif // ROBOT_SIMULATOR_H \ No newline at end of file +#endif // ROBOT_SIMULATOR_H \ No newline at end of file diff --git a/exercises/practice/robot-simulator/robot_simulator_test.cpp b/exercises/practice/robot-simulator/robot_simulator_test.cpp index 40e1e58f6..32e7cd47b 100644 --- a/exercises/practice/robot-simulator/robot_simulator_test.cpp +++ b/exercises/practice/robot-simulator/robot_simulator_test.cpp @@ -5,13 +5,12 @@ #endif #include "robot_simulator.h" -using robot_simulator::Robot; using robot_simulator::Bearing; +using robot_simulator::Robot; // Robot-Simulator exercise test case data version 3.1.0 -TEST_CASE("A_robots_is_created_with_a_position_and_a_direction") -{ +TEST_CASE("A_robots_is_created_with_a_position_and_a_direction") { const Robot r; const std::pair expected_robot_position{0, 0}; @@ -20,10 +19,9 @@ TEST_CASE("A_robots_is_created_with_a_position_and_a_direction") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Negative_positions_are_allowed") -{ +TEST_CASE("Negative_positions_are_allowed") { const std::pair robot_position{-1, -1}; - const Bearing robot_bearing {Bearing::SOUTH}; + const Bearing robot_bearing{Bearing::SOUTH}; const Robot r{robot_position, robot_bearing}; const std::pair expected_robot_position = robot_position; @@ -31,51 +29,47 @@ TEST_CASE("Negative_positions_are_allowed") REQUIRE(Bearing::SOUTH == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_north_to_east") -{ +TEST_CASE("Changes_the_direction_from_north_to_east") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::NORTH}; + const Bearing robot_bearing{Bearing::NORTH}; Robot r{robot_position, robot_bearing}; - + r.turn_right(); - + const std::pair expected_robot_position = robot_position; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::EAST == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_east_to_south") -{ +TEST_CASE("Changes_the_direction_from_east_to_south") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::EAST}; + const Bearing robot_bearing{Bearing::EAST}; Robot r{robot_position, robot_bearing}; - + r.turn_right(); - + const std::pair expected_robot_position = robot_position; - REQUIRE(expected_robot_position== r.get_position()); + REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::SOUTH == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_south_to_west") -{ +TEST_CASE("Changes_the_direction_from_south_to_west") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::SOUTH}; + const Bearing robot_bearing{Bearing::SOUTH}; Robot r{robot_position, robot_bearing}; - + r.turn_right(); - + const std::pair expected_robot_position = robot_position; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::WEST == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_west_to_north") -{ +TEST_CASE("Changes_the_direction_from_west_to_north") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::WEST}; + const Bearing robot_bearing{Bearing::WEST}; Robot r{robot_position, robot_bearing}; - + r.turn_right(); const std::pair expected_robot_position = robot_position; @@ -83,38 +77,35 @@ TEST_CASE("Changes_the_direction_from_west_to_north") REQUIRE(Bearing::NORTH == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_north_to_west") -{ +TEST_CASE("Changes_the_direction_from_north_to_west") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::NORTH}; + const Bearing robot_bearing{Bearing::NORTH}; Robot r{robot_position, robot_bearing}; - + r.turn_left(); - + const std::pair expected_robot_position = robot_position; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::WEST == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_west_to_south") -{ +TEST_CASE("Changes_the_direction_from_west_to_south") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::WEST}; + const Bearing robot_bearing{Bearing::WEST}; Robot r{robot_position, robot_bearing}; - + r.turn_left(); - + const std::pair expected_robot_position = robot_position; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::SOUTH == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_south_to_east") -{ +TEST_CASE("Changes_the_direction_from_south_to_east") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::SOUTH}; + const Bearing robot_bearing{Bearing::SOUTH}; Robot r{robot_position, robot_bearing}; - + r.turn_left(); const std::pair expected_robot_position = robot_position; @@ -122,64 +113,59 @@ TEST_CASE("Changes_the_direction_from_south_to_east") REQUIRE(Bearing::EAST == r.get_bearing()); } -TEST_CASE("Changes_the_direction_from_east_to_north") -{ +TEST_CASE("Changes_the_direction_from_east_to_north") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::EAST}; + const Bearing robot_bearing{Bearing::EAST}; Robot r{robot_position, robot_bearing}; - + r.turn_left(); - + const std::pair expected_robot_position = robot_position; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::NORTH == r.get_bearing()); } -TEST_CASE("Increases_the_y_coordinate_by_one_when_facing_north") -{ +TEST_CASE("Increases_the_y_coordinate_by_one_when_facing_north") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::NORTH}; + const Bearing robot_bearing{Bearing::NORTH}; Robot r{robot_position, robot_bearing}; - + r.advance(); - + const std::pair expected_robot_position{0, 1}; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::NORTH == r.get_bearing()); } -TEST_CASE("Decreases_the_y_coordinate_by_one_when_facing_south") -{ +TEST_CASE("Decreases_the_y_coordinate_by_one_when_facing_south") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::SOUTH}; + const Bearing robot_bearing{Bearing::SOUTH}; Robot r{robot_position, robot_bearing}; - + r.advance(); - + const std::pair expected_robot_position{0, -1}; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::SOUTH == r.get_bearing()); } -TEST_CASE("Increases_the_x_coordinate_by_one_when_facing_east") -{ +TEST_CASE("Increases_the_x_coordinate_by_one_when_facing_east") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::EAST}; + const Bearing robot_bearing{Bearing::EAST}; Robot r{robot_position, robot_bearing}; - + r.advance(); - + const std::pair expected_robot_position{1, 0}; REQUIRE(expected_robot_position == r.get_position()); REQUIRE(Bearing::EAST == r.get_bearing()); } -TEST_CASE("Decreases_the_x_coordinate_by_one_when_facing_west") -{ +TEST_CASE("Decreases_the_x_coordinate_by_one_when_facing_west") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::WEST}; + const Bearing robot_bearing{Bearing::WEST}; Robot r{robot_position, robot_bearing}; - + r.advance(); const std::pair expected_robot_position{-1, 0}; @@ -187,12 +173,11 @@ TEST_CASE("Decreases_the_x_coordinate_by_one_when_facing_west") REQUIRE(Bearing::WEST == r.get_bearing()); } -TEST_CASE("Instructions_to_move_east_and_north_from_readme") -{ +TEST_CASE("Instructions_to_move_east_and_north_from_readme") { const std::pair robot_position{7, 3}; - const Bearing robot_bearing {Bearing::NORTH}; + const Bearing robot_bearing{Bearing::NORTH}; Robot r{robot_position, robot_bearing}; - + r.execute_sequence("RAALAL"); const std::pair expected_robot_position{9, 4}; @@ -200,12 +185,11 @@ TEST_CASE("Instructions_to_move_east_and_north_from_readme") REQUIRE(Bearing::WEST == r.get_bearing()); } -TEST_CASE("Instructions_to_move_west_and_north") -{ +TEST_CASE("Instructions_to_move_west_and_north") { const std::pair robot_position{0, 0}; - const Bearing robot_bearing {Bearing::NORTH}; + const Bearing robot_bearing{Bearing::NORTH}; Robot r{robot_position, robot_bearing}; - + r.execute_sequence("LAAARALA"); const std::pair expected_robot_position{-4, 1}; @@ -213,12 +197,11 @@ TEST_CASE("Instructions_to_move_west_and_north") REQUIRE(Bearing::WEST == r.get_bearing()); } -TEST_CASE("Instructions_to_move_west_and_south") -{ +TEST_CASE("Instructions_to_move_west_and_south") { const std::pair robot_position{2, -7}; - const Bearing robot_bearing {Bearing::EAST}; + const Bearing robot_bearing{Bearing::EAST}; Robot r{robot_position, robot_bearing}; - + r.execute_sequence("RRAAAAALA"); const std::pair expected_robot_position{-3, -8}; @@ -226,12 +209,11 @@ TEST_CASE("Instructions_to_move_west_and_south") REQUIRE(Bearing::SOUTH == r.get_bearing()); } -TEST_CASE("Instructions_to_move_east_and_north") -{ +TEST_CASE("Instructions_to_move_east_and_north") { const std::pair robot_position{8, 4}; - const Bearing robot_bearing {Bearing::SOUTH}; + const Bearing robot_bearing{Bearing::SOUTH}; Robot r{robot_position, robot_bearing}; - + r.execute_sequence("LAAARRRALLLL"); const std::pair expected_robot_position{11, 5}; diff --git a/exercises/practice/roman-numerals/.meta/example.cpp b/exercises/practice/roman-numerals/.meta/example.cpp index 82daeccfa..6428dfee5 100644 --- a/exercises/practice/roman-numerals/.meta/example.cpp +++ b/exercises/practice/roman-numerals/.meta/example.cpp @@ -1,35 +1,23 @@ #include "roman_numerals.h" -namespace -{ +namespace { -struct digit_values -{ +struct digit_values { char numeral; int value; }; -const digit_values roman_numerals[] = -{ - { 'M', 1000 }, - { 'D', 500 }, - { 'C', 100 }, - { 'L', 50 }, - { 'X', 10 }, - { 'V', 5 }, - { 'I', 1 } -}; +const digit_values roman_numerals[] = {{'M', 1000}, {'D', 500}, {'C', 100}, + {'L', 50}, {'X', 10}, {'V', 5}, + {'I', 1}}; -class converter -{ -public: - converter(int n) - : n_(n) - {} +class converter { + public: + converter(int n) : n_(n) {} std::string convert(); -private: + private: void thousands(); void hundreds(); void tens(); @@ -42,8 +30,7 @@ class converter std::string result_; }; -std::string converter::convert() -{ +std::string converter::convert() { thousands(); hundreds(); tens(); @@ -51,28 +38,15 @@ std::string converter::convert() return result_; } -void converter::thousands() -{ - place(0); -} +void converter::thousands() { place(0); } -void converter::hundreds() -{ - place(2); -} +void converter::hundreds() { place(2); } -void converter::tens() -{ - place(4); -} +void converter::tens() { place(4); } -void converter::ones() -{ - result_ += std::string(n_, 'I'); -} +void converter::ones() { result_ += std::string(n_, 'I'); } -void converter::place(int place) -{ +void converter::place(int place) { const int tenth_place = place + 2; place_numeral(place); place_numeral_penultimate(place, tenth_place); @@ -81,17 +55,16 @@ void converter::place(int place) place_numeral_penultimate(half_place, tenth_place); } -void converter::place_numeral(int place) -{ +void converter::place_numeral(int place) { while (n_ >= roman_numerals[place].value) { result_ += roman_numerals[place].numeral; n_ -= roman_numerals[place].value; } } -void converter::place_numeral_penultimate(int place, int penultimate_place) -{ - const int amount = roman_numerals[place].value - roman_numerals[penultimate_place].value; +void converter::place_numeral_penultimate(int place, int penultimate_place) { + const int amount = + roman_numerals[place].value - roman_numerals[penultimate_place].value; if (n_ >= amount) { result_ += roman_numerals[penultimate_place].numeral; result_ += roman_numerals[place].numeral; @@ -99,9 +72,6 @@ void converter::place_numeral_penultimate(int place, int penultimate_place) } } -} +} // namespace -std::string roman_numerals::convert(int n) -{ - return converter(n).convert(); -} +std::string roman_numerals::convert(int n) { return converter(n).convert(); } diff --git a/exercises/practice/roman-numerals/.meta/example.h b/exercises/practice/roman-numerals/.meta/example.h index 580b9666f..b4d0926eb 100644 --- a/exercises/practice/roman-numerals/.meta/example.h +++ b/exercises/practice/roman-numerals/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace roman_numerals -{ +namespace roman_numerals { std::string convert(int n); diff --git a/exercises/practice/roman-numerals/roman_numerals.cpp b/exercises/practice/roman-numerals/roman_numerals.cpp index 359938327..88ee4f8d7 100644 --- a/exercises/practice/roman-numerals/roman_numerals.cpp +++ b/exercises/practice/roman-numerals/roman_numerals.cpp @@ -1,5 +1,3 @@ #include "roman_numerals.h" -namespace roman_numerals { - -} // namespace roman_numerals +namespace roman_numerals {} // namespace roman_numerals diff --git a/exercises/practice/roman-numerals/roman_numerals.h b/exercises/practice/roman-numerals/roman_numerals.h index 491805505..473d1b7d0 100644 --- a/exercises/practice/roman-numerals/roman_numerals.h +++ b/exercises/practice/roman-numerals/roman_numerals.h @@ -1,8 +1,6 @@ #if !defined(ROMAN_NUMERALS_H) #define ROMAN_NUMERALS_H -namespace roman_numerals { +namespace roman_numerals {} // namespace roman_numerals -} // namespace roman_numerals - -#endif // ROMAN_NUMERALS_H \ No newline at end of file +#endif // ROMAN_NUMERALS_H \ No newline at end of file diff --git a/exercises/practice/roman-numerals/roman_numerals_test.cpp b/exercises/practice/roman-numerals/roman_numerals_test.cpp index 5b1395ab3..f36557b4c 100644 --- a/exercises/practice/roman-numerals/roman_numerals_test.cpp +++ b/exercises/practice/roman-numerals/roman_numerals_test.cpp @@ -5,109 +5,41 @@ #include "test/catch.hpp" #endif -TEST_CASE("1_is_i") -{ - REQUIRE("I" == roman_numerals::convert(1)); -} +TEST_CASE("1_is_i") { REQUIRE("I" == roman_numerals::convert(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("2_is_ii") -{ - REQUIRE("II" == roman_numerals::convert(2)); -} -TEST_CASE("3_is_iii") -{ - REQUIRE("III" == roman_numerals::convert(3)); -} -TEST_CASE("4_is_iv") -{ - REQUIRE("IV" == roman_numerals::convert(4)); -} -TEST_CASE("5_is_v") -{ - REQUIRE("V" == roman_numerals::convert(5)); -} -TEST_CASE("6_is_vi") -{ - REQUIRE("VI" == roman_numerals::convert(6)); -} -TEST_CASE("9_is_ix") -{ - REQUIRE("IX" == roman_numerals::convert(9)); -} -TEST_CASE("27_is_xxvii") -{ - REQUIRE("XXVII" == roman_numerals::convert(27)); -} -TEST_CASE("48_is_xlviii") -{ - REQUIRE("XLVIII" == roman_numerals::convert(48)); -} -TEST_CASE("49_is_xlix") -{ - REQUIRE("XLIX" == roman_numerals::convert(49)); -} -TEST_CASE("59_is_lix") -{ - REQUIRE("LIX" == roman_numerals::convert(59)); -} -TEST_CASE("93_is_xciii") -{ - REQUIRE("XCIII" == roman_numerals::convert(93)); -} -TEST_CASE("141_is_cxli") -{ - REQUIRE("CXLI" == roman_numerals::convert(141)); -} -TEST_CASE("163_is_clxiii") -{ +TEST_CASE("2_is_ii") { REQUIRE("II" == roman_numerals::convert(2)); } +TEST_CASE("3_is_iii") { REQUIRE("III" == roman_numerals::convert(3)); } +TEST_CASE("4_is_iv") { REQUIRE("IV" == roman_numerals::convert(4)); } +TEST_CASE("5_is_v") { REQUIRE("V" == roman_numerals::convert(5)); } +TEST_CASE("6_is_vi") { REQUIRE("VI" == roman_numerals::convert(6)); } +TEST_CASE("9_is_ix") { REQUIRE("IX" == roman_numerals::convert(9)); } +TEST_CASE("27_is_xxvii") { REQUIRE("XXVII" == roman_numerals::convert(27)); } +TEST_CASE("48_is_xlviii") { REQUIRE("XLVIII" == roman_numerals::convert(48)); } +TEST_CASE("49_is_xlix") { REQUIRE("XLIX" == roman_numerals::convert(49)); } +TEST_CASE("59_is_lix") { REQUIRE("LIX" == roman_numerals::convert(59)); } +TEST_CASE("93_is_xciii") { REQUIRE("XCIII" == roman_numerals::convert(93)); } +TEST_CASE("141_is_cxli") { REQUIRE("CXLI" == roman_numerals::convert(141)); } +TEST_CASE("163_is_clxiii") { REQUIRE("CLXIII" == roman_numerals::convert(163)); } -TEST_CASE("402_is_cdii") -{ - REQUIRE("CDII" == roman_numerals::convert(402)); -} -TEST_CASE("575_is_dlxxv") -{ - REQUIRE("DLXXV" == roman_numerals::convert(575)); -} -TEST_CASE("911_is_cmxi") -{ - REQUIRE("CMXI" == roman_numerals::convert(911)); -} -TEST_CASE("1024_is_mxxiv") -{ +TEST_CASE("402_is_cdii") { REQUIRE("CDII" == roman_numerals::convert(402)); } +TEST_CASE("575_is_dlxxv") { REQUIRE("DLXXV" == roman_numerals::convert(575)); } +TEST_CASE("911_is_cmxi") { REQUIRE("CMXI" == roman_numerals::convert(911)); } +TEST_CASE("1024_is_mxxiv") { REQUIRE("MXXIV" == roman_numerals::convert(1024)); } -TEST_CASE("3000_is_mmm") -{ - REQUIRE("MMM" == roman_numerals::convert(3000)); -} -TEST_CASE("16_is_xvi") -{ - REQUIRE("XVI" == roman_numerals::convert(16)); -} -TEST_CASE("66_is_lxvi") -{ - REQUIRE("LXVI" == roman_numerals::convert(66)); -} -TEST_CASE("166_is_clxvi") -{ - REQUIRE("CLXVI" == roman_numerals::convert(166)); -} -TEST_CASE("666_is_dclxvi") -{ +TEST_CASE("3000_is_mmm") { REQUIRE("MMM" == roman_numerals::convert(3000)); } +TEST_CASE("16_is_xvi") { REQUIRE("XVI" == roman_numerals::convert(16)); } +TEST_CASE("66_is_lxvi") { REQUIRE("LXVI" == roman_numerals::convert(66)); } +TEST_CASE("166_is_clxvi") { REQUIRE("CLXVI" == roman_numerals::convert(166)); } +TEST_CASE("666_is_dclxvi") { REQUIRE("DCLXVI" == roman_numerals::convert(666)); } -TEST_CASE("1666_is_mdclxvi") -{ +TEST_CASE("1666_is_mdclxvi") { REQUIRE("MDCLXVI" == roman_numerals::convert(1666)); } -TEST_CASE("3001_is_mmmi") -{ - REQUIRE("MMMI" == roman_numerals::convert(3001)); -} -TEST_CASE("3999_is_mmmcmxcix") -{ +TEST_CASE("3001_is_mmmi") { REQUIRE("MMMI" == roman_numerals::convert(3001)); } +TEST_CASE("3999_is_mmmcmxcix") { REQUIRE("MMMCMXCIX" == roman_numerals::convert(3999)); } #endif diff --git a/exercises/practice/rotational-cipher/.meta/example.cpp b/exercises/practice/rotational-cipher/.meta/example.cpp index 48b50e7b6..97e1b7b2f 100644 --- a/exercises/practice/rotational-cipher/.meta/example.cpp +++ b/exercises/practice/rotational-cipher/.meta/example.cpp @@ -1,22 +1,20 @@ -#include "rotational_cipher.h" - #include -namespace rotational_cipher { - std::string rotate(const std::string& text, int shift_key) { +#include "rotational_cipher.h" - std::ostringstream encoded_text; +namespace rotational_cipher { +std::string rotate(const std::string& text, int shift_key) { + std::ostringstream encoded_text; - for(char c : text) { - if (c >= 'a' && c <= 'z') { - c = (c + shift_key - 'a') % 26 + 'a'; - } - else if (c >= 'A' && c <= 'Z') { - c = (c + shift_key - 'A') % 26 + 'A'; - } - encoded_text << c; + for (char c : text) { + if (c >= 'a' && c <= 'z') { + c = (c + shift_key - 'a') % 26 + 'a'; + } else if (c >= 'A' && c <= 'Z') { + c = (c + shift_key - 'A') % 26 + 'A'; } - return encoded_text.str(); + encoded_text << c; } + return encoded_text.str(); +} } // namespace rotational_cipher diff --git a/exercises/practice/rotational-cipher/.meta/example.h b/exercises/practice/rotational-cipher/.meta/example.h index 57de9d273..3aae94766 100644 --- a/exercises/practice/rotational-cipher/.meta/example.h +++ b/exercises/practice/rotational-cipher/.meta/example.h @@ -3,5 +3,5 @@ #include namespace rotational_cipher { - std::string rotate(const std::string& text, int shift_key); +std::string rotate(const std::string& text, int shift_key); } // namespace rotational_cipher diff --git a/exercises/practice/rotational-cipher/rotational_cipher.cpp b/exercises/practice/rotational-cipher/rotational_cipher.cpp index d1732f997..7dbe549bb 100644 --- a/exercises/practice/rotational-cipher/rotational_cipher.cpp +++ b/exercises/practice/rotational-cipher/rotational_cipher.cpp @@ -1,5 +1,3 @@ #include "rotational_cipher.h" -namespace rotational_cipher { - -} // namespace rotational_cipher +namespace rotational_cipher {} // namespace rotational_cipher diff --git a/exercises/practice/rotational-cipher/rotational_cipher.h b/exercises/practice/rotational-cipher/rotational_cipher.h index db7b9e503..5b1e32078 100644 --- a/exercises/practice/rotational-cipher/rotational_cipher.h +++ b/exercises/practice/rotational-cipher/rotational_cipher.h @@ -2,6 +2,4 @@ #include -namespace rotational_cipher { - -} // namespace rotational_cipher +namespace rotational_cipher {} // namespace rotational_cipher diff --git a/exercises/practice/rotational-cipher/rotational_cipher_test.cpp b/exercises/practice/rotational-cipher/rotational_cipher_test.cpp index ab198ca18..7fdc11ae0 100644 --- a/exercises/practice/rotational-cipher/rotational_cipher_test.cpp +++ b/exercises/practice/rotational-cipher/rotational_cipher_test.cpp @@ -6,49 +6,56 @@ #endif /* -The tests are a series of rotation tests: +The tests are a series of rotation tests: */ -TEST_CASE("rotate a by 0, same output as input", "[74e58a38-e484-43f1-9466-877a7515e10f]") { - REQUIRE(rotational_cipher::rotate("a", 0) == "a"); +TEST_CASE("rotate a by 0, same output as input", + "[74e58a38-e484-43f1-9466-877a7515e10f]") { + REQUIRE(rotational_cipher::rotate("a", 0) == "a"); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("rotate a by 1", "[7ee352c6-e6b0-4930-b903-d09943ecb8f5]") { - REQUIRE(rotational_cipher::rotate("a", 1) == "b"); + REQUIRE(rotational_cipher::rotate("a", 1) == "b"); } -TEST_CASE("rotate a by 26, same output as input", "[edf0a733-4231-4594-a5ee-46a4009ad764]") { - REQUIRE(rotational_cipher::rotate("a", 26) == "a"); +TEST_CASE("rotate a by 26, same output as input", + "[edf0a733-4231-4594-a5ee-46a4009ad764]") { + REQUIRE(rotational_cipher::rotate("a", 26) == "a"); } TEST_CASE("rotate m by 13", "[e3e82cb9-2a5b-403f-9931-e43213879300]") { - REQUIRE(rotational_cipher::rotate("m", 13) == "z"); + REQUIRE(rotational_cipher::rotate("m", 13) == "z"); } -TEST_CASE("rotate n by 13 with wrap around alphabet", "[19f9eb78-e2ad-4da4-8fe3-9291d47c1709]") { - REQUIRE(rotational_cipher::rotate("n", 13) == "a"); +TEST_CASE("rotate n by 13 with wrap around alphabet", + "[19f9eb78-e2ad-4da4-8fe3-9291d47c1709]") { + REQUIRE(rotational_cipher::rotate("n", 13) == "a"); } TEST_CASE("rotate capital letters", "[a116aef4-225b-4da9-884f-e8023ca6408a]") { - REQUIRE(rotational_cipher::rotate("OMG", 5) == "TRL"); + REQUIRE(rotational_cipher::rotate("OMG", 5) == "TRL"); } TEST_CASE("rotate spaces", "[71b541bb-819c-4dc6-a9c3-132ef9bb737b]") { - REQUIRE(rotational_cipher::rotate("O M G", 5) == "T R L"); + REQUIRE(rotational_cipher::rotate("O M G", 5) == "T R L"); } TEST_CASE("rotate numbers", "[ef32601d-e9ef-4b29-b2b5-8971392282e6]") { - REQUIRE(rotational_cipher::rotate("Testing 1 2 3 testing", 4) == "Xiwxmrk 1 2 3 xiwxmrk"); + REQUIRE(rotational_cipher::rotate("Testing 1 2 3 testing", 4) == + "Xiwxmrk 1 2 3 xiwxmrk"); } TEST_CASE("rotate punctuation", "[32dd74f6-db2b-41a6-b02c-82eb4f93e549]") { - REQUIRE(rotational_cipher::rotate("Let's eat, Grandma!", 21) == "Gzo'n zvo, Bmviyhv!"); + REQUIRE(rotational_cipher::rotate("Let's eat, Grandma!", 21) == + "Gzo'n zvo, Bmviyhv!"); } TEST_CASE("rotate all letters", "[9fb93fe6-42b0-46e6-9ec1-0bf0a062d8c9]") { - REQUIRE(rotational_cipher::rotate("The quick brown fox jumps over the lazy dog.", 13) == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt."); + REQUIRE(rotational_cipher::rotate( + "The quick brown fox jumps over the lazy dog.", 13) == + "Gur dhvpx oebja sbk whzcf bire gur ynml qbt."); } #endif \ No newline at end of file diff --git a/exercises/practice/run-length-encoding/.meta/example.cpp b/exercises/practice/run-length-encoding/.meta/example.cpp index c5ca18eb7..77b66c97a 100644 --- a/exercises/practice/run-length-encoding/.meta/example.cpp +++ b/exercises/practice/run-length-encoding/.meta/example.cpp @@ -1,49 +1,49 @@ -#include "run_length_encoding.h" - #include #include +#include "run_length_encoding.h" + namespace run_length_encoding { - std::string encode(const std::string& text) { - if (text.empty()) return ""; +std::string encode(const std::string& text) { + if (text.empty()) return ""; - std::ostringstream encoded_text; - char last{text[0]}; - int counter{0}; - for (char c : text) { - if (last == c) { - counter += 1; - } else { - if (counter > 1) { - encoded_text << counter; - } - encoded_text << last; - last = c; - counter = 1; + std::ostringstream encoded_text; + char last{text[0]}; + int counter{0}; + for (char c : text) { + if (last == c) { + counter += 1; + } else { + if (counter > 1) { + encoded_text << counter; } + encoded_text << last; + last = c; + counter = 1; } - if (counter > 1) { - encoded_text << counter; - } - encoded_text << last; - - return encoded_text.str(); } + if (counter > 1) { + encoded_text << counter; + } + encoded_text << last; + + return encoded_text.str(); +} - std::string decode(const std::string& text) { - std::ostringstream decoded_text; - int multi = 0; - for (char c : text) { - if( c >= '0' && c <= '9') { - multi = multi * 10 + c - '0'; - } else { - if (multi == 0) multi = 1; - for(int i{}; i < multi; ++i) { - decoded_text << c; - } - multi = 0; +std::string decode(const std::string& text) { + std::ostringstream decoded_text; + int multi = 0; + for (char c : text) { + if (c >= '0' && c <= '9') { + multi = multi * 10 + c - '0'; + } else { + if (multi == 0) multi = 1; + for (int i{}; i < multi; ++i) { + decoded_text << c; } + multi = 0; } - return decoded_text.str(); } + return decoded_text.str(); +} } // namespace run_length_encoding diff --git a/exercises/practice/run-length-encoding/.meta/example.h b/exercises/practice/run-length-encoding/.meta/example.h index 199c24cb0..1ecb14083 100644 --- a/exercises/practice/run-length-encoding/.meta/example.h +++ b/exercises/practice/run-length-encoding/.meta/example.h @@ -3,6 +3,6 @@ #include namespace run_length_encoding { - std::string encode(const std::string& text); - std::string decode(const std::string& text); +std::string encode(const std::string& text); +std::string decode(const std::string& text); } // namespace run_length_encoding diff --git a/exercises/practice/run-length-encoding/run_length_encoding.cpp b/exercises/practice/run-length-encoding/run_length_encoding.cpp index 9c4336c8d..9787186c2 100644 --- a/exercises/practice/run-length-encoding/run_length_encoding.cpp +++ b/exercises/practice/run-length-encoding/run_length_encoding.cpp @@ -1,5 +1,3 @@ #include "run_length_encoding.h" -namespace run_length_encoding { - -} // namespace run_length_encoding +namespace run_length_encoding {} // namespace run_length_encoding diff --git a/exercises/practice/run-length-encoding/run_length_encoding.h b/exercises/practice/run-length-encoding/run_length_encoding.h index 72710e3d5..3e307093e 100644 --- a/exercises/practice/run-length-encoding/run_length_encoding.h +++ b/exercises/practice/run-length-encoding/run_length_encoding.h @@ -1,5 +1,3 @@ #pragma once -namespace run_length_encoding { - -} // namespace run_length_encoding +namespace run_length_encoding {} // namespace run_length_encoding diff --git a/exercises/practice/run-length-encoding/run_length_encoding_test.cpp b/exercises/practice/run-length-encoding/run_length_encoding_test.cpp index 502d9dd9e..f2100c8e2 100644 --- a/exercises/practice/run-length-encoding/run_length_encoding_test.cpp +++ b/exercises/practice/run-length-encoding/run_length_encoding_test.cpp @@ -6,54 +6,60 @@ #endif TEST_CASE("encode empty string", "[encode]") { - REQUIRE(run_length_encoding::encode("") == ""); + REQUIRE(run_length_encoding::encode("") == ""); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("encode single characters only are encoded without count", "[encode]") { - REQUIRE(run_length_encoding::encode("XYZ") == "XYZ"); +TEST_CASE("encode single characters only are encoded without count", + "[encode]") { + REQUIRE(run_length_encoding::encode("XYZ") == "XYZ"); } TEST_CASE("encode string with no single characters", "[encode]") { - REQUIRE(run_length_encoding::encode("AABBBCCCC") == "2A3B4C"); + REQUIRE(run_length_encoding::encode("AABBBCCCC") == "2A3B4C"); } -TEST_CASE("encode single characters mixed with repeated characters", "[encode]") { - REQUIRE(run_length_encoding::encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") == "12WB12W3B24WB"); +TEST_CASE("encode single characters mixed with repeated characters", + "[encode]") { + REQUIRE(run_length_encoding::encode( + "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB") == + "12WB12W3B24WB"); } TEST_CASE("encode multiple whitespace mixed in string", "[encode]") { - REQUIRE(run_length_encoding::encode(" hsqq qww ") == "2 hs2q q2w2 "); + REQUIRE(run_length_encoding::encode(" hsqq qww ") == "2 hs2q q2w2 "); } TEST_CASE("encode lowercase characters", "[encode]") { - REQUIRE(run_length_encoding::encode("aabbbcccc") == "2a3b4c"); + REQUIRE(run_length_encoding::encode("aabbbcccc") == "2a3b4c"); } TEST_CASE("decode run-length decode a string", "[decode]") { - REQUIRE(run_length_encoding::decode("") == ""); + REQUIRE(run_length_encoding::decode("") == ""); } TEST_CASE("decode single characters only", "[decode]") { - REQUIRE(run_length_encoding::decode("XYZ") == "XYZ"); + REQUIRE(run_length_encoding::decode("XYZ") == "XYZ"); } TEST_CASE("decode string with no single characters", "[decode]") { - REQUIRE(run_length_encoding::decode("2A3B4C") == "AABBBCCCC"); + REQUIRE(run_length_encoding::decode("2A3B4C") == "AABBBCCCC"); } TEST_CASE("decode single characters with repeated characters", "[decode]") { - REQUIRE(run_length_encoding::decode("12WB12W3B24WB") == "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"); + REQUIRE(run_length_encoding::decode("12WB12W3B24WB") == + "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"); } TEST_CASE("decode multiple whitespace mixed in string", "[decode]") { - REQUIRE(run_length_encoding::decode("2 hs2q q2w2 ") == " hsqq qww "); + REQUIRE(run_length_encoding::decode("2 hs2q q2w2 ") == " hsqq qww "); } TEST_CASE("decode lowercase string", "[decode]") { - REQUIRE(run_length_encoding::decode("2a3b4c") == "aabbbcccc"); + REQUIRE(run_length_encoding::decode("2a3b4c") == "aabbbcccc"); } TEST_CASE("encode and then decode", "[consistency]") { - REQUIRE(run_length_encoding::decode(run_length_encoding::encode("zzz ZZ zZ")) == "zzz ZZ zZ"); + REQUIRE(run_length_encoding::decode( + run_length_encoding::encode("zzz ZZ zZ")) == "zzz ZZ zZ"); } #endif diff --git a/exercises/practice/say/.meta/example.cpp b/exercises/practice/say/.meta/example.cpp index e59bbe850..63b9835bb 100644 --- a/exercises/practice/say/.meta/example.cpp +++ b/exercises/practice/say/.meta/example.cpp @@ -1,54 +1,43 @@ -#include "say.h" #include #include #include +#include "say.h" + using namespace std; -namespace -{ +namespace { -const string singles_and_teens_names[] = -{ - "zero", "one", "two", "three", "four", - "five", "six", "seven", "eight", "nine", - "ten", "eleven", "twelve", "thirteen", "fourteen", - "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" -}; +const string singles_and_teens_names[] = { + "zero", "one", "two", "three", "four", + "five", "six", "seven", "eight", "nine", + "ten", "eleven", "twelve", "thirteen", "fourteen", + "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; -const string tens_names[] = -{ - "twenty", "thirty", "forty", "fifty", "sixty", - "seventy", "eighty", "ninety" -}; +const string tens_names[] = {"twenty", "thirty", "forty", "fifty", + "sixty", "seventy", "eighty", "ninety"}; typedef unsigned long long number_t; const number_t twenty{20ULL}; const number_t one_hundred{100ULL}; const number_t one_thousand{1000ULL}; -const number_t one_million{one_thousand*one_thousand}; -const number_t one_billion{one_thousand*one_million}; -const number_t one_trillion{one_thousand*one_billion}; +const number_t one_million{one_thousand * one_thousand}; +const number_t one_billion{one_thousand * one_million}; +const number_t one_trillion{one_thousand * one_billion}; -struct -{ +struct { number_t threshold; string name; -} -const units[] = -{ - { one_billion, "billion" }, - { one_million, "million" }, - { one_thousand, "thousand" }, - { one_hundred, "hundred" } -}; - -void in_english(ostream& english, number_t number) -{ +} const units[] = {{one_billion, "billion"}, + {one_million, "million"}, + {one_thousand, "thousand"}, + {one_hundred, "hundred"}}; + +void in_english(ostream& english, number_t number) { for (auto unit : units) { if (number >= unit.threshold) { - in_english(english, number/unit.threshold); + in_english(english, number / unit.threshold); english << ' ' << unit.name; number %= unit.threshold; @@ -60,7 +49,7 @@ void in_english(ostream& english, number_t number) } if (number >= twenty) { - const number_t tens{number/10ULL - 2ULL}; + const number_t tens{number / 10ULL - 2ULL}; english << tens_names[tens]; if (const number_t single{number % 10ULL}) { @@ -71,13 +60,11 @@ void in_english(ostream& english, number_t number) } } -} +} // namespace -namespace say -{ +namespace say { -string in_english(number_t number) -{ +string in_english(number_t number) { if (number >= one_trillion) { throw std::domain_error("argument out of range"); } @@ -87,4 +74,4 @@ string in_english(number_t number) return english.str(); } -} +} // namespace say diff --git a/exercises/practice/say/.meta/example.h b/exercises/practice/say/.meta/example.h index 8cc456ae9..640da0abe 100644 --- a/exercises/practice/say/.meta/example.h +++ b/exercises/practice/say/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace say -{ +namespace say { std::string in_english(unsigned long long number); diff --git a/exercises/practice/say/say.cpp b/exercises/practice/say/say.cpp index 015186697..706e278c6 100644 --- a/exercises/practice/say/say.cpp +++ b/exercises/practice/say/say.cpp @@ -1,5 +1,3 @@ #include "say.h" -namespace say { - -} // namespace say +namespace say {} // namespace say diff --git a/exercises/practice/say/say.h b/exercises/practice/say/say.h index c7bfe5d99..d4df2881c 100644 --- a/exercises/practice/say/say.h +++ b/exercises/practice/say/say.h @@ -1,8 +1,6 @@ #if !defined(SAY_H) #define SAY_H -namespace say { +namespace say {} // namespace say -} // namespace say - -#endif // SAY_H \ No newline at end of file +#endif // SAY_H \ No newline at end of file diff --git a/exercises/practice/say/say_test.cpp b/exercises/practice/say/say_test.cpp index e4005d03f..0aab4599a 100644 --- a/exercises/practice/say/say_test.cpp +++ b/exercises/practice/say/say_test.cpp @@ -5,92 +5,62 @@ #include "test/catch.hpp" #endif -TEST_CASE("zero") -{ - REQUIRE("zero" == say::in_english(0ULL)); -} +TEST_CASE("zero") { REQUIRE("zero" == say::in_english(0ULL)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("one") -{ - REQUIRE("one" == say::in_english(1ULL)); -} +TEST_CASE("one") { REQUIRE("one" == say::in_english(1ULL)); } -TEST_CASE("fourteen") -{ - REQUIRE("fourteen" == say::in_english(14ULL)); -} +TEST_CASE("fourteen") { REQUIRE("fourteen" == say::in_english(14ULL)); } -TEST_CASE("twenty") -{ - REQUIRE("twenty" == say::in_english(20ULL)); -} +TEST_CASE("twenty") { REQUIRE("twenty" == say::in_english(20ULL)); } -TEST_CASE("twenty_two") -{ - REQUIRE("twenty-two" == say::in_english(22ULL)); -} +TEST_CASE("twenty_two") { REQUIRE("twenty-two" == say::in_english(22ULL)); } -TEST_CASE("sixty_nine") -{ - REQUIRE("sixty-nine" == say::in_english(69ULL)); -} +TEST_CASE("sixty_nine") { REQUIRE("sixty-nine" == say::in_english(69ULL)); } -TEST_CASE("one_hundred") -{ - REQUIRE("one hundred" == say::in_english(100ULL)); -} +TEST_CASE("one_hundred") { REQUIRE("one hundred" == say::in_english(100ULL)); } -TEST_CASE("one_hundred_twenty_three") -{ +TEST_CASE("one_hundred_twenty_three") { REQUIRE("one hundred twenty-three" == say::in_english(123ULL)); } -TEST_CASE("one_thousand") -{ +TEST_CASE("one_thousand") { REQUIRE("one thousand" == say::in_english(1000ULL)); } -TEST_CASE("one_thousand_two_hundred_thirty_four") -{ +TEST_CASE("one_thousand_two_hundred_thirty_four") { REQUIRE("one thousand two hundred thirty-four" == say::in_english(1234ULL)); } -TEST_CASE("one_million") -{ - REQUIRE("one million" == say::in_english(1000ULL*1000ULL)); +TEST_CASE("one_million") { + REQUIRE("one million" == say::in_english(1000ULL * 1000ULL)); } -TEST_CASE("one_million_two") -{ - REQUIRE("one million two" == say::in_english(1000ULL*1000ULL + 2ULL)); +TEST_CASE("one_million_two") { + REQUIRE("one million two" == say::in_english(1000ULL * 1000ULL + 2ULL)); } -TEST_CASE("one_million_two_thousand_three_hundred_forty_five") -{ - REQUIRE("one million two thousand three hundred forty-five" == say::in_english(1002345ULL)); +TEST_CASE("one_million_two_thousand_three_hundred_forty_five") { + REQUIRE("one million two thousand three hundred forty-five" == + say::in_english(1002345ULL)); } -TEST_CASE("one_billion") -{ - REQUIRE("one billion" == say::in_english(1000ULL*1000ULL*1000ULL)); +TEST_CASE("one_billion") { + REQUIRE("one billion" == say::in_english(1000ULL * 1000ULL * 1000ULL)); } -TEST_CASE("a_really_big_number") -{ +TEST_CASE("a_really_big_number") { REQUIRE( "nine hundred eighty-seven billion six hundred fifty-four million " "three hundred twenty-one thousand one hundred twenty-three" == say::in_english(987654321123ULL)); } -TEST_CASE("raises_an_error_below_zero") -{ +TEST_CASE("raises_an_error_below_zero") { REQUIRE_THROWS_AS(say::in_english(-1), std::domain_error); } -TEST_CASE("raises_an_error_for_one_trillion") -{ +TEST_CASE("raises_an_error_for_one_trillion") { REQUIRE_THROWS_AS(say::in_english(1000ULL * 1000ULL * 1000ULL * 1000ULL), std::domain_error); } diff --git a/exercises/practice/scrabble-score/.meta/example.cpp b/exercises/practice/scrabble-score/.meta/example.cpp index ce1c1e6f8..79244ffca 100644 --- a/exercises/practice/scrabble-score/.meta/example.cpp +++ b/exercises/practice/scrabble-score/.meta/example.cpp @@ -1,44 +1,42 @@ -#include "scrabble_score.h" #include -namespace scrabble_score -{ +#include "scrabble_score.h" + +namespace scrabble_score { -namespace -{ +namespace { const int letter_scores[26] = { - 1, // A - 3, // B - 3, // C - 2, // D - 1, // E - 4, // F - 2, // G - 4, // H - 1, // I - 8, // J - 5, // K - 1, // L - 3, // M - 1, // N - 1, // O - 3, // P - 10, // Q - 1, // R - 1, // S - 1, // T - 1, // U - 4, // V - 4, // W - 8, // X - 4, // Y - 10 // Z + 1, // A + 3, // B + 3, // C + 2, // D + 1, // E + 4, // F + 2, // G + 4, // H + 1, // I + 8, // J + 5, // K + 1, // L + 3, // M + 1, // N + 1, // O + 3, // P + 10, // Q + 1, // R + 1, // S + 1, // T + 1, // U + 4, // V + 4, // W + 8, // X + 4, // Y + 10 // Z }; } -int score(const std::string &word) -{ +int score(const std::string &word) { int result = 0; for (const char c : word) { if (std::isalpha(c)) { @@ -48,4 +46,4 @@ int score(const std::string &word) return result; } -} +} // namespace scrabble_score diff --git a/exercises/practice/scrabble-score/.meta/example.h b/exercises/practice/scrabble-score/.meta/example.h index 4422f20f3..0163ef4b9 100644 --- a/exercises/practice/scrabble-score/.meta/example.h +++ b/exercises/practice/scrabble-score/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace scrabble_score -{ +namespace scrabble_score { int score(const std::string &word); diff --git a/exercises/practice/scrabble-score/scrabble_score.cpp b/exercises/practice/scrabble-score/scrabble_score.cpp index 133fbe89a..fbab62f18 100644 --- a/exercises/practice/scrabble-score/scrabble_score.cpp +++ b/exercises/practice/scrabble-score/scrabble_score.cpp @@ -1,5 +1,3 @@ #include "scrabble_score.h" -namespace scrabble_score { - -} // namespace scrabble_score +namespace scrabble_score {} // namespace scrabble_score diff --git a/exercises/practice/scrabble-score/scrabble_score.h b/exercises/practice/scrabble-score/scrabble_score.h index ffd01bd9b..394cf223a 100644 --- a/exercises/practice/scrabble-score/scrabble_score.h +++ b/exercises/practice/scrabble-score/scrabble_score.h @@ -1,8 +1,6 @@ #if !defined(SCRABBLE_SCORE_H) #define SCRABBLE_SCORE_H -namespace scrabble_score { +namespace scrabble_score {} // namespace scrabble_score -} // namespace scrabble_score - -#endif // SCRABBLE_SCORE_H \ No newline at end of file +#endif // SCRABBLE_SCORE_H \ No newline at end of file diff --git a/exercises/practice/scrabble-score/scrabble_score_test.cpp b/exercises/practice/scrabble-score/scrabble_score_test.cpp index 730a6a19f..ba0e31580 100644 --- a/exercises/practice/scrabble-score/scrabble_score_test.cpp +++ b/exercises/practice/scrabble-score/scrabble_score_test.cpp @@ -5,34 +5,26 @@ #include "test/catch.hpp" #endif -TEST_CASE("scores_an_empty_word_as_zero") -{ +TEST_CASE("scores_an_empty_word_as_zero") { REQUIRE(0 == scrabble_score::score("")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("scores_a_very_short_word") -{ +TEST_CASE("scores_a_very_short_word") { REQUIRE(1 == scrabble_score::score("a")); } -TEST_CASE("scores_the_word_by_the_number_of_letters") -{ +TEST_CASE("scores_the_word_by_the_number_of_letters") { REQUIRE(6 == scrabble_score::score("street")); } -TEST_CASE("scores_more_complicated_words_with_more") -{ +TEST_CASE("scores_more_complicated_words_with_more") { REQUIRE(22 == scrabble_score::score("quirky")); } -TEST_CASE("scores_case_insensitive_words") -{ +TEST_CASE("scores_case_insensitive_words") { REQUIRE(41 == scrabble_score::score("OXYPHENBUTAZONE")); } -TEST_CASE("scores_z_word") -{ - REQUIRE(12 == scrabble_score::score("zoo")); -} +TEST_CASE("scores_z_word") { REQUIRE(12 == scrabble_score::score("zoo")); } #endif diff --git a/exercises/practice/secret-handshake/.meta/example.cpp b/exercises/practice/secret-handshake/.meta/example.cpp index 04a94cc05..99c99d1f1 100644 --- a/exercises/practice/secret-handshake/.meta/example.cpp +++ b/exercises/practice/secret-handshake/.meta/example.cpp @@ -1,16 +1,17 @@ -#include "secret_handshake.h" -#include -#include #include +#include +#include + +#include "secret_handshake.h" using namespace std; vector secret_handshake::commands(int value) { vector answer; - if (value & (1<<0)) answer.push_back("wink"); - if (value & (1<<1)) answer.push_back("double blink"); - if (value & (1<<2)) answer.push_back("close your eyes"); - if (value & (1<<3)) answer.push_back("jump"); - if (value & (1<<4)) reverse(answer.begin(), answer.end()); + if (value & (1 << 0)) answer.push_back("wink"); + if (value & (1 << 1)) answer.push_back("double blink"); + if (value & (1 << 2)) answer.push_back("close your eyes"); + if (value & (1 << 3)) answer.push_back("jump"); + if (value & (1 << 4)) reverse(answer.begin(), answer.end()); return answer; } diff --git a/exercises/practice/secret-handshake/.meta/example.h b/exercises/practice/secret-handshake/.meta/example.h index 010812fa0..f32ece3be 100644 --- a/exercises/practice/secret-handshake/.meta/example.h +++ b/exercises/practice/secret-handshake/.meta/example.h @@ -1,13 +1,13 @@ #if !defined(SECRET_HANDSHAKE_H_) #define SECRET_HANDSHAKE_H_ -#include #include +#include namespace secret_handshake { std::vector commands(int value); -} // namespace secret_handshake +} // namespace secret_handshake #endif // !SECRET_HANDSHAKE_H_ diff --git a/exercises/practice/secret-handshake/secret_handshake.cpp b/exercises/practice/secret-handshake/secret_handshake.cpp index cf2541ad6..abfd91f23 100644 --- a/exercises/practice/secret-handshake/secret_handshake.cpp +++ b/exercises/practice/secret-handshake/secret_handshake.cpp @@ -1,5 +1,3 @@ #include "secret_handshake.h" -namespace secret_handshake { - -} // namespace secret_handshake +namespace secret_handshake {} // namespace secret_handshake diff --git a/exercises/practice/secret-handshake/secret_handshake.h b/exercises/practice/secret-handshake/secret_handshake.h index 341a7de57..0065fbfcd 100644 --- a/exercises/practice/secret-handshake/secret_handshake.h +++ b/exercises/practice/secret-handshake/secret_handshake.h @@ -1,8 +1,6 @@ #if !defined(SECRET_HANDSHAKE_H) #define SECRET_HANDSHAKE_H -namespace secret_handshake { +namespace secret_handshake {} // namespace secret_handshake -} // namespace secret_handshake - -#endif // SECRET_HANDSHAKE_H +#endif // SECRET_HANDSHAKE_H diff --git a/exercises/practice/secret-handshake/secret_handshake_test.cpp b/exercises/practice/secret-handshake/secret_handshake_test.cpp index 06438e083..42bc8cec7 100644 --- a/exercises/practice/secret-handshake/secret_handshake_test.cpp +++ b/exercises/practice/secret-handshake/secret_handshake_test.cpp @@ -3,70 +3,62 @@ #else #include "test/catch.hpp" #endif -#include "secret_handshake.h" -#include #include +#include + +#include "secret_handshake.h" using namespace std; // Secret-handshake exercise test case data version 1.2.1 -TEST_CASE("wink_for_1") -{ +TEST_CASE("wink_for_1") { REQUIRE(vector{"wink"} == secret_handshake::commands(1)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("double_blink_for_10") -{ +TEST_CASE("double_blink_for_10") { REQUIRE(vector{"double blink"} == secret_handshake::commands(2)); } -TEST_CASE("close_your_eyes_for_100") -{ +TEST_CASE("close_your_eyes_for_100") { REQUIRE(vector{"close your eyes"} == secret_handshake::commands(4)); } -TEST_CASE("jump_for_1000") -{ +TEST_CASE("jump_for_1000") { REQUIRE(vector{"jump"} == secret_handshake::commands(8)); } -TEST_CASE("combine_two_actions") -{ - REQUIRE(vector{"wink", "double blink"} == secret_handshake::commands(3)); +TEST_CASE("combine_two_actions") { + REQUIRE(vector{"wink", "double blink"} == + secret_handshake::commands(3)); } -TEST_CASE("reverse_two_actions") -{ - REQUIRE(vector{"double blink", "wink"} == secret_handshake::commands(19)); +TEST_CASE("reverse_two_actions") { + REQUIRE(vector{"double blink", "wink"} == + secret_handshake::commands(19)); } -TEST_CASE("reversing_one_action_gives_the_same_action") -{ +TEST_CASE("reversing_one_action_gives_the_same_action") { REQUIRE(vector{"jump"} == secret_handshake::commands(24)); } -TEST_CASE("reversing_no_actions_still_gives_no_actions") -{ +TEST_CASE("reversing_no_actions_still_gives_no_actions") { REQUIRE(vector{} == secret_handshake::commands(16)); } -TEST_CASE("all_possible_actions") -{ - REQUIRE(vector{"wink", "double blink", "close your eyes", "jump"} - == secret_handshake::commands(15)); +TEST_CASE("all_possible_actions") { + REQUIRE(vector{"wink", "double blink", "close your eyes", "jump"} == + secret_handshake::commands(15)); } -TEST_CASE("reverse_all_possible_actions") -{ - REQUIRE(vector{"jump", "close your eyes", "double blink", "wink"} - == secret_handshake::commands(31)); +TEST_CASE("reverse_all_possible_actions") { + REQUIRE(vector{"jump", "close your eyes", "double blink", "wink"} == + secret_handshake::commands(31)); } -TEST_CASE("do_nothing_for_zero") -{ +TEST_CASE("do_nothing_for_zero") { REQUIRE(vector{} == secret_handshake::commands(0)); } -#endif // !EXERCISM_RUN_ALL_TESTS +#endif // !EXERCISM_RUN_ALL_TESTS diff --git a/exercises/practice/series/.meta/example.cpp b/exercises/practice/series/.meta/example.cpp index fd1dece47..ee3216f08 100644 --- a/exercises/practice/series/.meta/example.cpp +++ b/exercises/practice/series/.meta/example.cpp @@ -1,30 +1,27 @@ -#include "series.h" #include #include #include #include +#include "series.h" + using namespace std; -namespace series -{ +namespace series { -inline string slice_me(const string &input, unsigned int start, unsigned int window) -{ +inline string slice_me(const string &input, unsigned int start, + unsigned int window) { auto end = start + window; stringstream baby_slice; - for (size_t pos = start; pos < end; pos++) - baby_slice << input[pos]; + for (size_t pos = start; pos < end; pos++) baby_slice << input[pos]; return baby_slice.str(); } -string digits(const string &input) -{ +string digits(const string &input) { return slice_me(input, 0, input.length()); } -vector slice(const string &input, size_t window) -{ +vector slice(const string &input, size_t window) { auto len = input.length(); if (len < window || window < 1) throw domain_error("Window size must be within size of the slice."); @@ -36,4 +33,4 @@ vector slice(const string &input, size_t window) return ginger_slice; } -} +} // namespace series diff --git a/exercises/practice/series/.meta/example.h b/exercises/practice/series/.meta/example.h index 88b35f45c..0c9ce6819 100644 --- a/exercises/practice/series/.meta/example.h +++ b/exercises/practice/series/.meta/example.h @@ -4,13 +4,12 @@ #include #include -namespace series -{ +namespace series { std::string digits(const std::string &input); std::vector slice(const std::string &input, size_t window); -} +} // namespace series #endif diff --git a/exercises/practice/series/series.cpp b/exercises/practice/series/series.cpp index 861bbc694..15a6d7ba5 100644 --- a/exercises/practice/series/series.cpp +++ b/exercises/practice/series/series.cpp @@ -1,5 +1,3 @@ #include "series.h" -namespace series { - -} // namespace series +namespace series {} // namespace series diff --git a/exercises/practice/series/series.h b/exercises/practice/series/series.h index cf125d184..d67b6d3c1 100644 --- a/exercises/practice/series/series.h +++ b/exercises/practice/series/series.h @@ -1,8 +1,6 @@ #if !defined(SERIES_H) #define SERIES_H -namespace series { +namespace series {} // namespace series -} // namespace series - -#endif // SERIES_H \ No newline at end of file +#endif // SERIES_H \ No newline at end of file diff --git a/exercises/practice/series/series_test.cpp b/exercises/practice/series/series_test.cpp index 59a0afdca..2f862d99b 100644 --- a/exercises/practice/series/series_test.cpp +++ b/exercises/practice/series/series_test.cpp @@ -7,9 +7,8 @@ #include using namespace std; -TEST_CASE("slices_of_one_from_one") -{ - const vector expected{ "1" }; +TEST_CASE("slices_of_one_from_one") { + const vector expected{"1"}; const vector actual{series::slice("1", 1)}; @@ -17,68 +16,60 @@ TEST_CASE("slices_of_one_from_one") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("slices_of_one_from_two") -{ - const vector expected{ "1", "2" }; +TEST_CASE("slices_of_one_from_two") { + const vector expected{"1", "2"}; const vector actual{series::slice("12", 1)}; REQUIRE(expected == actual); } -TEST_CASE("slices_of_two") -{ - const vector expected{ "35" }; +TEST_CASE("slices_of_two") { + const vector expected{"35"}; const vector actual{series::slice("35", 2)}; REQUIRE(expected == actual); } -TEST_CASE("slices_of_two_overlap") -{ - const vector expected{ "91", "14", "42" }; +TEST_CASE("slices_of_two_overlap") { + const vector expected{"91", "14", "42"}; const vector actual{series::slice("9142", 2)}; REQUIRE(expected == actual); } -TEST_CASE("slices_can_include_duplicates") -{ - const vector expected{ "777", "777", "777", "777" }; +TEST_CASE("slices_can_include_duplicates") { + const vector expected{"777", "777", "777", "777"}; const vector actual{series::slice("777777", 3)}; REQUIRE(expected == actual); } -TEST_CASE("slices_of_a_long_series") -{ - const vector expected{ "91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243" }; +TEST_CASE("slices_of_a_long_series") { + const vector expected{"91849", "18493", "84939", "49390", + "93904", "39042", "90424", "04243"}; const vector actual{series::slice("918493904243", 5)}; REQUIRE(expected == actual); } -TEST_CASE("slice_length_is_too_large") -{ +TEST_CASE("slice_length_is_too_large") { REQUIRE_THROWS_AS(series::slice("12345", 6), domain_error); } -TEST_CASE("slice_length_cannot_be_zero") -{ +TEST_CASE("slice_length_cannot_be_zero") { REQUIRE_THROWS_AS(series::slice("12345", 0), domain_error); } -TEST_CASE("slice_length_cannot_be_negative") -{ +TEST_CASE("slice_length_cannot_be_negative") { REQUIRE_THROWS_AS(series::slice("123", -1), domain_error); } -TEST_CASE("empty_series_is_invalid") -{ +TEST_CASE("empty_series_is_invalid") { REQUIRE_THROWS_AS(series::slice("", 1), domain_error); } #endif diff --git a/exercises/practice/sieve/.meta/example.cpp b/exercises/practice/sieve/.meta/example.cpp index a6410263d..734975627 100644 --- a/exercises/practice/sieve/.meta/example.cpp +++ b/exercises/practice/sieve/.meta/example.cpp @@ -1,15 +1,14 @@ -#include "sieve.h" #include #include #include -namespace sieve -{ +#include "sieve.h" + +namespace sieve { -std::vector primes(int n) -{ +std::vector primes(int n) { std::vector result; - std::list candidates(n-1); + std::list candidates(n - 1); std::iota(candidates.begin(), candidates.end(), 2); while (!candidates.empty()) { const int next = candidates.front(); @@ -20,4 +19,4 @@ std::vector primes(int n) return result; } -} +} // namespace sieve diff --git a/exercises/practice/sieve/.meta/example.h b/exercises/practice/sieve/.meta/example.h index 6c1aed77e..4687f7598 100644 --- a/exercises/practice/sieve/.meta/example.h +++ b/exercises/practice/sieve/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace sieve -{ +namespace sieve { std::vector primes(int n); diff --git a/exercises/practice/sieve/sieve.cpp b/exercises/practice/sieve/sieve.cpp index 084008693..b8cd8cb93 100644 --- a/exercises/practice/sieve/sieve.cpp +++ b/exercises/practice/sieve/sieve.cpp @@ -1,5 +1,3 @@ #include "sieve.h" -namespace sieve { - -} // namespace sieve +namespace sieve {} // namespace sieve diff --git a/exercises/practice/sieve/sieve.h b/exercises/practice/sieve/sieve.h index 996893436..db01dd221 100644 --- a/exercises/practice/sieve/sieve.h +++ b/exercises/practice/sieve/sieve.h @@ -1,8 +1,6 @@ #if !defined(SIEVE_H) #define SIEVE_H -namespace sieve { +namespace sieve {} // namespace sieve -} // namespace sieve - -#endif // SIEVE_H \ No newline at end of file +#endif // SIEVE_H \ No newline at end of file diff --git a/exercises/practice/sieve/sieve_test.cpp b/exercises/practice/sieve/sieve_test.cpp index dfd6477a5..e6dcef94d 100644 --- a/exercises/practice/sieve/sieve_test.cpp +++ b/exercises/practice/sieve/sieve_test.cpp @@ -5,8 +5,7 @@ #include "test/catch.hpp" #endif -TEST_CASE("no_primes_under_two") -{ +TEST_CASE("no_primes_under_two") { const std::vector expected{}; const std::vector actual = sieve::primes(1); @@ -15,8 +14,7 @@ TEST_CASE("no_primes_under_two") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("find_first_prime") -{ +TEST_CASE("find_first_prime") { const std::vector expected{2}; const std::vector actual = sieve::primes(2); @@ -24,8 +22,7 @@ TEST_CASE("find_first_prime") REQUIRE(expected == actual); } -TEST_CASE("find_primes_up_to_10") -{ +TEST_CASE("find_primes_up_to_10") { const std::vector expected{2, 3, 5, 7}; const std::vector actual = sieve::primes(10); @@ -33,8 +30,7 @@ TEST_CASE("find_primes_up_to_10") REQUIRE(expected == actual); } -TEST_CASE("limit_is_prime") -{ +TEST_CASE("limit_is_prime") { const std::vector expected{2, 3, 5, 7, 11, 13}; const std::vector actual = sieve::primes(13); @@ -42,23 +38,20 @@ TEST_CASE("limit_is_prime") REQUIRE(expected == actual); } -TEST_CASE("find_primes_up_to_1000") -{ +TEST_CASE("find_primes_up_to_1000") { const std::vector expected{ - 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, - 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, - 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, - 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, - 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, - 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, - 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, - 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, - 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, - 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, - 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, - 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, - 967, 971, 977, 983, 991, 997 - }; + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, + 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, + 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, + 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, + 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, + 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, + 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, + 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, + 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, + 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, + 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, + 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997}; const std::vector actual = sieve::primes(1000); diff --git a/exercises/practice/simple-linked-list/.meta/example.cpp b/exercises/practice/simple-linked-list/.meta/example.cpp index 0848ccf00..31a255e13 100644 --- a/exercises/practice/simple-linked-list/.meta/example.cpp +++ b/exercises/practice/simple-linked-list/.meta/example.cpp @@ -1,7 +1,7 @@ -#include "simple_linked_list.h" - #include +#include "simple_linked_list.h" + namespace simple_linked_list { List::~List() { while (head != nullptr) { diff --git a/exercises/practice/simple-linked-list/simple_linked_list_test.cpp b/exercises/practice/simple-linked-list/simple_linked_list_test.cpp index f10edae87..357ea10c7 100644 --- a/exercises/practice/simple-linked-list/simple_linked_list_test.cpp +++ b/exercises/practice/simple-linked-list/simple_linked_list_test.cpp @@ -9,23 +9,20 @@ #endif // Declares a single test. -TEST_CASE("EmptyListHasSizeZero") -{ +TEST_CASE("EmptyListHasSizeZero") { simple_linked_list::List empty{}; REQUIRE(empty.size() == 0); } #ifdef EXERCISM_RUN_ALL_TESTS -TEST_CASE("SingletonListHasSizeOne") -{ +TEST_CASE("SingletonListHasSizeOne") { simple_linked_list::List list{}; list.push(44); REQUIRE(list.size() == 1); } -TEST_CASE("NonEmptyListHasCorrectSize") -{ +TEST_CASE("NonEmptyListHasCorrectSize") { simple_linked_list::List list{}; list.push(44); list.push(42); @@ -34,8 +31,7 @@ TEST_CASE("NonEmptyListHasCorrectSize") REQUIRE(list.size() == 4); } -TEST_CASE("ListHasCorrectSizeAfterPop") -{ +TEST_CASE("ListHasCorrectSizeAfterPop") { simple_linked_list::List list{}; list.push(24); list.push(2); @@ -44,8 +40,7 @@ TEST_CASE("ListHasCorrectSizeAfterPop") REQUIRE(list.size() == 2); } -TEST_CASE("ListHasCorrectSizeAfterPopAndPush") -{ +TEST_CASE("ListHasCorrectSizeAfterPopAndPush") { simple_linked_list::List list{}; list.push(242); list.push(21); @@ -53,11 +48,9 @@ TEST_CASE("ListHasCorrectSizeAfterPopAndPush") list.pop(); list.push(34); REQUIRE(list.size() == 3); - } -TEST_CASE("PopFromSize1") -{ +TEST_CASE("PopFromSize1") { simple_linked_list::List list{}; auto desired = 142; list.push(desired); @@ -65,8 +58,7 @@ TEST_CASE("PopFromSize1") REQUIRE(actual == desired); } -TEST_CASE("PopFromSizeTwo") -{ +TEST_CASE("PopFromSizeTwo") { simple_linked_list::List list{}; auto desired_top = 112; auto desired_bottom = 221; @@ -78,8 +70,7 @@ TEST_CASE("PopFromSizeTwo") REQUIRE(actual_bottom == desired_bottom); } -TEST_CASE("PopAndPushList") -{ +TEST_CASE("PopAndPushList") { simple_linked_list::List list{}; list.push(1); @@ -102,25 +93,21 @@ TEST_CASE("PopAndPushList") REQUIRE(sixth == 6); } - -TEST_CASE("ReverseEmptyList") -{ +TEST_CASE("ReverseEmptyList") { simple_linked_list::List empty{}; empty.reverse(); REQUIRE(empty.size() == 0); - } -TEST_CASE("ReverseNonEmptyList") -{ +TEST_CASE("ReverseNonEmptyList") { simple_linked_list::List list{}; - for(int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { list.push(i); } list.reverse(); - for(int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { REQUIRE(list.pop() == i); } } diff --git a/exercises/practice/space-age/.meta/example.cpp b/exercises/practice/space-age/.meta/example.cpp index 9304a3751..133a7f47b 100644 --- a/exercises/practice/space-age/.meta/example.cpp +++ b/exercises/practice/space-age/.meta/example.cpp @@ -1,11 +1,9 @@ #include "space_age.h" -namespace space_age -{ +namespace space_age { -namespace -{ -const double earth_years_per_second = 1.0/31557600.0; +namespace { +const double earth_years_per_second = 1.0 / 31557600.0; const double earth_years_per_mercury_year = 0.2408467; const double earth_years_per_venus_year = 0.61519726; const double earth_years_per_mars_year = 1.8808158; @@ -13,56 +11,40 @@ const double earth_years_per_jupiter_year = 11.862615; const double earth_years_per_saturn_year = 29.447498; const double earth_years_per_uranus_year = 84.016846; const double earth_years_per_neptune_year = 164.79132; -} +} // namespace -space_age::space_age(unsigned long long secs) - : seconds_(secs) -{ -} +space_age::space_age(unsigned long long secs) : seconds_(secs) {} -unsigned long long space_age::seconds() const -{ - return seconds_; -} +unsigned long long space_age::seconds() const { return seconds_; } -double space_age::on_earth() const -{ - return seconds_*earth_years_per_second; -} +double space_age::on_earth() const { return seconds_ * earth_years_per_second; } -double space_age::on_mercury() const -{ - return on_earth()/earth_years_per_mercury_year; +double space_age::on_mercury() const { + return on_earth() / earth_years_per_mercury_year; } -double space_age::on_venus() const -{ - return on_earth()/earth_years_per_venus_year; +double space_age::on_venus() const { + return on_earth() / earth_years_per_venus_year; } -double space_age::on_mars() const -{ - return on_earth()/earth_years_per_mars_year; +double space_age::on_mars() const { + return on_earth() / earth_years_per_mars_year; } -double space_age::on_jupiter() const -{ - return on_earth()/earth_years_per_jupiter_year; +double space_age::on_jupiter() const { + return on_earth() / earth_years_per_jupiter_year; } -double space_age::on_saturn() const -{ - return on_earth()/earth_years_per_saturn_year; +double space_age::on_saturn() const { + return on_earth() / earth_years_per_saturn_year; } -double space_age::on_uranus() const -{ - return on_earth()/earth_years_per_uranus_year; +double space_age::on_uranus() const { + return on_earth() / earth_years_per_uranus_year; } -double space_age::on_neptune() const -{ - return on_earth()/earth_years_per_neptune_year; +double space_age::on_neptune() const { + return on_earth() / earth_years_per_neptune_year; } -} +} // namespace space_age diff --git a/exercises/practice/space-age/.meta/example.h b/exercises/practice/space-age/.meta/example.h index 3359314e8..303f397a6 100644 --- a/exercises/practice/space-age/.meta/example.h +++ b/exercises/practice/space-age/.meta/example.h @@ -1,12 +1,10 @@ #if !defined(SPACE_AGE_H) #define SPACE_AGE_H -namespace space_age -{ +namespace space_age { -class space_age -{ -public: +class space_age { + public: explicit space_age(unsigned long long secs); unsigned long long seconds() const; @@ -19,10 +17,10 @@ class space_age double on_uranus() const; double on_neptune() const; -private: + private: unsigned long long seconds_; }; -} +} // namespace space_age #endif diff --git a/exercises/practice/space-age/space_age.cpp b/exercises/practice/space-age/space_age.cpp index 9a20f180b..44f44cc86 100644 --- a/exercises/practice/space-age/space_age.cpp +++ b/exercises/practice/space-age/space_age.cpp @@ -1,5 +1,3 @@ #include "space_age.h" -namespace space_age { - -} // namespace space_age +namespace space_age {} // namespace space_age diff --git a/exercises/practice/space-age/space_age.h b/exercises/practice/space-age/space_age.h index 5c239c69f..6c46b4756 100644 --- a/exercises/practice/space-age/space_age.h +++ b/exercises/practice/space-age/space_age.h @@ -1,8 +1,6 @@ #if !defined(SPACE_AGE_H) #define SPACE_AGE_H -namespace space_age { +namespace space_age {} // namespace space_age -} // namespace space_age - -#endif // SPACE_AGE_H \ No newline at end of file +#endif // SPACE_AGE_H \ No newline at end of file diff --git a/exercises/practice/space-age/space_age_test.cpp b/exercises/practice/space-age/space_age_test.cpp index 027d3ff0e..0cbd96982 100644 --- a/exercises/practice/space-age/space_age_test.cpp +++ b/exercises/practice/space-age/space_age_test.cpp @@ -5,76 +5,67 @@ #include "test/catch.hpp" #endif -TEST_CASE("age_in_seconds") -{ +TEST_CASE("age_in_seconds") { const space_age::space_age age(1000000); REQUIRE(age.seconds() == 1000000); } #if defined(EXERCISM_RUN_ALL_TESTS) -namespace -{ +namespace { const double accuracy = 0.005; } -TEST_CASE("age_in_earth_years") -{ +TEST_CASE("age_in_earth_years") { const space_age::space_age age(1000000000); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(31.69, accuracy)); } -TEST_CASE("age_in_mercury_years") -{ +TEST_CASE("age_in_mercury_years") { const space_age::space_age age(2134835688); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(67.65, accuracy)); - REQUIRE_THAT(age.on_mercury(), Catch::Matchers::WithinAbs(280.88, accuracy)); + REQUIRE_THAT(age.on_mercury(), + Catch::Matchers::WithinAbs(280.88, accuracy)); } -TEST_CASE("age_in_venus_years") -{ +TEST_CASE("age_in_venus_years") { const space_age::space_age age(189839836); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(6.02, accuracy)); REQUIRE_THAT(age.on_venus(), Catch::Matchers::WithinAbs(9.78, accuracy)); } -TEST_CASE("age_in_mars_years") -{ +TEST_CASE("age_in_mars_years") { const space_age::space_age age(2329871239); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(73.83, accuracy)); REQUIRE_THAT(age.on_mars(), Catch::Matchers::WithinAbs(39.25, accuracy)); } -TEST_CASE("age_in_jupiter_years") -{ +TEST_CASE("age_in_jupiter_years") { const space_age::space_age age(901876382); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(28.58, accuracy)); REQUIRE_THAT(age.on_jupiter(), Catch::Matchers::WithinAbs(2.41, accuracy)); } -TEST_CASE("age_in_saturn_years") -{ +TEST_CASE("age_in_saturn_years") { const space_age::space_age age(3000000000); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(95.06, accuracy)); REQUIRE_THAT(age.on_saturn(), Catch::Matchers::WithinAbs(3.23, accuracy)); } -TEST_CASE("age_in_uranus_years") -{ +TEST_CASE("age_in_uranus_years") { const space_age::space_age age(3210123456); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(101.72, accuracy)); REQUIRE_THAT(age.on_uranus(), Catch::Matchers::WithinAbs(1.21, accuracy)); } -TEST_CASE("age_in_neptune_year") -{ +TEST_CASE("age_in_neptune_year") { const space_age::space_age age(8210123456); REQUIRE_THAT(age.on_earth(), Catch::Matchers::WithinAbs(260.16, accuracy)); diff --git a/exercises/practice/spiral-matrix/spiral_matrix.cpp b/exercises/practice/spiral-matrix/spiral_matrix.cpp index 3428b3936..f82c8ad79 100644 --- a/exercises/practice/spiral-matrix/spiral_matrix.cpp +++ b/exercises/practice/spiral-matrix/spiral_matrix.cpp @@ -1,5 +1,3 @@ #include "spiral_matrix.h" -namespace spiral_matrix { - -} // namespace spiral_matrix +namespace spiral_matrix {} // namespace spiral_matrix diff --git a/exercises/practice/spiral-matrix/spiral_matrix.h b/exercises/practice/spiral-matrix/spiral_matrix.h index cc56ad3f0..035611eb4 100644 --- a/exercises/practice/spiral-matrix/spiral_matrix.h +++ b/exercises/practice/spiral-matrix/spiral_matrix.h @@ -1,8 +1,6 @@ #if !defined(SPIRAL_MATRIX_H) #define SPIRAL_MATRIX_H -namespace spiral_matrix { - -} // namespace spiral_matrix +namespace spiral_matrix {} // namespace spiral_matrix #endif // SPIRAL_MATRIX_H diff --git a/exercises/practice/sublist/.meta/example.cpp b/exercises/practice/sublist/.meta/example.cpp index 52b418a52..adf92b78a 100644 --- a/exercises/practice/sublist/.meta/example.cpp +++ b/exercises/practice/sublist/.meta/example.cpp @@ -1,8 +1,8 @@ -#include "sublist.h" - #include #include +#include "sublist.h" + namespace sublist { bool is_sublist(const std::vector& sublist, const std::vector& superlist) { diff --git a/exercises/practice/sublist/.meta/example.h b/exercises/practice/sublist/.meta/example.h index 559f59a2d..0861fabca 100644 --- a/exercises/practice/sublist/.meta/example.h +++ b/exercises/practice/sublist/.meta/example.h @@ -3,7 +3,8 @@ #include namespace sublist { - enum class List_comparison { equal, sublist, superlist, unequal }; - - List_comparison sublist(const std::vector& list_one, const std::vector& list_two); +enum class List_comparison { equal, sublist, superlist, unequal }; + +List_comparison sublist(const std::vector& list_one, + const std::vector& list_two); } // namespace sublist diff --git a/exercises/practice/sublist/sublist.cpp b/exercises/practice/sublist/sublist.cpp index cc9725bd9..216579aef 100644 --- a/exercises/practice/sublist/sublist.cpp +++ b/exercises/practice/sublist/sublist.cpp @@ -1,5 +1,3 @@ #include "sublist.h" -namespace sublist { - -} // namespace sublist +namespace sublist {} // namespace sublist diff --git a/exercises/practice/sublist/sublist.h b/exercises/practice/sublist/sublist.h index 475b698f5..bd69a2148 100644 --- a/exercises/practice/sublist/sublist.h +++ b/exercises/practice/sublist/sublist.h @@ -1,5 +1,3 @@ #pragma once -namespace sublist { - -} // namespace sublist +namespace sublist {} // namespace sublist diff --git a/exercises/practice/sublist/sublist_test.cpp b/exercises/practice/sublist/sublist_test.cpp index 2e4b070c5..398b6c224 100644 --- a/exercises/practice/sublist/sublist_test.cpp +++ b/exercises/practice/sublist/sublist_test.cpp @@ -5,7 +5,6 @@ #include "test/catch.hpp" #endif - /* Lists are ordered and sequential. https://en.wikipedia.org/wiki/List_%28abstract_data_type%29 @@ -15,107 +14,113 @@ to go from the JSON array to the list representation. The expectation can be used to generate an expected value based on your implementation (such as a constant 'EQUAL', 'SUBLIST', etc.). -If appropriate for your track, you'll need to ensure that no pair of expected values are equal. -Otherwise, an implementation that always returns a constant value may falsely pass the tests. -See https://github.com/exercism/xpython/issues/342 +If appropriate for your track, you'll need to ensure that no pair of expected +values are equal. Otherwise, an implementation that always returns a constant +value may falsely pass the tests. See +https://github.com/exercism/xpython/issues/342 */ -CATCH_REGISTER_ENUM(sublist::List_comparison, - sublist::List_comparison::equal, - sublist::List_comparison::sublist, - sublist::List_comparison::superlist, - sublist::List_comparison::unequal) +CATCH_REGISTER_ENUM(sublist::List_comparison, sublist::List_comparison::equal, + sublist::List_comparison::sublist, + sublist::List_comparison::superlist, + sublist::List_comparison::unequal) TEST_CASE("empty lists", "[97319c93-ebc5-47ab-a022-02a1980e1d29]") { - sublist::List_comparison expected = sublist::List_comparison::equal; - REQUIRE(expected == sublist::sublist({}, {})); + sublist::List_comparison expected = sublist::List_comparison::equal; + REQUIRE(expected == sublist::sublist({}, {})); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("empty list within non empty list", "[de27dbd4-df52-46fe-a336-30be58457382]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({}, {1, 2, 3})); +TEST_CASE("empty list within non empty list", + "[de27dbd4-df52-46fe-a336-30be58457382]") { + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({}, {1, 2, 3})); } -TEST_CASE("non empty list contains empty list", "[5487cfd1-bc7d-429f-ac6f-1177b857d4fb]") { - sublist::List_comparison expected = sublist::List_comparison::superlist; - REQUIRE(expected == sublist::sublist({1, 2, 3}, {})); +TEST_CASE("non empty list contains empty list", + "[5487cfd1-bc7d-429f-ac6f-1177b857d4fb]") { + sublist::List_comparison expected = sublist::List_comparison::superlist; + REQUIRE(expected == sublist::sublist({1, 2, 3}, {})); } TEST_CASE("list equals itself", "[1f390b47-f6b2-4a93-bc23-858ba5dda9a6]") { - sublist::List_comparison expected = sublist::List_comparison::equal; - REQUIRE(expected == sublist::sublist({1, 2, 3}, {1, 2, 3})); + sublist::List_comparison expected = sublist::List_comparison::equal; + REQUIRE(expected == sublist::sublist({1, 2, 3}, {1, 2, 3})); } TEST_CASE("different lists", "[7ed2bfb2-922b-4363-ae75-f3a05e8274f5]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 2, 3}, {2, 3, 4})); + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 2, 3}, {2, 3, 4})); } TEST_CASE("false start", "[3b8a2568-6144-4f06-b0a1-9d266b365341]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({1, 2, 5}, {0, 1, 2, 3, 1, 2, 5, 6})); + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({1, 2, 5}, {0, 1, 2, 3, 1, 2, 5, 6})); } TEST_CASE("consecutive", "[dc39ed58-6311-4814-be30-05a64bc8d9b1]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({1, 1, 2}, {0, 1, 1, 1, 2, 1, 2})); + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({1, 1, 2}, {0, 1, 1, 1, 2, 1, 2})); } TEST_CASE("sublist at start", "[d1270dab-a1ce-41aa-b29d-b3257241ac26]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({0, 1, 2}, {0, 1, 2, 3, 4, 5})); + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({0, 1, 2}, {0, 1, 2, 3, 4, 5})); } TEST_CASE("sublist in middle", "[81f3d3f7-4f25-4ada-bcdc-897c403de1b6]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({2, 3, 4}, {0, 1, 2, 3, 4, 5})); + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({2, 3, 4}, {0, 1, 2, 3, 4, 5})); } TEST_CASE("sublist at end", "[43bcae1e-a9cf-470e-923e-0946e04d8fdd]") { - sublist::List_comparison expected = sublist::List_comparison::sublist; - REQUIRE(expected == sublist::sublist({3, 4, 5}, {0, 1, 2, 3, 4, 5})); + sublist::List_comparison expected = sublist::List_comparison::sublist; + REQUIRE(expected == sublist::sublist({3, 4, 5}, {0, 1, 2, 3, 4, 5})); } TEST_CASE("at start of superlist", "[76cf99ed-0ff0-4b00-94af-4dfb43fe5caa]") { - sublist::List_comparison expected = sublist::List_comparison::superlist; - REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {0, 1, 2})); + sublist::List_comparison expected = sublist::List_comparison::superlist; + REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {0, 1, 2})); } TEST_CASE("in middle of superlist", "[b83989ec-8bdf-4655-95aa-9f38f3e357fd]") { - sublist::List_comparison expected = sublist::List_comparison::superlist; - REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {2, 3})); + sublist::List_comparison expected = sublist::List_comparison::superlist; + REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {2, 3})); } TEST_CASE("at end of superlist", "[26f9f7c3-6cf6-4610-984a-662f71f8689b]") { - sublist::List_comparison expected = sublist::List_comparison::superlist; - REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {3, 4, 5})); + sublist::List_comparison expected = sublist::List_comparison::superlist; + REQUIRE(expected == sublist::sublist({0, 1, 2, 3, 4, 5}, {3, 4, 5})); } -TEST_CASE("first list missing element from second list", "[0a6db763-3588-416a-8f47-76b1cedde31e]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 3}, {1, 2, 3})); +TEST_CASE("first list missing element from second list", + "[0a6db763-3588-416a-8f47-76b1cedde31e]") { + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 3}, {1, 2, 3})); } -TEST_CASE("second list missing element from first list", "[83ffe6d8-a445-4a3c-8795-1e51a95e65c3]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 2, 3}, {1, 3})); +TEST_CASE("second list missing element from first list", + "[83ffe6d8-a445-4a3c-8795-1e51a95e65c3]") { + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 2, 3}, {1, 3})); } -TEST_CASE("first list missing additional digits from second list", "[7bc76cb8-5003-49ca-bc47-cdfbe6c2bb89]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 2}, {1, 22})); +TEST_CASE("first list missing additional digits from second list", + "[7bc76cb8-5003-49ca-bc47-cdfbe6c2bb89]") { + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 2}, {1, 22})); } TEST_CASE("order matters to a list", "[0d7ee7c1-0347-45c8-9ef5-b88db152b30b]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 2, 3}, {3, 2, 1})); + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 2, 3}, {3, 2, 1})); } -TEST_CASE("same digits but different numbers", "[5f47ce86-944e-40f9-9f31-6368aad70aa6]") { - sublist::List_comparison expected = sublist::List_comparison::unequal; - REQUIRE(expected == sublist::sublist({1, 0, 1}, {10, 1})); +TEST_CASE("same digits but different numbers", + "[5f47ce86-944e-40f9-9f31-6368aad70aa6]") { + sublist::List_comparison expected = sublist::List_comparison::unequal; + REQUIRE(expected == sublist::sublist({1, 0, 1}, {10, 1})); } #endif diff --git a/exercises/practice/sum-of-multiples/.meta/example.cpp b/exercises/practice/sum-of-multiples/.meta/example.cpp index 1998a5108..6aa2eafd5 100644 --- a/exercises/practice/sum-of-multiples/.meta/example.cpp +++ b/exercises/practice/sum-of-multiples/.meta/example.cpp @@ -1,10 +1,8 @@ #include "sum_of_multiples.h" -namespace sum_of_multiples -{ +namespace sum_of_multiples { -int to(std::initializer_list const& multiples, int num) -{ +int to(std::initializer_list const& multiples, int num) { int sum = 0; for (int i = 0; i < num; ++i) { for (const int multiple : multiples) { @@ -17,4 +15,4 @@ int to(std::initializer_list const& multiples, int num) return sum; } -} +} // namespace sum_of_multiples diff --git a/exercises/practice/sum-of-multiples/.meta/example.h b/exercises/practice/sum-of-multiples/.meta/example.h index 5b9aa26e6..8b0b3d6ea 100644 --- a/exercises/practice/sum-of-multiples/.meta/example.h +++ b/exercises/practice/sum-of-multiples/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace sum_of_multiples -{ +namespace sum_of_multiples { int to(std::initializer_list const& multiples, int num); diff --git a/exercises/practice/sum-of-multiples/sum_of_multiples.cpp b/exercises/practice/sum-of-multiples/sum_of_multiples.cpp index b7bab6389..e5d0da61a 100644 --- a/exercises/practice/sum-of-multiples/sum_of_multiples.cpp +++ b/exercises/practice/sum-of-multiples/sum_of_multiples.cpp @@ -1,5 +1,3 @@ #include "sum_of_multiples.h" -namespace sum_of_multiples { - -} // namespace sum_of_multiples +namespace sum_of_multiples {} // namespace sum_of_multiples diff --git a/exercises/practice/sum-of-multiples/sum_of_multiples.h b/exercises/practice/sum-of-multiples/sum_of_multiples.h index 5a57d1e0d..eea744443 100644 --- a/exercises/practice/sum-of-multiples/sum_of_multiples.h +++ b/exercises/practice/sum-of-multiples/sum_of_multiples.h @@ -1,8 +1,6 @@ #if !defined(SUM_OF_MULTIPLES_H) #define SUM_OF_MULTIPLES_H -namespace sum_of_multiples { +namespace sum_of_multiples {} // namespace sum_of_multiples -} // namespace sum_of_multiples - -#endif // SUM_OF_MULTIPLES_H \ No newline at end of file +#endif // SUM_OF_MULTIPLES_H \ No newline at end of file diff --git a/exercises/practice/sum-of-multiples/sum_of_multiples_test.cpp b/exercises/practice/sum-of-multiples/sum_of_multiples_test.cpp index bedc6eb8e..5f3ac0a89 100644 --- a/exercises/practice/sum-of-multiples/sum_of_multiples_test.cpp +++ b/exercises/practice/sum-of-multiples/sum_of_multiples_test.cpp @@ -5,64 +5,50 @@ #include "test/catch.hpp" #endif -TEST_CASE("sum_to_1_yields_0") -{ +TEST_CASE("sum_to_1_yields_0") { REQUIRE(0 == sum_of_multiples::to({3, 5}, 0)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("sum_to_4_yields_3") -{ +TEST_CASE("sum_to_4_yields_3") { REQUIRE(3 == sum_of_multiples::to({3, 5}, 4)); } -TEST_CASE("sum_to_10_yields_23") -{ +TEST_CASE("sum_to_10_yields_23") { REQUIRE(23 == sum_of_multiples::to({3, 5}, 10)); } -TEST_CASE("sum_to_100") -{ - REQUIRE(2318 == sum_of_multiples::to({3, 5}, 100)); -} +TEST_CASE("sum_to_100") { REQUIRE(2318 == sum_of_multiples::to({3, 5}, 100)); } -TEST_CASE("sum_to_1000") -{ +TEST_CASE("sum_to_1000") { REQUIRE(233168 == sum_of_multiples::to({3, 5}, 1000)); } -TEST_CASE("sum_of_7_13_17_to_20_yields_51") -{ +TEST_CASE("sum_of_7_13_17_to_20_yields_51") { REQUIRE(51 == sum_of_multiples::to({7, 13, 17}, 20)); } -TEST_CASE("sum_of_4_6_to_15") -{ +TEST_CASE("sum_of_4_6_to_15") { REQUIRE(30 == sum_of_multiples::to({4, 6}, 15)); } -TEST_CASE("sum_of_5_6_8_to_150") -{ +TEST_CASE("sum_of_5_6_8_to_150") { REQUIRE(4419 == sum_of_multiples::to({5, 6, 8}, 150)); } -TEST_CASE("sum_of_5_25_to_51") -{ +TEST_CASE("sum_of_5_25_to_51") { REQUIRE(275 == sum_of_multiples::to({5, 25}, 51)); } -TEST_CASE("sum_of_43_47_to_10000") -{ +TEST_CASE("sum_of_43_47_to_10000") { REQUIRE(2203160 == sum_of_multiples::to({43, 47}, 10000)); } -TEST_CASE("sum_of_1_to_100") -{ +TEST_CASE("sum_of_1_to_100") { REQUIRE(4950 == sum_of_multiples::to({1}, 100)); } -TEST_CASE("sum_of_empty_list") -{ +TEST_CASE("sum_of_empty_list") { REQUIRE(0 == sum_of_multiples::to({}, 10000)); } #endif diff --git a/exercises/practice/triangle/.meta/example.cpp b/exercises/practice/triangle/.meta/example.cpp index 7ee9069bd..2634cec15 100644 --- a/exercises/practice/triangle/.meta/example.cpp +++ b/exercises/practice/triangle/.meta/example.cpp @@ -1,23 +1,18 @@ -#include "triangle.h" #include -namespace triangle -{ +#include "triangle.h" -namespace -{ +namespace triangle { -bool triangle_equality(double a, double b, double c) -{ - return a < (b + c) - && b < (a + c) - && c < (a + b); -} +namespace { +bool triangle_equality(double a, double b, double c) { + return a < (b + c) && b < (a + c) && c < (a + b); } -flavor kind(double a, double b, double c) -{ +} // namespace + +flavor kind(double a, double b, double c) { if (a == 0 || b == 0 || c == 0) { throw std::domain_error("Zero triangle"); } @@ -33,4 +28,4 @@ flavor kind(double a, double b, double c) return flavor::scalene; } -} +} // namespace triangle diff --git a/exercises/practice/triangle/.meta/example.h b/exercises/practice/triangle/.meta/example.h index 92ab4a81d..cd82173c3 100644 --- a/exercises/practice/triangle/.meta/example.h +++ b/exercises/practice/triangle/.meta/example.h @@ -1,18 +1,12 @@ #if !defined(TRIANGLE_H) #define TRIANGLE_H -namespace triangle -{ +namespace triangle { -enum class flavor -{ - equilateral, - isosceles, - scalene -}; +enum class flavor { equilateral, isosceles, scalene }; flavor kind(double a, double b, double c); -} +} // namespace triangle #endif diff --git a/exercises/practice/triangle/triangle.cpp b/exercises/practice/triangle/triangle.cpp index 124cbe322..2145e12e4 100644 --- a/exercises/practice/triangle/triangle.cpp +++ b/exercises/practice/triangle/triangle.cpp @@ -1,5 +1,3 @@ #include "triangle.h" -namespace triangle { - -} // namespace triangle +namespace triangle {} // namespace triangle diff --git a/exercises/practice/triangle/triangle.h b/exercises/practice/triangle/triangle.h index 94c1d6523..879d8b974 100644 --- a/exercises/practice/triangle/triangle.h +++ b/exercises/practice/triangle/triangle.h @@ -1,8 +1,6 @@ #if !defined(TRIANGLE_H) #define TRIANGLE_H -namespace triangle { +namespace triangle {} // namespace triangle -} // namespace triangle - -#endif // TRIANGLE_H \ No newline at end of file +#endif // TRIANGLE_H \ No newline at end of file diff --git a/exercises/practice/triangle/triangle_test.cpp b/exercises/practice/triangle/triangle_test.cpp index df338b7e8..ca7059ed5 100644 --- a/exercises/practice/triangle/triangle_test.cpp +++ b/exercises/practice/triangle/triangle_test.cpp @@ -7,84 +7,67 @@ #include // improves error messages with triangle flavor enum text instead of integers: -CATCH_REGISTER_ENUM(triangle::flavor, - triangle::flavor::equilateral, - triangle::flavor::isosceles, - triangle::flavor::scalene) +CATCH_REGISTER_ENUM(triangle::flavor, triangle::flavor::equilateral, + triangle::flavor::isosceles, triangle::flavor::scalene) -TEST_CASE("equilateral_triangles_have_equal_sides") -{ +TEST_CASE("equilateral_triangles_have_equal_sides") { REQUIRE(triangle::flavor::equilateral == triangle::kind(2, 2, 2)); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("larger_equilateral_triangles_also_have_equal_sides") -{ +TEST_CASE("larger_equilateral_triangles_also_have_equal_sides") { REQUIRE(triangle::flavor::equilateral == triangle::kind(10, 10, 10)); } -TEST_CASE("isosceles_triangles_have_last_two_sides_equal") -{ +TEST_CASE("isosceles_triangles_have_last_two_sides_equal") { REQUIRE(triangle::flavor::isosceles == triangle::kind(3, 4, 4)); } -TEST_CASE("isosceles_triangles_have_first_and_last_sides_equal") -{ +TEST_CASE("isosceles_triangles_have_first_and_last_sides_equal") { REQUIRE(triangle::flavor::isosceles == triangle::kind(4, 3, 4)); } -TEST_CASE("isosceles_triangles_have_first_two_sides_equal") -{ +TEST_CASE("isosceles_triangles_have_first_two_sides_equal") { REQUIRE(triangle::flavor::isosceles == triangle::kind(4, 4, 3)); } -TEST_CASE("isosceles_triangles_have_in_fact_exactly_two_sides_equal") -{ +TEST_CASE("isosceles_triangles_have_in_fact_exactly_two_sides_equal") { REQUIRE(triangle::flavor::isosceles == triangle::kind(10, 10, 2)); } -TEST_CASE("scalene_triangles_have_no_equal_sides") -{ +TEST_CASE("scalene_triangles_have_no_equal_sides") { REQUIRE(triangle::flavor::scalene == triangle::kind(3, 4, 5)); } -TEST_CASE("scalene_triangles_have_no_equal_sides_at_a_larger_scale_too") -{ +TEST_CASE("scalene_triangles_have_no_equal_sides_at_a_larger_scale_too") { REQUIRE(triangle::flavor::scalene == triangle::kind(10, 11, 12)); } -TEST_CASE("scalene_triangles_have_no_equal_sides_in_descending_order_either") -{ +TEST_CASE("scalene_triangles_have_no_equal_sides_in_descending_order_either") { REQUIRE(triangle::flavor::scalene == triangle::kind(5, 4, 2)); } -TEST_CASE("very_small_triangles_are_legal") -{ +TEST_CASE("very_small_triangles_are_legal") { REQUIRE(triangle::flavor::scalene == triangle::kind(0.4, 0.6, 0.3)); } -TEST_CASE("triangles_with_no_size_are_illegal") -{ +TEST_CASE("triangles_with_no_size_are_illegal") { REQUIRE_THROWS_AS(triangle::kind(0, 0, 0), std::domain_error); } -TEST_CASE("triangles_with_negative_sides_are_illegal") -{ +TEST_CASE("triangles_with_negative_sides_are_illegal") { REQUIRE_THROWS_AS(triangle::kind(3, 4, -5), std::domain_error); } -TEST_CASE("triangles_violating_triangle_inequality_are_illegal") -{ +TEST_CASE("triangles_violating_triangle_inequality_are_illegal") { REQUIRE_THROWS_AS(triangle::kind(1, 1, 3), std::domain_error); } -TEST_CASE("larger_triangles_violating_triangle_inequality_are_illegal") -{ +TEST_CASE("larger_triangles_violating_triangle_inequality_are_illegal") { REQUIRE_THROWS_AS(triangle::kind(7, 3, 2), std::domain_error); } -TEST_CASE("double_and_integer_arguments") -{ +TEST_CASE("double_and_integer_arguments") { REQUIRE(triangle::flavor::scalene == triangle::kind(5.5, 4, 2)); } #endif diff --git a/exercises/practice/trinary/.meta/example.cpp b/exercises/practice/trinary/.meta/example.cpp index 91c348d60..3125be2b8 100644 --- a/exercises/practice/trinary/.meta/example.cpp +++ b/exercises/practice/trinary/.meta/example.cpp @@ -1,10 +1,8 @@ #include "trinary.h" -namespace trinary -{ +namespace trinary { -int to_decimal(std::string const &text) -{ +int to_decimal(std::string const &text) { int result = 0; for (const char digit : text) { if (digit < '0' || digit > '2') { @@ -16,4 +14,4 @@ int to_decimal(std::string const &text) return result; } -} +} // namespace trinary diff --git a/exercises/practice/trinary/.meta/example.h b/exercises/practice/trinary/.meta/example.h index da061493e..d80592bfe 100644 --- a/exercises/practice/trinary/.meta/example.h +++ b/exercises/practice/trinary/.meta/example.h @@ -3,8 +3,7 @@ #include -namespace trinary -{ +namespace trinary { int to_decimal(std::string const &text); diff --git a/exercises/practice/trinary/trinary.cpp b/exercises/practice/trinary/trinary.cpp index ac469759b..0374d1b5b 100644 --- a/exercises/practice/trinary/trinary.cpp +++ b/exercises/practice/trinary/trinary.cpp @@ -1,5 +1,3 @@ #include "trinary.h" -namespace trinary { - -} // namespace trinary +namespace trinary {} // namespace trinary diff --git a/exercises/practice/trinary/trinary.h b/exercises/practice/trinary/trinary.h index cb4e95a57..b9320bd78 100644 --- a/exercises/practice/trinary/trinary.h +++ b/exercises/practice/trinary/trinary.h @@ -1,8 +1,6 @@ #if !defined(TRINARY_H) #define TRINARY_H -namespace trinary { +namespace trinary {} // namespace trinary -} // namespace trinary - -#endif // TRINARY_H \ No newline at end of file +#endif // TRINARY_H \ No newline at end of file diff --git a/exercises/practice/trinary/trinary_test.cpp b/exercises/practice/trinary/trinary_test.cpp index eaf14237a..26a898f45 100644 --- a/exercises/practice/trinary/trinary_test.cpp +++ b/exercises/practice/trinary/trinary_test.cpp @@ -5,49 +5,30 @@ #include "test/catch.hpp" #endif -TEST_CASE("_1_yields_decimal_1") -{ - REQUIRE(1 == trinary::to_decimal("1")); -} +TEST_CASE("_1_yields_decimal_1") { REQUIRE(1 == trinary::to_decimal("1")); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("_2_yields_decimal_2") -{ - REQUIRE(2 == trinary::to_decimal("2")); -} +TEST_CASE("_2_yields_decimal_2") { REQUIRE(2 == trinary::to_decimal("2")); } -TEST_CASE("_10_yields_decimal_3") -{ - REQUIRE(3 == trinary::to_decimal("10")); -} +TEST_CASE("_10_yields_decimal_3") { REQUIRE(3 == trinary::to_decimal("10")); } -TEST_CASE("_11_yields_decimal_4") -{ - REQUIRE(4 == trinary::to_decimal("11")); -} +TEST_CASE("_11_yields_decimal_4") { REQUIRE(4 == trinary::to_decimal("11")); } -TEST_CASE("_100_yields_decimal_9") -{ - REQUIRE(9 == trinary::to_decimal("100")); -} +TEST_CASE("_100_yields_decimal_9") { REQUIRE(9 == trinary::to_decimal("100")); } -TEST_CASE("_112_yields_decimal_14") -{ +TEST_CASE("_112_yields_decimal_14") { REQUIRE(14 == trinary::to_decimal("112")); } -TEST_CASE("_222_yields_decimal_26") -{ +TEST_CASE("_222_yields_decimal_26") { REQUIRE(26 == trinary::to_decimal("222")); } -TEST_CASE("_1122000120_yields_decimal_32091") -{ +TEST_CASE("_1122000120_yields_decimal_32091") { REQUIRE(32091 == trinary::to_decimal("1122000120")); } -TEST_CASE("invalid_yields_decimal_0") -{ +TEST_CASE("invalid_yields_decimal_0") { REQUIRE(0 == trinary::to_decimal("carrot")); } #endif diff --git a/exercises/practice/two-bucket/.meta/example.cpp b/exercises/practice/two-bucket/.meta/example.cpp index d03c3a6b8..53079efec 100644 --- a/exercises/practice/two-bucket/.meta/example.cpp +++ b/exercises/practice/two-bucket/.meta/example.cpp @@ -1,35 +1,29 @@ -#include "two_bucket.h" - #include -two_bucket::measure_result two_bucket::measure( - int bucket1_capacity, int bucket2_capacity, - int target_volume, bucket_id start_bucket) -{ - if (start_bucket == bucket_id::two) - { - auto result = measure( - bucket2_capacity, bucket1_capacity, - target_volume, bucket_id::one); - result.goal_bucket = - (result.goal_bucket == bucket_id::one) - ? bucket_id::two - : bucket_id::one; +#include "two_bucket.h" + +two_bucket::measure_result two_bucket::measure(int bucket1_capacity, + int bucket2_capacity, + int target_volume, + bucket_id start_bucket) { + if (start_bucket == bucket_id::two) { + auto result = measure(bucket2_capacity, bucket1_capacity, target_volume, + bucket_id::one); + result.goal_bucket = (result.goal_bucket == bucket_id::one) + ? bucket_id::two + : bucket_id::one; return result; } - if (target_volume == 0) - return {0, bucket_id::one, 0}; - if (target_volume == bucket1_capacity) - return {1, bucket_id::one, 0}; + if (target_volume == 0) return {0, bucket_id::one, 0}; + if (target_volume == bucket1_capacity) return {1, bucket_id::one, 0}; if (target_volume == bucket2_capacity) return {2, bucket_id::two, bucket1_capacity}; int num_steps = 0; int volume1 = 0; int volume2 = 0; - while (volume1 != 0 || volume2 != bucket2_capacity) - { + while (volume1 != 0 || volume2 != bucket2_capacity) { num_steps += 2; if (volume1 == 0) volume1 = bucket1_capacity; // fill(one) @@ -37,14 +31,11 @@ two_bucket::measure_result two_bucket::measure( volume2 = 0; // empty(two) // pour(one, two) - if (volume1 + volume2 <= bucket2_capacity) - { + if (volume1 + volume2 <= bucket2_capacity) { volume2 += volume1; volume1 = 0; - if (volume2 == target_volume) - return {num_steps, bucket_id::two, 0}; - } - else // if volume1 + volume2 > bucket2_max + if (volume2 == target_volume) return {num_steps, bucket_id::two, 0}; + } else // if volume1 + volume2 > bucket2_max { volume1 -= bucket2_capacity - volume2; volume2 = bucket2_capacity; @@ -54,4 +45,3 @@ two_bucket::measure_result two_bucket::measure( } throw std::invalid_argument("impossible"); } - diff --git a/exercises/practice/two-bucket/.meta/example.h b/exercises/practice/two-bucket/.meta/example.h index 975f878b6..38930db86 100644 --- a/exercises/practice/two-bucket/.meta/example.h +++ b/exercises/practice/two-bucket/.meta/example.h @@ -1,22 +1,19 @@ #ifndef TWO_BUCKET_H #define TWO_BUCKET_H -namespace two_bucket -{ +namespace two_bucket { enum class bucket_id { one, two }; -struct measure_result -{ +struct measure_result { int num_moves; bucket_id goal_bucket; int other_bucket_volume; }; -measure_result measure( - int bucket1_capacity, int bucket2_capacity, - int target_volume, bucket_id start_bucket); +measure_result measure(int bucket1_capacity, int bucket2_capacity, + int target_volume, bucket_id start_bucket); } // namespace two_bucket -#endif // TWO_BUCKET_H +#endif // TWO_BUCKET_H diff --git a/exercises/practice/two-bucket/two_bucket.cpp b/exercises/practice/two-bucket/two_bucket.cpp index dcc772167..1e3309f72 100644 --- a/exercises/practice/two-bucket/two_bucket.cpp +++ b/exercises/practice/two-bucket/two_bucket.cpp @@ -1,6 +1,3 @@ #include "two_bucket.h" -namespace two_bucket -{ - -} // namespace two_bucket +namespace two_bucket {} // namespace two_bucket diff --git a/exercises/practice/two-bucket/two_bucket.h b/exercises/practice/two-bucket/two_bucket.h index 975f878b6..38930db86 100644 --- a/exercises/practice/two-bucket/two_bucket.h +++ b/exercises/practice/two-bucket/two_bucket.h @@ -1,22 +1,19 @@ #ifndef TWO_BUCKET_H #define TWO_BUCKET_H -namespace two_bucket -{ +namespace two_bucket { enum class bucket_id { one, two }; -struct measure_result -{ +struct measure_result { int num_moves; bucket_id goal_bucket; int other_bucket_volume; }; -measure_result measure( - int bucket1_capacity, int bucket2_capacity, - int target_volume, bucket_id start_bucket); +measure_result measure(int bucket1_capacity, int bucket2_capacity, + int target_volume, bucket_id start_bucket); } // namespace two_bucket -#endif // TWO_BUCKET_H +#endif // TWO_BUCKET_H diff --git a/exercises/practice/two-bucket/two_bucket_test.cpp b/exercises/practice/two-bucket/two_bucket_test.cpp index 14612f4ff..6186808f0 100644 --- a/exercises/practice/two-bucket/two_bucket_test.cpp +++ b/exercises/practice/two-bucket/two_bucket_test.cpp @@ -5,20 +5,21 @@ #include "test/catch.hpp" #endif -CATCH_REGISTER_ENUM(two_bucket::bucket_id, - two_bucket::bucket_id::one, - two_bucket::bucket_id::two) - -TEST_CASE("Measure using bucket one of size 3 and bucket two of size 5 - start with bucket one", "[a6f2b4ba-065f-4dca-b6f0-e3eee51cb661]") -{ +CATCH_REGISTER_ENUM(two_bucket::bucket_id, two_bucket::bucket_id::one, + two_bucket::bucket_id::two) + +TEST_CASE( + // clang-format off + "Measure using bucket one of size 3 and bucket two of size 5 - start with bucket one", + // clang-format on + "[a6f2b4ba-065f-4dca-b6f0-e3eee51cb661]") { auto bucket1_capacity = 3; auto bucket2_capacity = 5; auto goal_volume = 1; auto start_bucket = two_bucket::bucket_id::one; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 4); CHECK(actual.goal_bucket == two_bucket::bucket_id::one); @@ -27,124 +28,131 @@ TEST_CASE("Measure using bucket one of size 3 and bucket two of size 5 - start w #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("Measure using bucket one of size 3 and bucket two of size 5 - start with bucket two", "[6c4ea451-9678-4926-b9b3-68364e066d40]") -{ +TEST_CASE( + // clang-format off + "Measure using bucket one of size 3 and bucket two of size 5 - start with bucket two", + // clang-format on + "[6c4ea451-9678-4926-b9b3-68364e066d40]") { auto bucket1_capacity = 3; auto bucket2_capacity = 5; auto goal_volume = 1; auto start_bucket = two_bucket::bucket_id::two; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 8); CHECK(actual.goal_bucket == two_bucket::bucket_id::two); CHECK(actual.other_bucket_volume == 3); } -TEST_CASE("Measure using bucket one of size 7 and bucket two of size 11 - start with bucket one", "[3389f45e-6a56-46d5-9607-75aa930502ff]") -{ +TEST_CASE( + // clang-format off + "Measure using bucket one of size 7 and bucket two of size 11 - start with bucket one", + // clang-format on + "[3389f45e-6a56-46d5-9607-75aa930502ff]") { auto bucket1_capacity = 7; auto bucket2_capacity = 11; auto goal_volume = 2; auto start_bucket = two_bucket::bucket_id::one; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 14); CHECK(actual.goal_bucket == two_bucket::bucket_id::one); CHECK(actual.other_bucket_volume == 11); } -TEST_CASE("Measure using bucket one of size 7 and bucket two of size 11 - start with bucket two", "[fe0ff9a0-3ea5-4bf7-b17d-6d4243961aa1]") -{ +TEST_CASE( + // clang-format off + "Measure using bucket one of size 7 and bucket two of size 11 - start with bucket two", + // clang-format on + "[fe0ff9a0-3ea5-4bf7-b17d-6d4243961aa1]") { auto bucket1_capacity = 7; auto bucket2_capacity = 11; auto goal_volume = 2; auto start_bucket = two_bucket::bucket_id::two; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 18); CHECK(actual.goal_bucket == two_bucket::bucket_id::two); CHECK(actual.other_bucket_volume == 7); } -TEST_CASE("Measure one step using bucket one of size 1 and bucket two of size 3 - start with bucket two", "[0ee1f57e-da84-44f7-ac91-38b878691602]") -{ +TEST_CASE( + // clang-format off + "Measure one step using bucket one of size 1 and bucket two of size 3 - start with bucket two", + // clang-format on + "[0ee1f57e-da84-44f7-ac91-38b878691602]") { auto bucket1_capacity = 1; auto bucket2_capacity = 3; auto goal_volume = 3; auto start_bucket = two_bucket::bucket_id::two; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 1); CHECK(actual.goal_bucket == two_bucket::bucket_id::two); CHECK(actual.other_bucket_volume == 0); } -TEST_CASE("Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two", "[eb329c63-5540-4735-b30b-97f7f4df0f84]") -{ +TEST_CASE( + // clang-format off + "Measure using bucket one of size 2 and bucket two of size 3 - start with bucket one and end with bucket two", + // clang-format on + "[eb329c63-5540-4735-b30b-97f7f4df0f84]") { auto bucket1_capacity = 2; auto bucket2_capacity = 3; auto goal_volume = 3; auto start_bucket = two_bucket::bucket_id::one; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 2); CHECK(actual.goal_bucket == two_bucket::bucket_id::two); CHECK(actual.other_bucket_volume == 2); } -TEST_CASE("Not possible to reach the goal", "[449be72d-b10a-4f4b-a959-ca741e333b72]") -{ +TEST_CASE("Not possible to reach the goal", + "[449be72d-b10a-4f4b-a959-ca741e333b72]") { auto bucket1_capacity = 6; auto bucket2_capacity = 15; auto goal_volume = 5; auto start_bucket = two_bucket::bucket_id::one; - REQUIRE_THROWS(two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket)); + REQUIRE_THROWS(two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket)); } -TEST_CASE("With the same buckets but a different goal, then it is possible", "[aac38b7a-77f4-4d62-9b91-8846d533b054]") -{ +TEST_CASE("With the same buckets but a different goal, then it is possible", + "[aac38b7a-77f4-4d62-9b91-8846d533b054]") { auto bucket1_capacity = 6; auto bucket2_capacity = 15; auto goal_volume = 9; auto start_bucket = two_bucket::bucket_id::one; - auto actual = two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket); + auto actual = two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket); CHECK(actual.num_moves == 10); CHECK(actual.goal_bucket == two_bucket::bucket_id::two); CHECK(actual.other_bucket_volume == 0); } -TEST_CASE("Goal larger than both buckets is impossible", "[74633132-0ccf-49de-8450-af4ab2e3b299]") -{ +TEST_CASE("Goal larger than both buckets is impossible", + "[74633132-0ccf-49de-8450-af4ab2e3b299]") { auto bucket1_capacity = 5; auto bucket2_capacity = 7; auto goal_volume = 8; auto start_bucket = two_bucket::bucket_id::one; - REQUIRE_THROWS(two_bucket::measure( - bucket1_capacity, bucket2_capacity, - goal_volume, start_bucket)); + REQUIRE_THROWS(two_bucket::measure(bucket1_capacity, bucket2_capacity, + goal_volume, start_bucket)); } #endif // EXERCISM_RUN_ALL_TESTS diff --git a/exercises/practice/two-fer/.meta/example.h b/exercises/practice/two-fer/.meta/example.h index c1f3f6571..b206795df 100644 --- a/exercises/practice/two-fer/.meta/example.h +++ b/exercises/practice/two-fer/.meta/example.h @@ -3,12 +3,10 @@ #include -namespace two_fer -{ - inline std::string two_fer(const std::string& name = "you") - { - return "One for " + name + ", one for me."; - } -} // namespace two_fer +namespace two_fer { +inline std::string two_fer(const std::string& name = "you") { + return "One for " + name + ", one for me."; +} +} // namespace two_fer -#endif //TWO_FER_H +#endif // TWO_FER_H diff --git a/exercises/practice/two-fer/two_fer.cpp b/exercises/practice/two-fer/two_fer.cpp index 0868911a7..bb2e5d994 100644 --- a/exercises/practice/two-fer/two_fer.cpp +++ b/exercises/practice/two-fer/two_fer.cpp @@ -1,7 +1,3 @@ #include "two_fer.h" -namespace two_fer -{ - -} // namespace two_fer - +namespace two_fer {} // namespace two_fer diff --git a/exercises/practice/two-fer/two_fer.h b/exercises/practice/two-fer/two_fer.h index 8a63771fe..fc5378227 100644 --- a/exercises/practice/two-fer/two_fer.h +++ b/exercises/practice/two-fer/two_fer.h @@ -1,9 +1,6 @@ #if !defined(TWO_FER_H) #define TWO_FER_H -namespace two_fer -{ +namespace two_fer {} // namespace two_fer -} // namespace two_fer - -#endif //TWO_FER_H +#endif // TWO_FER_H diff --git a/exercises/practice/two-fer/two_fer_test.cpp b/exercises/practice/two-fer/two_fer_test.cpp index 812d59b55..90be550ce 100644 --- a/exercises/practice/two-fer/two_fer_test.cpp +++ b/exercises/practice/two-fer/two_fer_test.cpp @@ -8,28 +8,24 @@ // two-fer exercise test case data version 1.2.0 -TEST_CASE("no_name_given") -{ +TEST_CASE("no_name_given") { const std::string actual = two_fer::two_fer(); const std::string expected = "One for you, one for me."; REQUIRE(actual == expected); } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("a_name_given") -{ +TEST_CASE("a_name_given") { const std::string name = "Alice"; const std::string actual = two_fer::two_fer(name); const std::string expected = "One for Alice, one for me."; REQUIRE(actual == expected); } -TEST_CASE("another_name_given") -{ +TEST_CASE("another_name_given") { const std::string name = "Bob"; const std::string actual = two_fer::two_fer(name); const std::string expected = "One for Bob, one for me."; REQUIRE(actual == expected); } #endif - diff --git a/exercises/practice/word-count/.meta/example.cpp b/exercises/practice/word-count/.meta/example.cpp index 6753df346..9f945c07e 100644 --- a/exercises/practice/word-count/.meta/example.cpp +++ b/exercises/practice/word-count/.meta/example.cpp @@ -1,16 +1,15 @@ -#include "word_count.h" #include #include #include #include +#include "word_count.h" + using namespace std; -namespace -{ +namespace { -string trim_copy_if(string const& s, string const& delims) -{ +string trim_copy_if(string const& s, string const& delims) { string cpy(s); // Trim front while (!cpy.empty() && delims.find(cpy.front()) != string::npos) @@ -21,8 +20,7 @@ string trim_copy_if(string const& s, string const& delims) return cpy; } -vector split(string const& s, string const& delims) -{ +vector split(string const& s, string const& delims) { auto start = s.begin(); vector words; for (auto end = s.begin(); end != s.end(); end++) { @@ -39,42 +37,35 @@ vector split(string const& s, string const& delims) return words; } -string normalize_text(string const& text) -{ +string normalize_text(string const& text) { string normalized; transform(text.begin(), text.end(), back_inserter(normalized), - [](const char c) { return (isalnum(c) || c == '\'') ? tolower(c) : ' '; }); + [](const char c) { + return (isalnum(c) || c == '\'') ? tolower(c) : ' '; + }); return normalized; } -string trim_word(string const& word) -{ - return trim_copy_if(word, "' "); -} +string trim_word(string const& word) { return trim_copy_if(word, "' "); } -vector split_text_into_words(string const& text) -{ +vector split_text_into_words(string const& text) { vector words = split(text, "\t "); transform(words.begin(), words.end(), words.begin(), trim_word); return words; } -} +} // namespace -namespace word_count -{ +namespace word_count { -map words(string const& text) -{ +map words(string const& text) { map count; - for (auto const& word : split_text_into_words(normalize_text(text))) - { - if (!word.empty()) - { + for (auto const& word : split_text_into_words(normalize_text(text))) { + if (!word.empty()) { ++count[word]; } } return count; } -} +} // namespace word_count diff --git a/exercises/practice/word-count/.meta/example.h b/exercises/practice/word-count/.meta/example.h index b5d4179bb..e8465d5bc 100644 --- a/exercises/practice/word-count/.meta/example.h +++ b/exercises/practice/word-count/.meta/example.h @@ -4,8 +4,7 @@ #include #include -namespace word_count -{ +namespace word_count { std::map words(std::string const& text); diff --git a/exercises/practice/word-count/word_count.cpp b/exercises/practice/word-count/word_count.cpp index 0e6dc4466..c5dd7380b 100644 --- a/exercises/practice/word-count/word_count.cpp +++ b/exercises/practice/word-count/word_count.cpp @@ -1,5 +1,3 @@ #include "word_count.h" -namespace word_count { - -} // namespace word_count +namespace word_count {} // namespace word_count diff --git a/exercises/practice/word-count/word_count.h b/exercises/practice/word-count/word_count.h index df57451d0..c814e9eef 100644 --- a/exercises/practice/word-count/word_count.h +++ b/exercises/practice/word-count/word_count.h @@ -1,8 +1,6 @@ #if !defined(WORD_COUNT_H) #define WORD_COUNT_H -namespace word_count { +namespace word_count {} // namespace word_count -} // namespace word_count - -#endif // WORD_COUNT_H \ No newline at end of file +#endif // WORD_COUNT_H \ No newline at end of file diff --git a/exercises/practice/word-count/word_count_test.cpp b/exercises/practice/word-count/word_count_test.cpp index 64292eab3..077e275a6 100644 --- a/exercises/practice/word-count/word_count_test.cpp +++ b/exercises/practice/word-count/word_count_test.cpp @@ -5,82 +5,106 @@ #include "test/catch.hpp" #endif - /* For each word in the input, count the number of times it appears in the entire sentence. */ TEST_CASE("count one word", "[61559d5f-2cad-48fb-af53-d3973a9ee9ef]") { - const std::map expected{{"word", 1}}; - REQUIRE(expected == word_count::words("word")); + const std::map expected{{"word", 1}}; + REQUIRE(expected == word_count::words("word")); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("count one of each word", "[5abd53a3-1aed-43a4-a15a-29f88c09cbbd]") { - const std::map expected{{"one", 1}, {"of", 1}, {"each", 1}}; - REQUIRE(expected == word_count::words("one of each")); + const std::map expected{ + {"one", 1}, {"of", 1}, {"each", 1}}; + REQUIRE(expected == word_count::words("one of each")); } -TEST_CASE("multiple occurrences of a word", "[2a3091e5-952e-4099-9fac-8f85d9655c0e]") { - const std::map expected{{"one", 1}, {"fish", 4}, {"two", 1}, {"red", 1}, {"blue", 1}}; - REQUIRE(expected == word_count::words("one fish two fish red fish blue fish")); +TEST_CASE("multiple occurrences of a word", + "[2a3091e5-952e-4099-9fac-8f85d9655c0e]") { + const std::map expected{ + {"one", 1}, {"fish", 4}, {"two", 1}, {"red", 1}, {"blue", 1}}; + REQUIRE(expected == + word_count::words("one fish two fish red fish blue fish")); } TEST_CASE("handles cramped lists", "[e81877ae-d4da-4af4-931c-d923cd621ca6]") { - const std::map expected{{"one", 1}, {"two", 1}, {"three", 1}}; - REQUIRE(expected == word_count::words("one,two,three")); + const std::map expected{ + {"one", 1}, {"two", 1}, {"three", 1}}; + REQUIRE(expected == word_count::words("one,two,three")); } TEST_CASE("handles expanded lists", "[7349f682-9707-47c0-a9af-be56e1e7ff30]") { - const std::map expected{{"one", 1}, {"two", 1}, {"three", 1}}; - REQUIRE(expected == word_count::words("one,\ntwo,\nthree")); + const std::map expected{ + {"one", 1}, {"two", 1}, {"three", 1}}; + REQUIRE(expected == word_count::words("one,\ntwo,\nthree")); } TEST_CASE("ignore punctuation", "[a514a0f2-8589-4279-8892-887f76a14c82]") { - const std::map expected{{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}}; - REQUIRE(expected == word_count::words("car: carpet as java: javascript!!&@$%^&")); + const std::map expected{ + {"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}}; + REQUIRE(expected == + word_count::words("car: carpet as java: javascript!!&@$%^&")); } TEST_CASE("include numbers", "[d2e5cee6-d2ec-497b-bdc9-3ebe092ce55e]") { - const std::map expected{{"testing", 2}, {"1", 1}, {"2", 1}}; - REQUIRE(expected == word_count::words("testing, 1, 2 testing")); + const std::map expected{ + {"testing", 2}, {"1", 1}, {"2", 1}}; + REQUIRE(expected == word_count::words("testing, 1, 2 testing")); } TEST_CASE("normalize case", "[dac6bc6a-21ae-4954-945d-d7f716392dbf]") { - const std::map expected{{"go", 3}, {"stop", 2}}; - REQUIRE(expected == word_count::words("go Go GO Stop stop")); + const std::map expected{{"go", 3}, {"stop", 2}}; + REQUIRE(expected == word_count::words("go Go GO Stop stop")); } TEST_CASE("with apostrophes", "[4ff6c7d7-fcfc-43ef-b8e7-34ff1837a2d3]") { - const std::map expected{{"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, {"cry", 1}, {"you're", 1}, {"getting", 1}, {"it", 1}}; - REQUIRE(expected == word_count::words("'First: don't laugh. Then: don't cry. You're getting it.'")); + const std::map expected{ + {"first", 1}, {"don't", 2}, {"laugh", 1}, {"then", 1}, + {"cry", 1}, {"you're", 1}, {"getting", 1}, {"it", 1}}; + REQUIRE(expected == + word_count::words( + "'First: don't laugh. Then: don't cry. You're getting it.'")); } TEST_CASE("with quotations", "[be72af2b-8afe-4337-b151-b297202e4a7b]") { - const std::map expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"large", 2}, {"and", 1}}; - REQUIRE(expected == word_count::words("Joe can't tell between 'large' and large.")); + const std::map expected{{"joe", 1}, {"can't", 1}, + {"tell", 1}, {"between", 1}, + {"large", 2}, {"and", 1}}; + REQUIRE(expected == + word_count::words("Joe can't tell between 'large' and large.")); } -TEST_CASE("substrings from the beginning", "[8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6]") { - const std::map expected{{"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, {"app", 1}, {"apple", 1}, {"and", 1}, {"a", 1}}; - REQUIRE(expected == word_count::words("Joe can't tell between app, apple and a.")); +TEST_CASE("substrings from the beginning", + "[8d6815fe-8a51-4a65-96f9-2fb3f6dc6ed6]") { + const std::map expected{ + {"joe", 1}, {"can't", 1}, {"tell", 1}, {"between", 1}, + {"app", 1}, {"apple", 1}, {"and", 1}, {"a", 1}}; + REQUIRE(expected == + word_count::words("Joe can't tell between app, apple and a.")); } -TEST_CASE("multiple spaces not detected as a word", "[c5f4ef26-f3f7-4725-b314-855c04fb4c13]") { - const std::map expected{{"multiple", 1}, {"whitespaces", 1}}; - REQUIRE(expected == word_count::words(" multiple whitespaces")); +TEST_CASE("multiple spaces not detected as a word", + "[c5f4ef26-f3f7-4725-b314-855c04fb4c13]") { + const std::map expected{{"multiple", 1}, + {"whitespaces", 1}}; + REQUIRE(expected == word_count::words(" multiple whitespaces")); } -TEST_CASE("alternating word separators not detected as a word", "[50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360]") { - const std::map expected{{"one", 1}, {"two", 1}, {"three", 1}}; - REQUIRE(expected == word_count::words(",\n,one,\n ,two \n 'three'")); +TEST_CASE("alternating word separators not detected as a word", + "[50176e8a-fe8e-4f4c-b6b6-aa9cf8f20360]") { + const std::map expected{ + {"one", 1}, {"two", 1}, {"three", 1}}; + REQUIRE(expected == word_count::words(",\n,one,\n ,two \n 'three'")); } -TEST_CASE("quotation for word with apostrophe", "[6d00f1db-901c-4bec-9829-d20eb3044557]") { - const std::map expected{{"can", 1}, {"can't", 2}}; - REQUIRE(expected == word_count::words("can, can't, 'can't'")); +TEST_CASE("quotation for word with apostrophe", + "[6d00f1db-901c-4bec-9829-d20eb3044557]") { + const std::map expected{{"can", 1}, {"can't", 2}}; + REQUIRE(expected == word_count::words("can, can't, 'can't'")); } #endif diff --git a/exercises/practice/yacht/.meta/example.cpp b/exercises/practice/yacht/.meta/example.cpp index 1a75a5efd..c2eeb951f 100644 --- a/exercises/practice/yacht/.meta/example.cpp +++ b/exercises/practice/yacht/.meta/example.cpp @@ -1,9 +1,9 @@ -#include "yacht.h" - #include #include #include +#include "yacht.h" + namespace yacht { int simple_scores(const std::array& dice, int target) { diff --git a/exercises/practice/yacht/yacht.cpp b/exercises/practice/yacht/yacht.cpp index 47c8192a1..56e67c3eb 100644 --- a/exercises/practice/yacht/yacht.cpp +++ b/exercises/practice/yacht/yacht.cpp @@ -1,5 +1,3 @@ #include "yacht.h" -namespace yacht { - -} // namespace yacht +namespace yacht {} // namespace yacht diff --git a/exercises/practice/yacht/yacht.h b/exercises/practice/yacht/yacht.h index cd205f138..bdaeeee2d 100644 --- a/exercises/practice/yacht/yacht.h +++ b/exercises/practice/yacht/yacht.h @@ -1,5 +1,3 @@ #pragma once -namespace yacht { - -} // namespace yacht +namespace yacht {} // namespace yacht diff --git a/exercises/practice/yacht/yacht_test.cpp b/exercises/practice/yacht/yacht_test.cpp index 03e6a35b5..d4121d03b 100644 --- a/exercises/practice/yacht/yacht_test.cpp +++ b/exercises/practice/yacht/yacht_test.cpp @@ -5,7 +5,6 @@ #include "test/catch.hpp" #endif - /* The dice are represented always as a list of exactly five integers with values between 1 and 6 inclusive. The category is a string. @@ -19,121 +18,135 @@ Then 'full house', */ TEST_CASE("Yacht", "[3060e4a5-4063-4deb-a380-a630b43a84b6]") { - REQUIRE(50 == yacht::score({5, 5, 5, 5, 5}, "yacht")); + REQUIRE(50 == yacht::score({5, 5, 5, 5, 5}, "yacht")); } #if defined(EXERCISM_RUN_ALL_TESTS) TEST_CASE("Not Yacht", "[15026df2-f567-482f-b4d5-5297d57769d9]") { - REQUIRE(0 == yacht::score({1, 3, 3, 2, 5}, "yacht")); + REQUIRE(0 == yacht::score({1, 3, 3, 2, 5}, "yacht")); } TEST_CASE("Ones", "[36b6af0c-ca06-4666-97de-5d31213957a4]") { - REQUIRE(3 == yacht::score({1, 1, 1, 3, 5}, "ones")); + REQUIRE(3 == yacht::score({1, 1, 1, 3, 5}, "ones")); } TEST_CASE("Ones, out of order", "[023a07c8-6c6e-44d0-bc17-efc5e1b8205a]") { - REQUIRE(3 == yacht::score({3, 1, 1, 5, 1}, "ones")); + REQUIRE(3 == yacht::score({3, 1, 1, 5, 1}, "ones")); } TEST_CASE("No ones", "[7189afac-cccd-4a74-8182-1cb1f374e496]") { - REQUIRE(0 == yacht::score({4, 3, 6, 5, 5}, "ones")); + REQUIRE(0 == yacht::score({4, 3, 6, 5, 5}, "ones")); } TEST_CASE("Twos", "[793c4292-dd14-49c4-9707-6d9c56cee725]") { - REQUIRE(2 == yacht::score({2, 3, 4, 5, 6}, "twos")); + REQUIRE(2 == yacht::score({2, 3, 4, 5, 6}, "twos")); } TEST_CASE("Fours", "[dc41bceb-d0c5-4634-a734-c01b4233a0c6]") { - REQUIRE(8 == yacht::score({1, 4, 1, 4, 1}, "fours")); + REQUIRE(8 == yacht::score({1, 4, 1, 4, 1}, "fours")); } TEST_CASE("Yacht counted as threes", "[f6125417-5c8a-4bca-bc5b-b4b76d0d28c8]") { - REQUIRE(15 == yacht::score({3, 3, 3, 3, 3}, "threes")); + REQUIRE(15 == yacht::score({3, 3, 3, 3, 3}, "threes")); } -TEST_CASE("Yacht of 3s counted as fives", "[464fc809-96ed-46e4-acb8-d44e302e9726]") { - REQUIRE(0 == yacht::score({3, 3, 3, 3, 3}, "fives")); +TEST_CASE("Yacht of 3s counted as fives", + "[464fc809-96ed-46e4-acb8-d44e302e9726]") { + REQUIRE(0 == yacht::score({3, 3, 3, 3, 3}, "fives")); } TEST_CASE("Fives", "[d054227f-3a71-4565-a684-5c7e621ec1e9]") { - REQUIRE(10 == yacht::score({1, 5, 3, 5, 3}, "fives")); + REQUIRE(10 == yacht::score({1, 5, 3, 5, 3}, "fives")); } TEST_CASE("Sixes", "[e8a036e0-9d21-443a-8b5f-e15a9e19a761]") { - REQUIRE(6 == yacht::score({2, 3, 4, 5, 6}, "sixes")); + REQUIRE(6 == yacht::score({2, 3, 4, 5, 6}, "sixes")); } -TEST_CASE("Full house two small, three big", "[51cb26db-6b24-49af-a9ff-12f53b252eea]") { - REQUIRE(16 == yacht::score({2, 2, 4, 4, 4}, "full house")); +TEST_CASE("Full house two small, three big", + "[51cb26db-6b24-49af-a9ff-12f53b252eea]") { + REQUIRE(16 == yacht::score({2, 2, 4, 4, 4}, "full house")); } -TEST_CASE("Full house three small, two big", "[1822ca9d-f235-4447-b430-2e8cfc448f0c]") { - REQUIRE(19 == yacht::score({5, 3, 3, 5, 3}, "full house")); +TEST_CASE("Full house three small, two big", + "[1822ca9d-f235-4447-b430-2e8cfc448f0c]") { + REQUIRE(19 == yacht::score({5, 3, 3, 5, 3}, "full house")); } -TEST_CASE("Two pair is not a full house", "[b208a3fc-db2e-4363-a936-9e9a71e69c07]") { - REQUIRE(0 == yacht::score({2, 2, 4, 4, 5}, "full house")); +TEST_CASE("Two pair is not a full house", + "[b208a3fc-db2e-4363-a936-9e9a71e69c07]") { + REQUIRE(0 == yacht::score({2, 2, 4, 4, 5}, "full house")); } -TEST_CASE("Four of a kind is not a full house", "[b90209c3-5956-445b-8a0b-0ac8b906b1c2]") { - REQUIRE(0 == yacht::score({1, 4, 4, 4, 4}, "full house")); +TEST_CASE("Four of a kind is not a full house", + "[b90209c3-5956-445b-8a0b-0ac8b906b1c2]") { + REQUIRE(0 == yacht::score({1, 4, 4, 4, 4}, "full house")); } -TEST_CASE("Yacht is not a full house", "[32a3f4ee-9142-4edf-ba70-6c0f96eb4b0c]") { - REQUIRE(0 == yacht::score({2, 2, 2, 2, 2}, "full house")); +TEST_CASE("Yacht is not a full house", + "[32a3f4ee-9142-4edf-ba70-6c0f96eb4b0c]") { + REQUIRE(0 == yacht::score({2, 2, 2, 2, 2}, "full house")); } TEST_CASE("Four of a Kind", "[b286084d-0568-4460-844a-ba79d71d79c6]") { - REQUIRE(24 == yacht::score({6, 6, 4, 6, 6}, "four of a kind")); + REQUIRE(24 == yacht::score({6, 6, 4, 6, 6}, "four of a kind")); } -TEST_CASE("Yacht can be scored{s Four of a Kind", "[f25c0c90-5397}732-9779-b1e9b5f612ca]") { - REQUIRE(12 == yacht::score({3, 3, 3, 3, 3}, "four of a kind")); +TEST_CASE("Yacht can be scored{s Four of a Kind", + "[f25c0c90-5397}732-9779-b1e9b5f612ca]") { + REQUIRE(12 == yacht::score({3, 3, 3, 3, 3}, "four of a kind")); } -TEST_CASE("Full house is not Four of a Kind", "[9f8ef4f0-72bb-401a-a871-cbad39c9cb08]") { - REQUIRE(0 == yacht::score({3, 3, 3, 5, 5}, "four of a kind")); +TEST_CASE("Full house is not Four of a Kind", + "[9f8ef4f0-72bb-401a-a871-cbad39c9cb08]") { + REQUIRE(0 == yacht::score({3, 3, 3, 5, 5}, "four of a kind")); } TEST_CASE("Little Straight", "[b4743c82-1eb8-4a65-98f7-33ad126905cd]") { - REQUIRE(30 == yacht::score({3, 5, 4, 1, 2}, "little straight")); + REQUIRE(30 == yacht::score({3, 5, 4, 1, 2}, "little straight")); } -TEST_CASE("Little Straight as Big Straight", "[7ac08422-41bf-459c-8187-a38a12d080bc]") { - REQUIRE(0 == yacht::score({1, 2, 3, 4, 5}, "big straight")); +TEST_CASE("Little Straight as Big Straight", + "[7ac08422-41bf-459c-8187-a38a12d080bc]") { + REQUIRE(0 == yacht::score({1, 2, 3, 4, 5}, "big straight")); } -TEST_CASE("Four in order but not a little straight", "[97bde8f7-9058-43ea-9de7-0bc3ed6d3002]") { - REQUIRE(0 == yacht::score({1, 1, 2, 3, 4}, "little straight")); +TEST_CASE("Four in order but not a little straight", + "[97bde8f7-9058-43ea-9de7-0bc3ed6d3002]") { + REQUIRE(0 == yacht::score({1, 1, 2, 3, 4}, "little straight")); } -TEST_CASE("No pairs but not a little straight", "[cef35ff9-9c5e-4fd2-ae95-6e4af5e95a99]") { - REQUIRE(0 == yacht::score({1, 2, 3, 4, 6}, "little straight")); +TEST_CASE("No pairs but not a little straight", + "[cef35ff9-9c5e-4fd2-ae95-6e4af5e95a99]") { + REQUIRE(0 == yacht::score({1, 2, 3, 4, 6}, "little straight")); } -TEST_CASE("Minimum is 1, maximum is 5, but not a little straight", "[fd785ad2-c060-4e45-81c6-ea2bbb781b9d]") { - REQUIRE(0 == yacht::score({1, 1, 3, 4, 5}, "little straight")); +TEST_CASE("Minimum is 1, maximum is 5, but not a little straight", + "[fd785ad2-c060-4e45-81c6-ea2bbb781b9d]") { + REQUIRE(0 == yacht::score({1, 1, 3, 4, 5}, "little straight")); } TEST_CASE("Big Straight", "[35bd74a6-5cf6-431a-97a3-4f713663f467]") { - REQUIRE(30 == yacht::score({4, 6, 2, 5, 3}, "big straight")); + REQUIRE(30 == yacht::score({4, 6, 2, 5, 3}, "big straight")); } -TEST_CASE("Big Straight as little straight", "[87c67e1e-3e87-4f3a-a9b1-62927822b250]") { - REQUIRE(0 == yacht::score({6, 5, 4, 3, 2}, "little straight")); +TEST_CASE("Big Straight as little straight", + "[87c67e1e-3e87-4f3a-a9b1-62927822b250]") { + REQUIRE(0 == yacht::score({6, 5, 4, 3, 2}, "little straight")); } -TEST_CASE("No pairs but not a big straight", "[c1fa0a3a-40ba-4153-a42d-32bc34d2521e]") { - REQUIRE(0 == yacht::score({6, 5, 4, 3, 1}, "big straight")); +TEST_CASE("No pairs but not a big straight", + "[c1fa0a3a-40ba-4153-a42d-32bc34d2521e]") { + REQUIRE(0 == yacht::score({6, 5, 4, 3, 1}, "big straight")); } TEST_CASE("Choice", "[207e7300-5d10-43e5-afdd-213e3ac8827d]") { - REQUIRE(23 == yacht::score({3, 3, 5, 6, 6}, "choice")); + REQUIRE(23 == yacht::score({3, 3, 5, 6, 6}, "choice")); } TEST_CASE("Yacht as choice", "[b524c0cf-32d2-4b40-8fb3-be3500f3f135]") { - REQUIRE(10 == yacht::score({2, 2, 2, 2, 2}, "choice")); + REQUIRE(10 == yacht::score({2, 2, 2, 2, 2}, "choice")); } #endif