Skip to content
Snippets Groups Projects
Commit dacf8400 authored by Sam Yates's avatar Sam Yates
Browse files

Address PR comments

* Add unit test that demonstrates need for non-const version
  of `max_element_by`
* Rename file stream member variable from `f_` to `out_`
  in `validation_data.hpp`.
parent ee3b83c5
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment