diff --git a/project/histogram.cpp b/project/histogram.cpp index 8913643..8432327 100644 --- a/project/histogram.cpp +++ b/project/histogram.cpp @@ -6,17 +6,24 @@ using namespace std; void find_minmax(vector numbers, double& min, double& max) { - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) + if (numbers.empty()) { - if (x < min) - { - min = x; - } - else if (x > max) + min = max = 0; + } + else + { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { - max = x; + if (x < min) + { + min = x; + } + else if (x > max) + { + max = x; + } } } return; diff --git a/unittest.cpp b/unittest.cpp index 9646fb8..09b46e0 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -34,7 +34,8 @@ TEST_CASE("vector with same elements") { TEST_CASE("void vector") { double min = 0; double max = 0; - find_minmax({0}, min, max); + std::vector numbers {}; + find_minmax( numbers, min, max); CHECK(min == 0); CHECK(max == 0); }