diff --git a/tests/unit/test_range.cpp b/tests/unit/test_range.cpp index 90df4067f743e4e1baa1a6bdefa0442f9bc34b4c..f486d2239c80f183a73f949ee624657902f14a75 100644 --- a/tests/unit/test_range.cpp +++ b/tests/unit/test_range.cpp @@ -205,6 +205,14 @@ TEST(range, max_element_by) { EXPECT_TRUE((std::is_same<const char *, decltype(i)>::value)); EXPECT_EQ('d', *i); EXPECT_EQ(cstr+9, i); + + // with mutable container + std::vector<int> v = { 1, 3, -5, 2 }; + auto j = util::max_element_by(v, [](int x) { return x*x; }); + EXPECT_EQ(-5, *j); + *j = 1; + j = util::max_element_by(v, [](int x) { return x*x; }); + EXPECT_EQ(3, *j); } TEST(range, max_value) { diff --git a/tests/validation/validation_data.hpp b/tests/validation/validation_data.hpp index d9026da3df5ce1e53638c6b2a4ebf6987fa3cde6..70e99a52227b70f9772dd94370ec38fb7301e2d1 100644 --- a/tests/validation/validation_data.hpp +++ b/tests/validation/validation_data.hpp @@ -34,9 +34,9 @@ public: } void write_traces() { - if (f_) { - f_ << jtraces_; - f_.close(); + if (out_) { + out_ << jtraces_; + out_.close(); } } @@ -55,8 +55,8 @@ public: void set_datadir(const util::path& dir) { datadir_ = dir; } void set_output(const util::path& file) { - f_.open(file); - if (!f_) { + out_.open(file); + if (!out_) { throw std::runtime_error("unable to open file for writing"); } } @@ -64,14 +64,14 @@ public: // write traces on exit ~trace_io() { - if (f_) { + if (out_) { write_traces(); } } private: util::path datadir_ = DATADIR "/validation"; - std::ofstream f_; + std::ofstream out_; nlohmann::json jtraces_ = nlohmann::json::array(); bool verbose_flag_ = false; int max_ncomp_ = 1000;