diff --git a/Lab01.cbp b/Lab01.cbp index 5d67df3..fafc2c3 100644 --- a/Lab01.cbp +++ b/Lab01.cbp @@ -39,6 +39,7 @@ + diff --git a/doctest.h b/doctest.h index 6f43ce0..5c754cd 100644 --- a/doctest.h +++ b/doctest.h @@ -7104,4 +7104,3 @@ DOCTEST_SUPPRESS_COMMON_WARNINGS_POP #undef NOMINMAX #undef DOCTEST_UNDEF_NOMINMAX #endif // DOCTEST_UNDEF_NOMINMAX - diff --git a/histogram.cpp b/histogram.cpp index 6477f85..a54fe18 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,7 +1,12 @@ #include "histogram.h" #include -void find_minmax(const std::vector &numbers, double &min, double &max) +void find_minmax(const std::vector &numbers, double &min, double &max, bool &res) { + if (numbers.size()==0) + { + res = true; + return; + } min = numbers[0]; max = numbers[0]; for (double x : numbers) @@ -19,7 +24,8 @@ void find_minmax(const std::vector &numbers, double &min, double &max) std::vector make_histogram(const std::vector &numbers, std::size_t bin_count) { double min, max; - find_minmax(numbers, min, max); + bool res = false; + find_minmax(numbers, min, max, res); double bin_size = (max - min) / bin_count; std::vector bins (bin_count); diff --git a/main.cpp b/main.cpp index 8883021..f29ddf9 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,7 @@ input_data() int main() { + bool res = false; Input in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_text(bins); diff --git a/text.cpp b/text.cpp index 34c7d59..5edd2ec 100644 --- a/text.cpp +++ b/text.cpp @@ -8,6 +8,7 @@ const std::size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; void show_histogram_text(const std::vector &bins) { + std::cout< numbers; + find_minmax(numbers, min, max, res); + 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); + 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); +} + +TEST_CASE("same number but zero") { + bool res = false; + double min = 0; + double max = 0; + find_minmax({0,0,0,0}, min, max, res); + CHECK(min == 0); + CHECK(max == 0); + CHECK(res==0); }