diff --git a/histogram.cpp b/histogram.cpp index 50cb037..820c885 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -7,8 +7,9 @@ using namespace std; void find_minmax(const vector& numbers, double& min, double& max){ + if (numbers.size() >=1){ min = numbers[0]; - min = numbers[0]; + max = numbers[0]; for(size_t i=0; i < numbers.size(); i++){ if (numbers[i] < min) { @@ -18,7 +19,7 @@ find_minmax(const vector& numbers, double& min, double& max){ { max = numbers[i]; } - } + }} } diff --git a/histogram_internal.h b/histogram_internal.h index 5c31312..654569d 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -6,3 +6,4 @@ void find_minmax(const std::vector& numbers, double& min, double& max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED + diff --git a/laba3.cbp b/laba3.cbp index 2a15d57..c1218af 100644 --- a/laba3.cbp +++ b/laba3.cbp @@ -32,7 +32,15 @@ + + + + + + + + diff --git a/main.cpp b/main.cpp index 3246b34..e63a609 100644 --- a/main.cpp +++ b/main.cpp @@ -11,8 +11,8 @@ using namespace std; struct Input { vector numbers; size_t bin_count{}; - string stroke; - string fill; + vector stroke; + vector fill; }; Input @@ -34,20 +34,25 @@ input_data(){ cerr << "Enter bin count: "; cin >> in.bin_count; - cerr << "Enter color: "; - cin >> in.stroke; - - cerr << "Enter color to fill: "; - cin >> in.fill; + in.stroke.resize(in.bin_count); + in.fill.resize(in.bin_count); + for (size_t i=0;i>in.stroke[i]; + cerr <<"Enter fill in format RGB:"; + cin >>in.fill[i]; + } return in; } + int main() { auto in = input_data(); std::vector bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins, in.stroke, in.fill); + show_histogram_svg(bins,in.stroke,in.fill); return 0; } + diff --git a/svg.cpp b/svg.cpp index 88bf76a..05a46af 100644 --- a/svg.cpp +++ b/svg.cpp @@ -29,28 +29,9 @@ void svg_rect(double x, double y, double width, double height, string stroke = "chartreuse", string fill = "plum"){ cout << ""; } + void -input_colors(string &colors_stroke, string &colors_fill){ - string color_personal; - cout << "Do you want to change colors? Yes/No" << endl; - cin >> color_personal; - while ((color_personal != "No") && (color_personal != "Yes")){ - cout << "WRONG ANSWER! Try again!" << endl; - cin >> color_personal; - } - if (color_personal == "No"){ - return; - } - else { - cout << "What color for a stroke do you want?" << endl; - cin >> colors_stroke; - cout << "What color to fill do you want?" << endl; - cin >> colors_fill; - } - return; -} -void -show_histogram_svg(const vector& bins, string stroke, string fill) { +show_histogram_svg(const vector& bins, const vector& stroke,const vector& fill) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; const auto TEXT_LEFT = 20; @@ -67,10 +48,10 @@ show_histogram_svg(const vector& bins, string stroke, string fill) { maxel = bin; } } - for (size_t bin : bins) { - const double bin_width = (( IMAGE_WIDTH - TEXT_WIDTH ) / BLOCK_WIDTH ) * ( bin / maxel ); - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill); + for (size_t i=0; i void -show_histogram_svg(const std::vector& bins, std::string stroke, std::string fill); +show_histogram_svg(const std::vector& bins, const std::vector& stroke, const std::vector& fill); diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..cc815ba 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,12 @@ + + + + + + diff --git a/unittest.cpp b/unittest.cpp index f4d7164..0025075 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -2,23 +2,6 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" #include "histogram_internal.h" -#include "input_colors_internal.h" - -TEST_CASE("Mistakes in spelling") { - std::string colors_stroke = "black"; - std::string colors_fill = "green"; - input_colors(colors_stroke, colors_fill); - CHECK(colors_stroke == "yellow"); - CHECK(colors_fill == "pink"); -} - -TEST_CASE("The answer is No") { - std::string colors_stroke = "black"; - std::string colors_fill = "green"; - input_colors(colors_stroke, colors_fill); - CHECK(colors_stroke == "black"); - CHECK(colors_fill == "green"); -} TEST_CASE("distinct positive numbers") { double min = 0; @@ -28,18 +11,32 @@ TEST_CASE("distinct positive numbers") { CHECK(max == 2); } -TEST_CASE("empty vector"){ +TEST_CASE("same elements"){ double min = 0; double max = 0; - find_minmax({ 0, 0 }, min, max); - CHECK(min == 0); - CHECK(max == 0); + find_minmax({ 1, 1 }, min, max); + CHECK(min == max); } -TEST_CASE("same elements"){ +TEST_CASE("only one number"){ double min = 0; double max = 0; - find_minmax({ 1, 1 }, min, max); - CHECK(min == max); - CHECK(max == min); + find_minmax({1}, min, max); + CHECK(min == 1); + CHECK(max == 1); +} + +TEST_CASE("distinct negative numbers") { + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); +} +TEST_CASE("empty vector") { + double min = 0; + double max = 0; + find_minmax({}, min, max); + CHECK(min == 0); + CHECK(max == 0); }