From d022b0a95bfd47211d14c0ed32be26064d49ecba Mon Sep 17 00:00:00 2001 From: "Daniil (FilippovDY)" Date: Thu, 9 May 2024 21:11:09 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=BA=D0=BE=D0=BD=D0=B5=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 5 ++--- histogram_internal.h | 2 +- main.cpp | 1 - unittest.cpp | 27 +++++---------------------- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 2d35027..71b6fc5 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,11 +1,10 @@ #include "histogram.h" #include #include "histogram_internal.h" -void find_minmax(const std::vector &numbers, double &min, double &max, bool &res) +void find_minmax(const std::vector &numbers, double &min, double &max) { if (numbers.size()==0) { - res = true; return; } min = numbers[0]; @@ -26,7 +25,7 @@ std::vector make_histogram(const std::vector &numbers, std: { double min, max; bool res = false; - find_minmax(numbers, min, max, res); + find_minmax(numbers, min, max); double bin_size = (max - min) / bin_count; std::vector bins (bin_count); diff --git a/histogram_internal.h b/histogram_internal.h index 44594cb..a4eddaa 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -3,6 +3,6 @@ #include -void find_minmax(const std::vector &numbers, double &min, double &max, bool &res); +void find_minmax(const std::vector &numbers, double &min, double &max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/main.cpp b/main.cpp index 5677ea7..92cb303 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,6 @@ input_data() int main() { - bool res = false; Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); diff --git a/unittest.cpp b/unittest.cpp index 3cfebd4..966bf30 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -6,52 +6,35 @@ TEST_CASE("distinct positive numbers") { - bool res = false; double min = 0; double max = 0; - find_minmax({1, 2}, min, max, res); + find_minmax({1, 2}, min, max); CHECK(min == 1); CHECK(max == 2); - CHECK(res==0); } TEST_CASE("negative numbers") { - bool res = false; double min = 0; double max = 0; - find_minmax({-1, -2}, min, max, res); + find_minmax({-1, -2}, min, max); CHECK(min == -2); CHECK(max == -1); - CHECK(res==0); } -TEST_CASE("empty array") { - bool res = false; +TEST_CASE("empty vector") { double min = 0; double max = 0; std::vector numbers; - find_minmax(numbers, min, max, res); + find_minmax(numbers, min, max); CHECK(min == 0); CHECK(max == 0); - CHECK(res==1); } TEST_CASE("1 number") { - bool res = false; double min = 0; double max = 0; - find_minmax({-1}, min, max, res); + find_minmax({-1}, min, max); CHECK(min == -1); CHECK(max == -1); - CHECK(res==0); } -TEST_CASE("same number") { - bool res = false; - double min = 0; - double max = 0; - find_minmax({1,1,1,1}, min, max, res); - CHECK(min == 1); - CHECK(max == 1); - CHECK(res==0); -}