From 436c5c0d8897cfdee865a4302d7220a08f440e81 Mon Sep 17 00:00:00 2001 From: Sylvester Joosten <sjoosten@anl.gov> Date: Tue, 22 Dec 2020 13:55:43 +0000 Subject: [PATCH] treat 'weight' as optional variable, initialized to 1 --- util/benchmark.hh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/util/benchmark.hh b/util/benchmark.hh index 329b5781..ad0f1774 100644 --- a/util/benchmark.hh +++ b/util/benchmark.hh @@ -69,17 +69,20 @@ struct test_definition_error : exception { // - result: pass/fail/error struct test { test(nlohmann::json definition) : json{std::move(definition)} { - json["weight"] = 1.0; // initialize with error (as we don't have a value yet) error(); // Check that all required fields are present for (const auto& field : {"name", "title", "description", "quantity", - "target", "value", "weight", "result"}) { + "target", "value", "result"}) { if (json.find(field) == json.end()) { throw test_definition_error{ fmt::format("Error in test definition: field '{}' missing", field)}; } } + // Default "weight" to 1 if not set + if (json.find("weight") == json.end()) { + json["weight"] = 1.0; + } } // Set this test to pass/fail/error void pass(double value) { update_result("pass", value); } -- GitLab