From 2d7b807aa9ff6db5500b4ca4f10129629260bcee Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:05:15 -0500 Subject: [PATCH 1/6] Clean up optional throw --- include/emp/base/_optional_throw.hpp | 22 +++++++++++----------- include/emp/base/always_assert.hpp | 2 +- include/emp/base/optional_throw.hpp | 4 ++-- tests/base/optional_throw.cpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/emp/base/_optional_throw.hpp b/include/emp/base/_optional_throw.hpp index b4cf060952..3eca499988 100644 --- a/include/emp/base/_optional_throw.hpp +++ b/include/emp/base/_optional_throw.hpp @@ -19,40 +19,40 @@ namespace emp { /// Base case for assert_print... - inline void assert_print(std::stringstream &) { ; } + inline void assert_print_opt(std::stringstream &) { ; } /// Print out information about the next variable and recurse... template - void assert_print(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { + void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { if constexpr ( emp::is_streamable::value ) { ss << name << ": [" << val << "]" << std::endl; } else ss << name << ": (non-streamable type)" << std::endl; - assert_print(ss, std::forward(extra)...); + assert_print_opt(ss, std::forward(extra)...); } template - void assert_print_second(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { - assert_print(ss, std::forward(extra)...); + void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { + assert_print_opt(ss, std::forward(extra)...); } template - void assert_print_second(std::stringstream & ss, std::string name, T && val) {;} + void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;} template - void assert_print_first(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { + void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) { if constexpr ( emp::is_streamable::value ) { ss << name << ": [" << val << "]" << std::endl; } else ss << name << ": (non-streamable type)" << std::endl; - assert_print_second(ss, std::forward(extra)...); + assert_print_second_opt(ss, std::forward(extra)...); } - void assert_print_first(std::stringstream & ss, int placeholder) {;} + void assert_print_first_opt(std::stringstream & ss, int placeholder) {;} template - void assert_throw(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) { + void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) { std::stringstream ss; ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n"; - assert_print_first(ss, std::forward(extra)...); + assert_print_first_opt(ss, std::forward(extra)...); throw(std::runtime_error(ss.str())); } } diff --git a/include/emp/base/always_assert.hpp b/include/emp/base/always_assert.hpp index b77020cdbd..a4c34b4995 100644 --- a/include/emp/base/always_assert.hpp +++ b/include/emp/base/always_assert.hpp @@ -59,7 +59,7 @@ #define emp_always_assert_impl(TEST) emp_always_assert_msvc_impl(TEST) -#elif defined(IN_PYTHON) +#elif defined(EMP_OPTIONAL_THROW_ON) #define emp_always_assert_impl(...) \ do { \ diff --git a/include/emp/base/optional_throw.hpp b/include/emp/base/optional_throw.hpp index 0b2f1ee78d..62762c5260 100644 --- a/include/emp/base/optional_throw.hpp +++ b/include/emp/base/optional_throw.hpp @@ -20,14 +20,14 @@ #endif -#if defined( IN_PYTHON ) +#if defined( EMP_OPTIONAL_THROW_ON ) // #if defined (_MSC_VER ) #define emp_optional_throw(TEST, MESSAGE) \ do { \ if (!(TEST)) { \ - emp::assert_throw(__FILE__, __LINE__, #TEST, MESSAGE, 0); \ + emp::assert_throw_opt(__FILE__, __LINE__, #TEST, MESSAGE, 0); \ } \ } while(0) diff --git a/tests/base/optional_throw.cpp b/tests/base/optional_throw.cpp index 6e9bb84f39..e0a2998e4f 100644 --- a/tests/base/optional_throw.cpp +++ b/tests/base/optional_throw.cpp @@ -19,7 +19,7 @@ TEST_CASE("Optional throw" "[asserts]") { emp_optional_throw(false); REQUIRE(emp::assert_last_fail); - #define IN_PYTHON 1 + #define EMP_OPTIONAL_THROW_ON 1 try { emp_optional_throw(false); } From cad65b077f7cc2170d64a2f5e2f7db9d315df4d0 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:06:49 -0500 Subject: [PATCH 2/6] Fix trailing whitespace --- tests/Evolve/Systematics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Evolve/Systematics.cpp b/tests/Evolve/Systematics.cpp index 2182c6d317..b10ef61462 100644 --- a/tests/Evolve/Systematics.cpp +++ b/tests/Evolve/Systematics.cpp @@ -916,7 +916,7 @@ TEST_CASE("Run world", "[evo]") { for (size_t i = 0; i < 100; i++) { EliteSelect(world, 1, 1); } - + for (size_t i = 0; i < world.GetSize(); i++) { record_fit_sig.Trigger(i, world.CalcFitnessID(i)); record_phen_sig.Trigger(i, phen_fun(world.GetOrg(i))); From 9f73a69b38b0f53c1a1178ce8c4d7944cd77a5f1 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:07:49 -0500 Subject: [PATCH 3/6] Fix alphabetize includes --- include/emp/base/_optional_throw.hpp | 2 +- tests/base/optional_throw.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/emp/base/_optional_throw.hpp b/include/emp/base/_optional_throw.hpp index 3eca499988..5a7bc22868 100644 --- a/include/emp/base/_optional_throw.hpp +++ b/include/emp/base/_optional_throw.hpp @@ -57,4 +57,4 @@ namespace emp { } } -#endif // #ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE \ No newline at end of file +#endif // #ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE diff --git a/tests/base/optional_throw.cpp b/tests/base/optional_throw.cpp index e0a2998e4f..f67babb671 100644 --- a/tests/base/optional_throw.cpp +++ b/tests/base/optional_throw.cpp @@ -26,4 +26,4 @@ TEST_CASE("Optional throw" "[asserts]") { catch (std::runtime_error & error) { REQUIRE(std::string(error.what()) == "Internal Error (in always_assert.cpp line 37): false,\nfalse: [0]\n"); } -} \ No newline at end of file +} From 99386bd73e03dafe7c5165959d6d9bf9fc490e15 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:21:49 -0500 Subject: [PATCH 4/6] Fix docstrings --- include/emp/Evolve/Systematics.hpp | 14 +++++++------- include/emp/base/_optional_throw.hpp | 14 +++++++------- include/emp/base/optional_throw.hpp | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/emp/Evolve/Systematics.hpp b/include/emp/Evolve/Systematics.hpp index 8d1cafc746..cd462d5f34 100644 --- a/include/emp/Evolve/Systematics.hpp +++ b/include/emp/Evolve/Systematics.hpp @@ -1,11 +1,11 @@ +/* + * This file is part of Empirical, https://github.com/devosoft/Empirical + * Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * date: 2024 +*/ /** - * @note This file is part of Empirical, https://github.com/devosoft/Empirical - * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2017-2023 - * - * @file Systematics.hpp - * @brief Track genotypes, species, clades, or lineages of organisms in a world. - * + * @file + * @brief TODO. * @todo We should provide an option to back up systematics data to a file so that it doesn't all * need to be kept in memory, especially if we're only doing post-analysis. * @todo This inheritance system makes adding new systematics-related data tracking kind of a pain. diff --git a/include/emp/base/_optional_throw.hpp b/include/emp/base/_optional_throw.hpp index 5a7bc22868..946034edfa 100644 --- a/include/emp/base/_optional_throw.hpp +++ b/include/emp/base/_optional_throw.hpp @@ -1,11 +1,11 @@ +/* + * This file is part of Empirical, https://github.com/devosoft/Empirical + * Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * date: 2024 +*/ /** - * @note This file is part of Empirical, https://github.com/devosoft/Empirical - * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2023. - * - * @file _optional_throw.hpp - * @brief Variant of asserts that throws exception - * @note This is useful for writing code that gets wrapped in Python via pybind11 + * @file + * @brief TODO. */ #ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE diff --git a/include/emp/base/optional_throw.hpp b/include/emp/base/optional_throw.hpp index 62762c5260..9a0425a48d 100644 --- a/include/emp/base/optional_throw.hpp +++ b/include/emp/base/optional_throw.hpp @@ -1,11 +1,11 @@ +/* + * This file is part of Empirical, https://github.com/devosoft/Empirical + * Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * date: 2024 +*/ /** - * @note This file is part of Empirical, https://github.com/devosoft/Empirical - * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2023. - * - * @file optional_throw.hpp - * @brief Like emp_assert, but throws an exception if in Python - * @note Status: RELEASE + * @file + * @brief TODO. * */ From 2a90a30983a2a6a39a32d5c7d31366e0d4175e7e Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:22:32 -0500 Subject: [PATCH 5/6] Fix headergaurd --- include/emp/base/_optional_throw.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/emp/base/_optional_throw.hpp b/include/emp/base/_optional_throw.hpp index 946034edfa..855e244b57 100644 --- a/include/emp/base/_optional_throw.hpp +++ b/include/emp/base/_optional_throw.hpp @@ -8,8 +8,8 @@ * @brief TODO. */ -#ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE -#define EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE +#ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE +#define EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE #include #include @@ -57,4 +57,4 @@ namespace emp { } } -#endif // #ifndef EMP_BASE__OPTIONAL_THROW_TRIGGER_HPP_INCLUDE +#endif // #ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE From ab563bf6b2f0419f45386f0fd142dc34f7d196b7 Mon Sep 17 00:00:00 2001 From: Emily Dolson Date: Thu, 29 Feb 2024 02:24:29 -0500 Subject: [PATCH 6/6] Fix license --- tests/Evolve/Systematics.cpp | 16 ++++++++-------- tests/base/optional_throw.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Evolve/Systematics.cpp b/tests/Evolve/Systematics.cpp index b10ef61462..f3ef3e3399 100644 --- a/tests/Evolve/Systematics.cpp +++ b/tests/Evolve/Systematics.cpp @@ -1,14 +1,14 @@ +/* + * This file is part of Empirical, https://github.com/devosoft/Empirical + * Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * date: 2024 +*/ /** - * @note This file is part of Empirical, https://github.com/devosoft/Empirical - * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2021 - * - * @file Systematics.cpp - */ - + * @file + * @brief TODO. #include #include -#include + */ #include "third-party/Catch/single_include/catch2/catch.hpp" diff --git a/tests/base/optional_throw.cpp b/tests/base/optional_throw.cpp index f67babb671..24b53f0bb9 100644 --- a/tests/base/optional_throw.cpp +++ b/tests/base/optional_throw.cpp @@ -1,13 +1,13 @@ +/* + * This file is part of Empirical, https://github.com/devosoft/Empirical + * Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md + * date: 2024 +*/ /** - * @note This file is part of Empirical, https://github.com/devosoft/Empirical - * @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md - * @date 2023 - * - * @file optional_throw.cpp - */ - + * @file + * @brief TODO. #include -#include + */ #include "third-party/Catch/single_include/catch2/catch.hpp"