diff --git a/.clang-format b/.clang-format index 4632d32..1515027 100644 --- a/.clang-format +++ b/.clang-format @@ -1,36 +1,26 @@ --- # Copyright © 2023 Alexandre Coderre-Chabot # -# This file is licensed under the MIT license. For more information, visit: -# https://mit-license.org +# https://github.com/acodcha/clang-format-tidy # -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# - The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. +# This file is licensed under the MIT license (https://mit-license.org). Permission is hereby +# granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# - The above copyright notice and this permission notice shall be included in all copies or +# substantial portions of the Software. +# - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -# This file was originally obtained from: -# https://github.com/acodcha/clang-format -# -# This is a style configuration file for use with LLVM's ClangFormat automatic -# source code formatter. For more information about ClangFormat, visit: -# https://clang.llvm.org/docs/ClangFormat.html -# -# This file is compatible with ClangFormat version 14.0.0 or any later version. -# To format your source code files, copy this file to the root directory of your -# source code repository, name it either '.clang-format' or '_clang-format', and -# run: +# This is a configuration file for use with LLVM's ClangFormat automatic source code formatter +# (https://clang.llvm.org/docs/ClangFormat.html). This file is compatible with ClangFormat version +# 14.0.0 or any later version. To format your source code files, copy this file to the root +# directory of your source code repository, name it ".clang-format", and run: # clang-format --style=file path/to/source/code/files # AccessModifierOffset: -2 @@ -57,7 +47,7 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes -AttributeMacros: ['__capability'] +AttributeMacros: ["__capability"] BinPackArguments: true BinPackParameters: true BitFieldColonSpacing: Both @@ -88,8 +78,8 @@ BreakBeforeTernaryOperators: false BreakConstructorInitializers: BeforeColon BreakInheritanceList: BeforeColon BreakStringLiterals: true -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' +ColumnLimit: 100 +CommentPragmas: "^ IWYU pragma:" CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 2 @@ -102,24 +92,20 @@ EmptyLineAfterAccessModifier: Never EmptyLineBeforeAccessModifier: Always ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true -ForEachMacros: ['BOOST_FOREACH', 'FOREACH', 'foreach', 'Q_FOREACH'] -IfMacros: ['IF', 'KJ_IF_MAYBE'] +ForEachMacros: ["BOOST_FOREACH", "FOREACH", "foreach", "Q_FOREACH"] +IfMacros: ["IF", "KJ_IF_MAYBE"] IncludeBlocks: Regroup IncludeCategories: - - Regex: '^<.*\.h>' # C standard template library headers - Priority: 1 - SortPriority: 1 - CaseSensitive: false - - Regex: '^<.*' # C++ standard template library headers - Priority: 2 - SortPriority: 2 - CaseSensitive: false - - Regex: '.*' # All other headers - Priority: 3 - SortPriority: 3 - CaseSensitive: false -IncludeIsMainRegex: '([-_](test|unittest))?$' -IncludeIsMainSourceRegex: '' + - Regex: "^<.*" + Priority: 1 + SortPriority: 1 + CaseSensitive: false + - Regex: ".*" + Priority: 2 + SortPriority: 2 + CaseSensitive: false +IncludeIsMainRegex: "([-_](test|unittest))?$" +IncludeIsMainSourceRegex: "" IndentAccessModifiers: false IndentCaseBlocks: true IndentCaseLabels: true @@ -135,8 +121,8 @@ JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false LambdaBodyIndentation: Signature -MacroBlockBegin: '' -MacroBlockEnd: '' +MacroBlockBegin: "" +MacroBlockEnd: "" MaxEmptyLinesToKeep: 1 NamespaceIndentation: None NamespaceMacros: [] @@ -149,33 +135,33 @@ PPIndentWidth: 2 PackConstructorInitializers: BinPack PenaltyBreakAssignment: 4 PenaltyBreakBeforeFirstCallParameter: 4 -PenaltyBreakComment: 16 +PenaltyBreakComment: 8 PenaltyBreakFirstLessLess: 4 PenaltyBreakOpenParenthesis: 4 -PenaltyBreakString: 32 +PenaltyBreakString: 100 PenaltyBreakTemplateDeclaration: 0 -PenaltyExcessCharacter: 1024 +PenaltyExcessCharacter: 10000 PenaltyIndentedWhitespace: 1 -PenaltyReturnTypeOnItsOwnLine: 32 +PenaltyReturnTypeOnItsOwnLine: 50 PointerAlignment: Left QualifierAlignment: Left RawStringFormats: - Language: Cpp - Delimiters: ['cc', 'CC', 'cpp', 'Cpp', 'CPP', 'c++', 'C++'] - CanonicalDelimiter: '' + Delimiters: ["cc", "CC", "cpp", "Cpp", "CPP", "c++", "C++"] + CanonicalDelimiter: "" BasedOnStyle: Google - Language: TextProto - Delimiters: ['pb', 'PB', 'proto', 'PROTO'] + Delimiters: ["pb", "PB", "proto", "PROTO"] EnclosingFunctions: - - 'EqualsProto' - - 'EquivToProto' - - 'PARSE_PARTIAL_TEXT_PROTO' - - 'PARSE_TEST_PROTO' - - 'PARSE_TEXT_PROTO' - - 'ParseTextOrDie' - - 'ParseTextProtoOrDie' - - 'ParseTestProto' - - 'ParsePartialTestProto' + - "EqualsProto" + - "EquivToProto" + - "PARSE_PARTIAL_TEXT_PROTO" + - "PARSE_TEST_PROTO" + - "PARSE_TEXT_PROTO" + - "ParseTextOrDie" + - "ParseTextProtoOrDie" + - "ParseTestProto" + - "ParsePartialTestProto" CanonicalDelimiter: pb BasedOnStyle: Google ReferenceAlignment: Left @@ -219,15 +205,15 @@ SpacesInLineCommentPrefix: SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Latest -StatementAttributeLikeMacros: ['Q_EMIT'] -StatementMacros: ['Q_UNUSED', 'QT_REQUIRE_VERSION'] +StatementAttributeLikeMacros: ["Q_EMIT"] +StatementMacros: ["Q_UNUSED", "QT_REQUIRE_VERSION"] TabWidth: 8 -TypenameMacros: ['STACK_OF', 'LIST'] +TypenameMacros: ["STACK_OF", "LIST"] UseCRLF: false UseTab: Never WhitespaceSensitiveMacros: - - 'STRINGIZE' - - 'PP_STRINGIZE' - - 'BOOST_PP_STRINGIZE' - - 'NS_SWIFT_NAME' - - 'CF_SWIFT_NAME' + - "STRINGIZE" + - "PP_STRINGIZE" + - "BOOST_PP_STRINGIZE" + - "NS_SWIFT_NAME" + - "CF_SWIFT_NAME" diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..234c8b9 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,93 @@ +--- +# Copyright © 2023 Alexandre Coderre-Chabot +# +# https://github.com/acodcha/clang-format-tidy +# +# This file is licensed under the MIT license (https://mit-license.org). Permission is hereby +# granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# - The above copyright notice and this permission notice shall be included in all copies or +# substantial portions of the Software. +# - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# This is a configuration file for use with LLVM's Clang-Tidy automatic source code linter +# (https://clang.llvm.org/extra/clang-tidy). To run the linter on your source code files, copy this +# file to the root directory of your source code repository, name it ".clang-tidy", and run: +# clang-tidy --extra-arg=-std=c++20 /path/to/source/code/files +# +Checks: ' +*, +abseil-*, +altera-*, +android-*, +boost-*, +bugprone-*, +-bugprone-easily-swappable-parameters, +cert-*, +-cert-dcl21-cpp, +-cert-err58-cpp, +clang-analyzer-*, +concurrency-*, +cppcoreguidelines-*, +-cppcoreguidelines-avoid-magic-numbers, +-cppcoreguidelines-non-private-member-variables-in-classes, +darwin-*, +fuchsia-*, +-fuchsia-default-arguments-calls, +-fuchsia-default-arguments-declarations, +-fuchsia-multiple-inheritance, +-fuchsia-overloaded-operator, +-fuchsia-trailing-return, +-fuchsia-virtual-inheritance, +google-*, +-google-objc-avoid-throwing-exception, +-google-objc-function-naming, +-google-objc-global-variable-declaration, +-google-readability-todo, +hicpp-*, +-hicpp-no-assembler, +linuxkernel-*, +llvm-* +-llvm-header-guard, +-llvm-include-order, +llvmlibc-*, +-llvmlibc-callee-namespace, +-llvmlibc-implementation-in-namespace, +-llvmlibc-inline-function-decl, +-llvmlibc-restrict-system-libc-headers, +misc-*, +-misc-non-private-member-variables-in-classes, +modernize-*, +-modernize-use-trailing-return-type, +mpi-*, +objc-*, +openmp-*, +performance-*, +-performance-avoid-endl, +portability-*, +-portability-restrict-system-includes, +readability-*, +-readability-function-cognitive-complexity, +-readability-identifier-length, +-readability-magic-numbers, +zircon-*, +-zircon-temporary-objects, +' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: '' +CheckOptions: + - key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals + value: 'true' + - key: readability-redundant-member-init.IgnoreBaseInCopyConstructors + value: 'true' +... diff --git a/source/Configuration.hpp b/source/Configuration.hpp index 72f520e..4b71961 100644 --- a/source/Configuration.hpp +++ b/source/Configuration.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -25,10 +22,9 @@ #ifndef SECRET_SANTA_CONFIGURATION_HPP #define SECRET_SANTA_CONFIGURATION_HPP -#include - #include #include +#include #include "Participant.hpp" @@ -37,13 +33,12 @@ namespace SecretSanta { // Configuration details read from a YAML configuration file. class Configuration { public: - // Default constructor. Constructs configuration details with a default - // message and no participants. + // Default constructor. Constructs configuration details with a default message and no + // participants. Configuration() = default; - // Constructor. Constructs configuration details by reading them from a YAML - // configuration file. - Configuration(const std::filesystem::path& path) { + // Constructor. Constructs configuration details by reading them from a YAML configuration file. + explicit Configuration(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { std::cout << "Cannot find the YAML configuration file at " << path << "; please check the file path." << std::endl; @@ -62,25 +57,22 @@ class Configuration { YAML::Node message_subject = message["subject"]; if (message_subject) { message_subject_ = message_subject.as(); - std::cout << "The email message subject was read from the YAML " - "configuration file. " - << std::endl; - } else { std::cout - << "No email message subject is defined in the YAML configuration " - "file; using the default email message subject." - << std::endl; + << "The email message subject was read from the YAML configuration file. " << std::endl; + } else { + std::cout << "No email message subject is defined in the YAML configuration file; using the " + "default email message subject." + << std::endl; } YAML::Node message_body = message["body"]; if (message_body) { message_body_ = message_body.as(); - std::cout << "The email message body was read from the YAML " - "configuration file. " - << std::endl; + std::cout + << "The email message body was read from the YAML configuration file. " << std::endl; } else { - std::cout << "No email message body is defined in the YAML configuration " - "file; using the default email message body." + std::cout << "No email message body is defined in the YAML configuration file; using the " + "default email message body." << std::endl; } @@ -92,8 +84,7 @@ class Configuration { } if (participants_.empty()) { - std::cout << "No participants are defined in the YAML configuration file." - << std::endl; + std::cout << "No participants are defined in the YAML configuration file." << std::endl; } else { std::cout << "A total of " << participants_.size() << " participants were found. They are:" << std::endl; @@ -119,42 +110,38 @@ class Configuration { // Deleted move assignment operator. Configuration& operator=(Configuration&& other) noexcept = delete; - // Subject of the email message that will be sent to each participant. A - // default value is used if no message subject is defined in the YAML - // configuration file. - const std::string& MessageSubject() const noexcept { + // Subject of the email message that will be sent to each participant. A default value is used if + // no message subject is defined in the YAML configuration file. + [[nodiscard]] const std::string& MessageSubject() const noexcept { return message_subject_; } - // Body of the email message that will be sent to each participant. A default - // value is used if no message body is defined in the YAML configuration file. - // A brief greeting of "Hello " is automatically prepended to this body, - // and information regarding the participant's giftee is automatically - // appended to this body. - const std::string& MessageBody() const noexcept { + // Body of the email message that will be sent to each participant. A default value is used if no + // message body is defined in the YAML configuration file. A brief greeting of "Hello " is + // automatically prepended to this body, and information regarding the participant's giftee is + // automatically appended to this body. + [[nodiscard]] const std::string& MessageBody() const noexcept { return message_body_; } // Set of participants. - const std::set& Participants() const noexcept { + [[nodiscard]] const std::set& Participants() const noexcept { return participants_; } private: - // Subject of the email message that will be sent to each participant. A - // default value is used if no message subject is defined in the YAML - // configuration file. + // Subject of the email message that will be sent to each participant. A default value is used if + // no message subject is defined in the YAML configuration file. std::string message_subject_{"Secret Santa Gift Exchange"}; - // Body of the email message that will be sent to each participant. A default - // value is used if no message body is defined in the YAML configuration file. - // A brief greeting of "Hello " is automatically prepended to this body, - // and information regarding the participant's giftee is automatically - // appended to this body. + // Body of the email message that will be sent to each participant. A default value is used if no + // message body is defined in the YAML configuration file. A brief greeting of "Hello " is + // automatically prepended to this body, and information regarding the participant's giftee is + // automatically appended to this body. std::string message_body_{ - "You are receiving this message because you opted to participate in a " - "Secret Santa gift exchange! This is an automated email message " - "generated by: https://github.com/acodcha/secret-santa"}; + "You are receiving this message because you opted to participate in a Secret Santa gift " + "exchange! This is an automated email message generated by: " + "https://github.com/acodcha/secret-santa"}; // Set of participants. std::set participants_; diff --git a/source/Matchings.hpp b/source/Matchings.hpp index 65b6b66..6a9c879 100644 --- a/source/Matchings.hpp +++ b/source/Matchings.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -25,8 +22,6 @@ #ifndef SECRET_SANTA_MATCHINGS_HPP #define SECRET_SANTA_MATCHINGS_HPP -#include - #include #include #include @@ -35,6 +30,7 @@ #include #include #include +#include #include "Participant.hpp" @@ -46,8 +42,8 @@ class Matchings { // Default constructor. Constructs an empty set of matchings. Matchings() = default; - // Constructor. Constructs matchings given a set of participants and an - // optional random seed. Ensures that the matchings are valid. + // Constructor. Constructs matchings given a set of participants and an optional random seed. + // Ensures that the matchings are valid. Matchings(const std::set& participants, const std::optional& random_seed = std::nullopt) { // Initialize the random generator. @@ -68,32 +64,26 @@ class Matchings { } // Shuffle the participant names. - std::shuffle( - participant_names.begin(), participant_names.end(), random_generator); - - // Create the matchings between gifters and giftees. Each participant in the - // shuffled sequence is a gifter, and their giftee is the next participant - // in the shuffled sequence. This results in one large cyclic list rather - // than a graph and guarantees that gifters cannot be their own giftees. For - // example, consider the sequence [Alice, Bob, Claire, David]. After - // shuffling, suppose this sequence is [Claire, Bob, David, Alice]. The - // matchings are thus: Claire->Bob, Bob->David, David->Alice, and - // Alice->Claire. - for (std::size_t gifter_index = 0; gifter_index < participant_names.size(); - ++gifter_index) { + std::shuffle(participant_names.begin(), participant_names.end(), random_generator); + + // Create the matchings between gifters and giftees. Each participant in the shuffled sequence + // is a gifter, and their giftee is the next participant in the shuffled sequence. This results + // in one large cyclic list rather than a graph and guarantees that gifters cannot be their own + // giftees. For example, consider the sequence [Alice, Bob, Claire, David]. After shuffling, + // suppose this sequence is [Claire, Bob, David, Alice]. The matchings are thus: Claire->Bob, + // Bob->David, David->Alice, and Alice->Claire. + for (std::size_t gifter_index = 0; gifter_index < participant_names.size(); ++gifter_index) { const std::size_t giftee_index = gifter_index + 1 < participant_names.size() ? gifter_index + 1 : 0; - gifters_to_giftees_.emplace( - participant_names[gifter_index], participant_names[giftee_index]); + gifters_to_giftees_.emplace(participant_names[gifter_index], participant_names[giftee_index]); } - std::cout - << "Randomized the matchings between gifters and giftees." << std::endl; + std::cout << "Randomized the matchings between gifters and giftees." << std::endl; } // Constructor. Constructs matchings by reading them from a given YAML file. - Matchings(const std::filesystem::path& path) { + explicit Matchings(const std::filesystem::path& path) { if (!std::filesystem::exists(path)) { std::cout << "Cannot find the YAML matchings file at " << path << "; please check the file path." << std::endl; @@ -113,17 +103,15 @@ class Matchings { for (YAML::iterator gifter_to_giftee = gifters_to_giftees.begin(); gifter_to_giftee != gifters_to_giftees.end(); ++gifter_to_giftee) { if (gifter_to_giftee->size() == 1 && gifter_to_giftee->IsMap()) { - gifters_to_giftees_.emplace( - gifter_to_giftee->begin()->first.as(), - gifter_to_giftee->begin()->second.as()); + gifters_to_giftees_.emplace(gifter_to_giftee->begin()->first.as(), + gifter_to_giftee->begin()->second.as()); } } } std::cout << "Read " << gifters_to_giftees_.size() - << " matchings between gifters and giftees from the YAML file at: " - << path << std::endl; + << " matchings between gifters and giftees from the YAML file at: " << path << std::endl; } // Destructor. Destroys this matchings object. @@ -141,10 +129,10 @@ class Matchings { // Deleted move assignment operator. Matchings& operator=(Matchings&& other) noexcept = delete; - // Map of gifter participant names to giftee participant names. For example, - // the map element {Alice, Bob} means that Alice is the gifter and Bob is the - // giftee, such that Alice is Bob's Secret Santa. - const std::map& GiftersToGiftees() const noexcept { + // Map of gifter participant names to giftee participant names. For example, the map element + // {Alice, Bob} means that Alice is the gifter and Bob is the giftee, such that Alice is Bob's + // Secret Santa. + [[nodiscard]] const std::map& GiftersToGiftees() const noexcept { return gifters_to_giftees_; } @@ -163,8 +151,8 @@ class Matchings { if (!path.empty()) { stream.open(path.string()); if (!stream.is_open()) { - std::cout << "Could not open the YAML matchings file for writing at: " - << path.string() << std::endl; + std::cout << "Could not open the YAML matchings file for writing at: " << path.string() + << std::endl; return; } } @@ -174,8 +162,7 @@ class Matchings { emitter << YAML::Key << "gifters_to_giftees"; emitter << YAML::Value << YAML::BeginSeq; - for (const std::pair& gifter_and_giftee : - gifters_to_giftees_) { + for (const std::pair& gifter_and_giftee : gifters_to_giftees_) { YAML::Node node; node[gifter_and_giftee.first] = gifter_and_giftee.second; emitter << node; @@ -187,19 +174,16 @@ class Matchings { if (std::filesystem::exists(path)) { std::filesystem::permissions( - path, std::filesystem::perms::owner_read - | std::filesystem::perms::owner_write - | std::filesystem::perms::group_read - | std::filesystem::perms::others_read); + path, std::filesystem::perms::owner_read | std::filesystem::perms::owner_write + | std::filesystem::perms::group_read | std::filesystem::perms::others_read); } if (stream.is_open()) { stream.close(); } - std::cout - << "Wrote the matchings between gifters and giftees to the YAML file: " - << path << std::endl; + std::cout << "Wrote the matchings between gifters and giftees to the YAML file: " << path + << std::endl; } inline bool operator==(const Matchings& other) const noexcept { @@ -227,9 +211,9 @@ class Matchings { } private: - // Map of gifter participant names to giftee participant names. For example, - // the map element {Alice, Bob} means that Alice is the gifter and Bob is the - // giftee, such that Alice is Bob's Secret Santa. + // Map of gifter participant names to giftee participant names. For example, the map element + // {Alice, Bob} means that Alice is the gifter and Bob is the giftee, such that Alice is Bob's + // Secret Santa. std::map gifters_to_giftees_; }; diff --git a/source/Messenger/Argument.hpp b/source/Messenger/Argument.hpp index d4d46ba..815a750 100644 --- a/source/Messenger/Argument.hpp +++ b/source/Messenger/Argument.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -51,17 +48,17 @@ static const std::string Path{""}; } // namespace Value // Prints usage instructions and exits. Optional. -std::string_view Help() { +[[nodiscard]] std::string_view Help() { return Key::Help; } // Path to the YAML configuration file to be read. Required. -std::string Configuration() { +[[nodiscard]] std::string Configuration() { return Key::Configuration + " " + Value::Path; } // Path to the YAML matchings file to be read. Required. -std::string Matchings() { +[[nodiscard]] std::string Matchings() { return Key::Matchings + " " + Value::Path; } diff --git a/source/Messenger/Emailer.hpp b/source/Messenger/Emailer.hpp index 4b98b34..6baea98 100644 --- a/source/Messenger/Emailer.hpp +++ b/source/Messenger/Emailer.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -30,11 +27,10 @@ namespace SecretSanta::Messenger { -// Composes the full email message body for a given gifter. Prefixes a brief -// greeting to the given main message body and appends the giftee information. -std::string ComposeFullMessageBody( - const Participant& gifter, const Participant& giftee, - const std::string& main_message_body) { +// Composes the full email message body for a given gifter. Prefixes a brief greeting to the given +// main message body and appends the giftee information. +[[nodiscard]] std::string ComposeFullMessageBody( + const Participant& gifter, const Participant& giftee, const std::string& main_message_body) { std::string text; text.append("Hello " + gifter.Name() + ",\n\n"); @@ -57,42 +53,38 @@ std::string ComposeFullMessageBody( } // Composes the command used to invoke the S-nail utility for a given gifter. -std::string ComposeCommand( +[[nodiscard]] std::string ComposeCommand( const Participant& gifter, const std::string& message_subject, const std::string& message_body) { - return "echo \"" + message_body + "\" | s-nail --subject \"" + message_subject - + "\" " + gifter.Email(); + return "echo \"" + message_body + "\" | s-nail --subject \"" + message_subject + "\" " + + gifter.Email(); } -// Composes and sends an email message to a given gifter. Creates the full body -// of the message and sends it using the S-nail utility. +// Composes and sends an email message to a given gifter. Creates the full body of the message and +// sends it using the S-nail utility. void ComposeAndSendEmailMessage( - const Participant& gifter, const Participant& giftee, - const std::string& message_subject, const std::string& main_message_body) { - const std::string full_message_body = - ComposeFullMessageBody(gifter, giftee, main_message_body); + const Participant& gifter, const Participant& giftee, const std::string& message_subject, + const std::string& main_message_body) { + const std::string full_message_body = ComposeFullMessageBody(gifter, giftee, main_message_body); - const std::string command{ - ComposeCommand(gifter, message_subject, full_message_body)}; + const std::string command{ComposeCommand(gifter, message_subject, full_message_body)}; const int outcome{std::system(command.c_str())}; if (outcome == 0) { - std::cout << "Sent an email message to " << gifter.Name() << " (" - << gifter.Email() << ")." << std::endl; + std::cout << "Sent an email message to " << gifter.Name() << " (" << gifter.Email() << ")." + << std::endl; } else { std::cout << "Could not run the command: " << command << std::endl; } } // Composes and sends email messages to all gifters. -void ComposeAndSendEmailMessages( - const Configuration& configuration, const Matchings& matchings) { +void ComposeAndSendEmailMessages(const Configuration& configuration, const Matchings& matchings) { for (const Participant& gifter : configuration.Participants()) { // Obtain the gifter and giftee names. - const std::map::const_iterator - gifter_name_and_giftee_name = - matchings.GiftersToGiftees().find(gifter.Name()); + const std::map::const_iterator gifter_name_and_giftee_name = + matchings.GiftersToGiftees().find(gifter.Name()); if (gifter_name_and_giftee_name == matchings.GiftersToGiftees().cend()) { continue; @@ -100,16 +92,15 @@ void ComposeAndSendEmailMessages( // Obtain the giftee information. const std::set::const_iterator giftee = - configuration.Participants().find( - {gifter_name_and_giftee_name->second}); + configuration.Participants().find(Participant{gifter_name_and_giftee_name->second}); if (giftee == configuration.Participants().cend()) { continue; } // Compose and send the email message to this gifter. - ComposeAndSendEmailMessage(gifter, *giftee, configuration.MessageSubject(), - configuration.MessageBody()); + ComposeAndSendEmailMessage( + gifter, *giftee, configuration.MessageSubject(), configuration.MessageBody()); } } diff --git a/source/Messenger/Main.cpp b/source/Messenger/Main.cpp index f3f3691..27e00f8 100644 --- a/source/Messenger/Main.cpp +++ b/source/Messenger/Main.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -38,8 +35,7 @@ int main(int argc, char* argv[]) { SecretSanta::Messenger::ComposeAndSendEmailMessages(configuration, matchings); - std::cout << "End of " << SecretSanta::Messenger::Program::Title << "." - << std::endl; + std::cout << "End of " << SecretSanta::Messenger::Program::Title << "." << std::endl; return EXIT_SUCCESS; } diff --git a/source/Messenger/Program.hpp b/source/Messenger/Program.hpp index 2121b1b..fb5321a 100644 --- a/source/Messenger/Program.hpp +++ b/source/Messenger/Program.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa diff --git a/source/Messenger/Settings.hpp b/source/Messenger/Settings.hpp index 79b9dc3..ff14541 100644 --- a/source/Messenger/Settings.hpp +++ b/source/Messenger/Settings.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -67,12 +64,12 @@ class Settings { Settings& operator=(Settings&& other) noexcept = delete; // Path to the YAML configuration file to be read. - const std::filesystem::path& ConfigurationFile() const noexcept { + [[nodiscard]] const std::filesystem::path& ConfigurationFile() const noexcept { return configuration_file_; } // Path to the YAML matchings file to be read. - const std::filesystem::path& MatchingsFile() const noexcept { + [[nodiscard]] const std::filesystem::path& MatchingsFile() const noexcept { return matchings_file_; } @@ -90,8 +87,8 @@ class Settings { std::cout << "Usage:" << std::endl; - std::cout << indent << executable_name_ << " " << Argument::Configuration() - << " " << Argument::Matchings() << std::endl; + std::cout << indent << executable_name_ << " " << Argument::Configuration() << " " + << Argument::Matchings() << std::endl; // Compute the padding length of the argument patterns. const std::size_t length = std::max({ @@ -105,14 +102,11 @@ class Settings { std::cout << indent << PadToLength(Argument::Help(), length) << indent << "Displays this information and exits." << std::endl; - std::cout - << indent << PadToLength(Argument::Configuration(), length) << indent - << "Path to the YAML configuration file to be read. Required." - << std::endl; + std::cout << indent << PadToLength(Argument::Configuration(), length) << indent + << "Path to the YAML configuration file to be read. Required." << std::endl; std::cout << indent << PadToLength(Argument::Matchings(), length) << indent - << "Path to the YAML matchings file to be written. Optional." - << std::endl; + << "Path to the YAML matchings file to be written. Optional." << std::endl; } // Parses the program's command-line arguments. @@ -132,12 +126,10 @@ class Settings { PrintHeader(); PrintUsage(); exit(EXIT_SUCCESS); - } else if (argv[index] == Argument::Key::Configuration - && AtLeastOneMore(index, argc)) { + } else if (argv[index] == Argument::Key::Configuration && AtLeastOneMore(index, argc)) { configuration_file_ = argv[index + 1]; index += 2; - } else if (argv[index] == Argument::Key::Matchings - && AtLeastOneMore(index, argc)) { + } else if (argv[index] == Argument::Key::Matchings && AtLeastOneMore(index, argc)) { matchings_file_ = argv[index + 1]; index += 2; } else { @@ -149,28 +141,23 @@ class Settings { } } - // Returns whether there is at least one more element after the given element - // index. - bool AtLeastOneMore(const int index, const int count) const noexcept { + // Returns whether there is at least one more element after the given element index. + [[nodiscard]] bool AtLeastOneMore(const int index, const int count) const noexcept { return index + 1 < count; } // Prints the command to the console. void PrintCommand() const { - std::cout - << "Command: " << executable_name_ << " " - << Argument::Key::Configuration << " " << configuration_file_ << " " - << Argument::Key::Matchings + " " + matchings_file_.string() - << std::endl; + std::cout << "Command: " << executable_name_ << " " << Argument::Key::Configuration << " " + << configuration_file_ << " " + << Argument::Key::Matchings + " " + matchings_file_.string() << std::endl; } // Prints the settings to the console. void PrintSettings() const { - std::cout << "- The configuration will be read from: " - << configuration_file_ << std::endl; + std::cout << "- The configuration will be read from: " << configuration_file_ << std::endl; - std::cout << "- The matchings will be read from: " << matchings_file_ - << std::endl; + std::cout << "- The matchings will be read from: " << matchings_file_ << std::endl; } // Name of the Secret Santa Messenger executable. diff --git a/source/Participant.hpp b/source/Participant.hpp index 0a37e90..6dc1330 100644 --- a/source/Participant.hpp +++ b/source/Participant.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -25,32 +22,29 @@ #ifndef SECRET_SANTA_PARTICIPANT_HPP #define SECRET_SANTA_PARTICIPANT_HPP -#include - #include #include +#include namespace SecretSanta { -// A participant in the Secret Santa gift exchange. Contains the participant's -// information. +// A participant in the Secret Santa gift exchange. Contains the participant's information. class Participant { public: - // Default constructor. Creates a participant with an empty name, email, - // address, and instructions. + // Default constructor. Creates a participant with an empty name, email, address, and + // instructions. Participant() = default; - // Constructor. Creates a participant from a given name. The email address, - // street address, and instructions are empty. Only used for searching through - // a set of participants. - Participant(const std::string& name) : name_(name) {} + // Constructor. Creates a participant from a given name. The email address, street address, and + // instructions are empty. Only used for searching through a set of participants. + explicit Participant(const std::string& name) : name_(name) {} // Constructor. Creates a participant from a YAML node of the form: // Alice Smith: // email: alice.smith@gmail.com // address: 123 First Ave, Apt 1, Townsville, CA, 91234 USA // instructions: Leave the package with the doorman in the lobby. - Participant(const YAML::Node& node) { + explicit Participant(const YAML::Node& node) { if (!node.IsMap()) { return; } @@ -96,27 +90,27 @@ class Participant { Participant& operator=(Participant&& other) noexcept = default; // Name of this participant. Each participant must have a unique name. - const std::string& Name() const noexcept { + [[nodiscard]] const std::string& Name() const noexcept { return name_; } // Email address of this participant. - const std::string& Email() const noexcept { + [[nodiscard]] const std::string& Email() const noexcept { return email_; } // Street address of this participant. - const std::string& Address() const noexcept { + [[nodiscard]] const std::string& Address() const noexcept { return address_; } // Additional instructions for mailing packages to this participant. - const std::string& Instructions() const noexcept { + [[nodiscard]] const std::string& Instructions() const noexcept { return instructions_; } // Prints this participant as a string. - std::string Print() const noexcept { + [[nodiscard]] std::string Print() const noexcept { std::string details; if (!email_.empty()) { @@ -150,7 +144,7 @@ class Participant { // email: alice.smith@gmail.com // address: 123 First Ave, Apt 1, Townsville, CA, 91234 USA // instructions: Leave the package with the doorman in the lobby. - YAML::Node YAML() const { + [[nodiscard]] YAML::Node YAML() const { YAML::Node node; node[name_]["email"] = email_; node[name_]["address"] = address_; @@ -196,8 +190,7 @@ class Participant { std::string instructions_; }; -inline std::ostream& operator<<( - std::ostream& stream, const Participant& participant) { +inline std::ostream& operator<<(std::ostream& stream, const Participant& participant) { stream << participant.Print(); return stream; } diff --git a/source/Randomizer/Argument.hpp b/source/Randomizer/Argument.hpp index 922cd7f..f00fd0c 100644 --- a/source/Randomizer/Argument.hpp +++ b/source/Randomizer/Argument.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -57,22 +54,22 @@ static const std::string Path{""}; } // namespace Value // Prints usage instructions and exits. Optional. -std::string_view Help() { +[[nodiscard]] std::string_view Help() { return Key::Help; } // Path to the YAML configuration file to be read. Required. -std::string Configuration() { +[[nodiscard]] std::string Configuration() { return Key::Configuration + " " + Value::Path; } // Path to the YAML matchings file to be written. Optional. -std::string Matchings() { +[[nodiscard]] std::string Matchings() { return Key::Matchings + " " + Value::Path; } // Seed value for pseudo-random number generation. Optional. -std::string Seed() { +[[nodiscard]] std::string Seed() { return Key::Seed + " " + Value::Integer; } diff --git a/source/Randomizer/Main.cpp b/source/Randomizer/Main.cpp index 4bfe4e3..0b1d4a4 100644 --- a/source/Randomizer/Main.cpp +++ b/source/Randomizer/Main.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -33,13 +30,11 @@ int main(int argc, char* argv[]) { const SecretSanta::Configuration configuration{settings.ConfigurationFile()}; - const SecretSanta::Matchings matchings{ - configuration.Participants(), settings.RandomSeed()}; + const SecretSanta::Matchings matchings{configuration.Participants(), settings.RandomSeed()}; matchings.Write(settings.MatchingsFile()); - std::cout << "End of " << SecretSanta::Randomizer::Program::Title << "." - << std::endl; + std::cout << "End of " << SecretSanta::Randomizer::Program::Title << "." << std::endl; return EXIT_SUCCESS; } diff --git a/source/Randomizer/Program.hpp b/source/Randomizer/Program.hpp index 064705a..fda7c4f 100644 --- a/source/Randomizer/Program.hpp +++ b/source/Randomizer/Program.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa diff --git a/source/Randomizer/Settings.hpp b/source/Randomizer/Settings.hpp index be0a15d..00a96d7 100644 --- a/source/Randomizer/Settings.hpp +++ b/source/Randomizer/Settings.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -67,19 +64,18 @@ class Settings { Settings& operator=(Settings&& other) noexcept = delete; // Path to the YAML configuration file to be read. - const std::filesystem::path& ConfigurationFile() const noexcept { + [[nodiscard]] const std::filesystem::path& ConfigurationFile() const noexcept { return configuration_file_; } - // Path to the YAML matchings file to be written. If empty, no matchings file - // is written. - const std::filesystem::path& MatchingsFile() const noexcept { + // Path to the YAML matchings file to be written. If empty, no matchings file is written. + [[nodiscard]] const std::filesystem::path& MatchingsFile() const noexcept { return matchings_file_; } - // Optional seed value for pseudo-random number generation. If no value is - // specified, the seed value is randomized. - constexpr const std::optional& RandomSeed() const noexcept { + // Optional seed value for pseudo-random number generation. If no value is specified, the seed + // value is randomized. + [[nodiscard]] constexpr const std::optional& RandomSeed() const noexcept { return random_seed_; } @@ -97,8 +93,8 @@ class Settings { std::cout << "Usage:" << std::endl; - std::cout << indent << executable_name_ << " " << Argument::Configuration() - << " [" << Argument::Matchings() << "] " + std::cout << indent << executable_name_ << " " << Argument::Configuration() << " [" + << Argument::Matchings() << "] " << " [" << Argument::Seed() << "]" << std::endl; // Compute the padding length of the argument patterns. @@ -114,18 +110,14 @@ class Settings { std::cout << indent << PadToLength(Argument::Help(), length) << indent << "Displays this information and exits." << std::endl; - std::cout - << indent << PadToLength(Argument::Configuration(), length) << indent - << "Path to the YAML configuration file to be read. Required." - << std::endl; + std::cout << indent << PadToLength(Argument::Configuration(), length) << indent + << "Path to the YAML configuration file to be read. Required." << std::endl; std::cout << indent << PadToLength(Argument::Matchings(), length) << indent - << "Path to the YAML matchings file to be written. Optional." - << std::endl; + << "Path to the YAML matchings file to be written. Optional." << std::endl; std::cout << indent << PadToLength(Argument::Seed(), length) << indent - << "Seed value for pseudo-random number generation. Optional." - << std::endl; + << "Seed value for pseudo-random number generation. Optional." << std::endl; } // Parses the program's command-line arguments. @@ -145,16 +137,13 @@ class Settings { PrintHeader(); PrintUsage(); exit(EXIT_SUCCESS); - } else if (argv[index] == Argument::Key::Configuration - && AtLeastOneMore(index, argc)) { + } else if (argv[index] == Argument::Key::Configuration && AtLeastOneMore(index, argc)) { configuration_file_ = argv[index + 1]; index += 2; - } else if (argv[index] == Argument::Key::Matchings - && AtLeastOneMore(index, argc)) { + } else if (argv[index] == Argument::Key::Matchings && AtLeastOneMore(index, argc)) { matchings_file_ = argv[index + 1]; index += 2; - } else if ( - argv[index] == Argument::Key::Seed && AtLeastOneMore(index, argc)) { + } else if (argv[index] == Argument::Key::Seed && AtLeastOneMore(index, argc)) { random_seed_ = std::strtoll(argv[index + 1], nullptr, 10); index += 2; } else { @@ -166,47 +155,40 @@ class Settings { } } - // Returns whether there is at least one more element after the given element - // index. - bool AtLeastOneMore(const int index, const int count) const noexcept { + // Returns whether there is at least one more element after the given element index. + [[nodiscard]] bool AtLeastOneMore(const int index, const int count) const noexcept { return index + 1 < count; } // Prints the command to the console. void PrintCommand() const { std::cout - << "Command: " << executable_name_ << " " - << Argument::Key::Configuration << " " << configuration_file_ - << (!matchings_file_.empty() ? " " + Argument::Key::Matchings + " " - + matchings_file_.string() : - "") + << "Command: " << executable_name_ << " " << Argument::Key::Configuration << " " + << configuration_file_ + << (!matchings_file_.empty() ? + " " + Argument::Key::Matchings + " " + matchings_file_.string() : + "") << (random_seed_.has_value() ? - " " + Argument::Key::Seed + " " - + std::to_string(random_seed_.value()) : + " " + Argument::Key::Seed + " " + std::to_string(random_seed_.value()) : "") << std::endl; } // Prints the settings to the console. void PrintSettings() const { - std::cout << "- The configuration will be read from: " - << configuration_file_ << std::endl; + std::cout << "- The configuration will be read from: " << configuration_file_ << std::endl; if (matchings_file_.empty()) { - std::cout - << "- The matchings will not be written to a file." << std::endl; + std::cout << "- The matchings will not be written to a file." << std::endl; } else { - std::cout << "- The matchings will be written to: " << matchings_file_ - << std::endl; + std::cout << "- The matchings will be written to: " << matchings_file_ << std::endl; } if (random_seed_.has_value()) { std::cout << "- The seed value for pseudo-random number generation is : " << random_seed_.value() << std::endl; } else { - std::cout - << "- The seed value for random number generation will be randomized." - << std::endl; + std::cout << "- The seed value for random number generation will be randomized." << std::endl; } } @@ -216,12 +198,11 @@ class Settings { // Path to the YAML configuration file to be read. std::filesystem::path configuration_file_; - // Path to the YAML matchings file to be written. If empty, no matchings file - // is written. + // Path to the YAML matchings file to be written. If empty, no matchings file is written. std::filesystem::path matchings_file_; - // Optional seed value for pseudo-random number generation. If no value is - // specified, the seed value is randomized. + // Optional seed value for pseudo-random number generation. If no value is specified, the seed + // value is randomized. std::optional random_seed_; }; diff --git a/source/String.hpp b/source/String.hpp index e25b610..7b413f8 100644 --- a/source/String.hpp +++ b/source/String.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -32,10 +29,9 @@ // Namespace that encapsulates all of the Secret Santa program's contents. namespace SecretSanta { -// Returns a copy of a given string where the copy has been padded to a given -// length with trailing spaces. If the given string is already longer than the -// given length, nothing is changed. -std::string PadToLength( +// Returns a copy of a given string where the copy has been padded to a given length with trailing +// spaces. If the given string is already longer than the given length, nothing is changed. +[[nodiscard]] std::string PadToLength( const std::string_view text, const std::size_t length) noexcept { std::string padded_text{text}; const std::size_t text_length = text.size(); diff --git a/test/Configuration.cpp b/test/Configuration.cpp index a6a007f..f05af66 100644 --- a/test/Configuration.cpp +++ b/test/Configuration.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -41,9 +38,9 @@ TEST(Configuration, DefaultConstructor) { const Configuration configuration; EXPECT_EQ(configuration.MessageSubject(), "Secret Santa Gift Exchange"); EXPECT_EQ(configuration.MessageBody(), - "You are receiving this message because you opted to participate " - "in a Secret Santa gift exchange! This is an automated email " - "message generated by: https://github.com/acodcha/secret-santa"); + "You are receiving this message because you opted to participate in a Secret Santa " + "gift exchange! This is an automated email message generated by: " + "https://github.com/acodcha/secret-santa"); } } // namespace diff --git a/test/CreateSampleParticipant.hpp b/test/CreateSampleParticipant.hpp index fc4e32e..abc5d5a 100644 --- a/test/CreateSampleParticipant.hpp +++ b/test/CreateSampleParticipant.hpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -34,18 +31,15 @@ namespace SecretSanta { YAML::Node CreateSampleParticipantA() { YAML::Node node; node["Alice Smith"]["email"] = "alice.smith@gmail.com"; - node["Alice Smith"]["address"] = - "123 First Ave, Apt 1, Townsville, CA 91234 USA"; - node["Alice Smith"]["instructions"] = - "Leave the package with the doorman in the lobby."; + node["Alice Smith"]["address"] = "123 First Ave, Apt 1, Townsville, CA 91234 USA"; + node["Alice Smith"]["instructions"] = "Leave the package with the doorman in the lobby."; return node; } YAML::Node CreateSampleParticipantB() { YAML::Node node; node["Bob Johnson"]["email"] = "bob.johnson@gmail.com"; - node["Bob Johnson"]["address"] = - "456 Second St, Apt 2, Villagetown, CA 92345 USA"; + node["Bob Johnson"]["address"] = "456 Second St, Apt 2, Villagetown, CA 92345 USA"; return node; } diff --git a/test/Matchings.cpp b/test/Matchings.cpp index 6b3feab..98b50b9 100644 --- a/test/Matchings.cpp +++ b/test/Matchings.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -41,7 +38,7 @@ std::set CreateSampleParticipants() { } TEST(Matchings, ComparisonOperators) { - const Matchings first{{CreateSampleParticipantA()}}; + const Matchings first{std::set{Participant{CreateSampleParticipantA()}}}; const Matchings second{CreateSampleParticipants()}; EXPECT_EQ(first, first); EXPECT_NE(first, second); @@ -59,10 +56,9 @@ TEST(Matchings, ConstructorFromNoParticipants) { } TEST(Matchings, ConstructorFromOneParticipant) { - const Matchings matchings{{CreateSampleParticipantA()}}; + const Matchings matchings{std::set{Participant{CreateSampleParticipantA()}}}; EXPECT_EQ(matchings.GiftersToGiftees().size(), 1); - EXPECT_NE(matchings.GiftersToGiftees().find("Alice Smith"), - matchings.GiftersToGiftees().cend()); + EXPECT_NE(matchings.GiftersToGiftees().find("Alice Smith"), matchings.GiftersToGiftees().cend()); EXPECT_EQ(matchings.GiftersToGiftees().at("Alice Smith"), "Alice Smith"); } diff --git a/test/Messenger/Emailer.cpp b/test/Messenger/Emailer.cpp index 02690be..2184e4c 100644 --- a/test/Messenger/Emailer.cpp +++ b/test/Messenger/Emailer.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -33,34 +30,31 @@ namespace SecretSanta::Messenger { namespace { TEST(MessengerEmailer, ComposeFullMessageBody) { - const Participant gifter = CreateSampleParticipantA(); - const Participant giftee = CreateSampleParticipantB(); + const Participant gifter{CreateSampleParticipantA()}; + const Participant giftee{CreateSampleParticipantB()}; const std::string main_message_body{ - "You are receiving this message because you opted to participate in a " - "Secret Santa gift exchange!"}; + "You are receiving this message because you opted to participate in a Secret Santa gift " + "exchange!"}; - const std::string result = - ComposeFullMessageBody(gifter, giftee, main_message_body); + const std::string result = ComposeFullMessageBody(gifter, giftee, main_message_body); EXPECT_EQ(result, - "Hello Alice Smith,\n\nYou are receiving this message because you " - "opted to participate in a Secret Santa gift exchange!\n\nYour " - "giftee is: Bob Johnson\n\nMail to:\n\nBob Johnson SECRET " - "SANTA\n456 Second St, Apt 2, Villagetown, CA 92345 USA\n\nThank " - "you!"); + "Hello Alice Smith,\n\nYou are receiving this message because you opted to participate " + "in a Secret Santa gift exchange!\n\nYour giftee is: Bob Johnson\n\nMail to:\n\nBob " + "Johnson SECRET SANTA\n456 Second St, Apt 2, Villagetown, CA 92345 USA\n\nThank you!"); } TEST(MessengerEmailer, ComposeCommand) { - const Participant gifter = CreateSampleParticipantA(); + const Participant gifter{CreateSampleParticipantA()}; const std::string message_subject{"My Message Subject"}; const std::string message_body{"My Message Body"}; std::string command = ComposeCommand(gifter, message_subject, message_body); - EXPECT_EQ(command, - "echo \"My Message Body\" | s-nail --subject \"My Message " - "Subject\" alice.smith@gmail.com"); + EXPECT_EQ( + command, + "echo \"My Message Body\" | s-nail --subject \"My Message Subject\" alice.smith@gmail.com"); } } // namespace diff --git a/test/Messenger/Settings.cpp b/test/Messenger/Settings.cpp index 31a8e99..393a236 100644 --- a/test/Messenger/Settings.cpp +++ b/test/Messenger/Settings.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -42,14 +39,12 @@ TEST(MessengerSettings, Constructor) { int argc = 5; char* argv[] = { - program, configuration_key, configuration_value, - matchings_key, matchings_value, + program, configuration_key, configuration_value, matchings_key, matchings_value, }; const Settings settings{argc, argv}; - EXPECT_EQ(settings.ConfigurationFile(), - "path/to/some/directory/configuration.yaml"); + EXPECT_EQ(settings.ConfigurationFile(), "path/to/some/directory/configuration.yaml"); EXPECT_EQ(settings.MatchingsFile(), "path/to/some/directory/matchings.yaml"); } diff --git a/test/Participant.cpp b/test/Participant.cpp index d368e77..f27cf68 100644 --- a/test/Participant.cpp +++ b/test/Participant.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -57,15 +54,13 @@ TEST(Participant, ConstructorFromYamlNode) { const Participant participant{CreateSampleParticipantA()}; EXPECT_EQ(participant.Name(), "Alice Smith"); EXPECT_EQ(participant.Email(), "alice.smith@gmail.com"); - EXPECT_EQ( - participant.Address(), "123 First Ave, Apt 1, Townsville, CA 91234 USA"); - EXPECT_EQ(participant.Instructions(), - "Leave the package with the doorman in the lobby."); + EXPECT_EQ(participant.Address(), "123 First Ave, Apt 1, Townsville, CA 91234 USA"); + EXPECT_EQ(participant.Instructions(), "Leave the package with the doorman in the lobby."); } TEST(Participant, CopyAssignmentOperator) { const Participant first{CreateSampleParticipantA()}; - Participant second = CreateSampleParticipantB(); + Participant second = Participant{CreateSampleParticipantB()}; second = first; EXPECT_EQ(second, first); } @@ -93,7 +88,7 @@ TEST(Participant, Hash) { TEST(Participant, MoveAssignmentOperator) { Participant first{CreateSampleParticipantA()}; - Participant second = CreateSampleParticipantB(); + Participant second{CreateSampleParticipantB()}; second = std::move(first); EXPECT_EQ(second, Participant(CreateSampleParticipantA())); } @@ -107,9 +102,8 @@ TEST(Participant, MoveConstructor) { TEST(Participant, Print) { const Participant participant{CreateSampleParticipantA()}; EXPECT_EQ(participant.Print(), - "Alice Smith (email: alice.smith@gmail.com; address: 123 First " - "Ave, Apt 1, Townsville, CA 91234 USA; instructions: Leave the " - "package with the doorman in the lobby.)"); + "Alice Smith (email: alice.smith@gmail.com; address: 123 First Ave, Apt 1, Townsville, " + "CA 91234 USA; instructions: Leave the package with the doorman in the lobby.)"); } TEST(Participant, Stream) { @@ -117,21 +111,19 @@ TEST(Participant, Stream) { std::stringstream stream; stream << participant; EXPECT_EQ(stream.str(), - "Alice Smith (email: alice.smith@gmail.com; address: 123 First " - "Ave, Apt 1, Townsville, CA 91234 USA; instructions: Leave the " - "package with the doorman in the lobby.)"); + "Alice Smith (email: alice.smith@gmail.com; address: 123 First Ave, Apt 1, Townsville, " + "CA 91234 USA; instructions: Leave the package with the doorman in the lobby.)"); } TEST(Participant, YAML) { const Participant participant{CreateSampleParticipantA()}; - const YAML::Node node = participant.YAML(); + const YAML::Node node{participant.YAML()}; ASSERT_TRUE(node.IsMap()); ASSERT_EQ(node.size(), 1); for (const YAML::detail::iterator_value& element : node) { ASSERT_EQ(element.first.as(), "Alice Smith"); ASSERT_TRUE(element.second["email"]); - ASSERT_EQ( - element.second["email"].as(), "alice.smith@gmail.com"); + ASSERT_EQ(element.second["email"].as(), "alice.smith@gmail.com"); ASSERT_TRUE(element.second["address"]); ASSERT_EQ(element.second["address"].as(), "123 First Ave, Apt 1, Townsville, CA 91234 USA"); diff --git a/test/Randomizer/Settings.cpp b/test/Randomizer/Settings.cpp index 7fb7e9b..f425d28 100644 --- a/test/Randomizer/Settings.cpp +++ b/test/Randomizer/Settings.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa @@ -51,8 +48,7 @@ TEST(RandomizerSettings, Constructor) { const Settings settings{argc, argv}; - EXPECT_EQ(settings.ConfigurationFile(), - "path/to/some/directory/configuration.yaml"); + EXPECT_EQ(settings.ConfigurationFile(), "path/to/some/directory/configuration.yaml"); EXPECT_EQ(settings.MatchingsFile(), "path/to/some/directory/matchings.yaml"); ASSERT_TRUE(settings.RandomSeed().has_value()); EXPECT_EQ(settings.RandomSeed(), 42); diff --git a/test/String.cpp b/test/String.cpp index 962a003..4045a33 100644 --- a/test/String.cpp +++ b/test/String.cpp @@ -1,23 +1,20 @@ -// Copyright © 2023 Alexandre Coderre-Chabot +// Copyright © 2023-2024 Alexandre Coderre-Chabot // // This file is licensed under the MIT license. For more information, visit: // https://mit-license.org // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +// associated documentation files (the "Software"), to deal in the Software without restriction, +// including without limitation the rights to use, copy, modify, merge, publish, distribute, +// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// - The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. +// - The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // This file was originally obtained from: // https://github.com/acodcha/secret-santa