From b8a8ebdeba55129da261cb9a802a536d53a58da3 Mon Sep 17 00:00:00 2001 From: BushmanovAS Date: Mon, 27 May 2024 07:30:46 +0300 Subject: [PATCH] Input data --- main.cpp | 23 ++++++++++++----------- project.cbp | 7 +++++++ svg.h | 1 - unittest.cbp | 2 ++ unittest.cpp | 37 +++++++++++++++++++++++-------------- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/main.cpp b/main.cpp index cbfe033..4704d3f 100644 --- a/main.cpp +++ b/main.cpp @@ -12,26 +12,27 @@ struct Input size_t bin_count{}; }; -Input -input_data() +Input input_data(istream& in, bool prompt = true) { size_t number_count; - cerr << "Enter number count: "; - cin >> number_count; - Input in; - in.numbers.resize(number_count); + if (prompt) + cerr << "Enter number count: "; + in >> number_count; + Input input; + input.numbers.resize(number_count); for (size_t i = 0; i < number_count; i++) { - cin >> in.numbers[i]; + in >> input.numbers[i]; } - cerr << "Enter bin count: "; - cin >> in.bin_count; - return in; + if (prompt) + cerr << "Enter bin count: "; + in >> input.bin_count; + return input; } int main() { - Input in = input_data(); + Input in = input_data(cin); vector bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); } diff --git a/project.cbp b/project.cbp index 99bb702..fda6f8f 100644 --- a/project.cbp +++ b/project.cbp @@ -32,7 +32,14 @@ + + + + + + + diff --git a/svg.h b/svg.h index 85ae932..af68030 100644 --- a/svg.h +++ b/svg.h @@ -1,6 +1,5 @@ #ifndef SVG_H_INCLUDED #define SVG_H_INCLUDED - #include void diff --git a/unittest.cbp b/unittest.cbp index bffa065..4577330 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -36,6 +36,8 @@ + + diff --git a/unittest.cpp b/unittest.cpp index 0708330..afddc34 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -3,6 +3,8 @@ #include #include "doctest.h" #include "histogram_internal.h" +#include "svg.h" +#include TEST_CASE("distinct positive numbers") { double min = 0; @@ -19,15 +21,6 @@ TEST_CASE("negative numbers") { CHECK(min == -10); CHECK(max == 10); } - -TEST_CASE("empty numbers") { - double min = 0; - double max = 0; - find_minmax({ }, min, max); - CHECK(min != 0); - CHECK(max != 0); -} - TEST_CASE("one number") { double min = 0; double max = 0; @@ -36,9 +29,25 @@ TEST_CASE("one number") { CHECK(max == 2); } - - - - - +#include "doctest.h" +#include "svg.h" +#include +#include + +TEST_CASE("show_histogram_svg") { + std::ostringstream oss; + std::streambuf* p_cout_streambuf = std::cout.rdbuf(); + std::cout.rdbuf(oss.rdbuf()); + show_histogram_svg({1, 2, 3, 4}); + std::cout.rdbuf(p_cout_streambuf); + std::string result = oss.str(); + std::string expected = "" +"" +"" +"1" +"2" +"3" +"4"; + CHECK(result == expected); +}