From 6ad5b7518af6b163ae93cc4a25c3c1faf4cc5cad Mon Sep 17 00:00:00 2001 From: AnisenkovPD Date: Sat, 25 May 2024 13:15:57 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B4=D0=B8=D0=BD=D0=B0=D0=BC=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B1=D0=B8=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 3 +++ project.cbp | 17 +++++++++++++++++ svg.cpp | 16 ++++++++++------ unittest.cbp | 6 ++++++ unittest.cpp | 16 +++++++++------- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index e9799ef..492acbd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,9 +1,11 @@ + #include #include #include #include "histogram.h" #include "text.h" #include "svg.h" +#include using namespace std; const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; @@ -44,6 +46,7 @@ input_data(istream& in, bool prompt) { int main() { + curl_global_init(CURL_GLOBAL_ALL); auto in = input_data(cin, true); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins); diff --git a/project.cbp b/project.cbp index 99bb702..bb977d0 100644 --- a/project.cbp +++ b/project.cbp @@ -31,8 +31,25 @@ + + + + + + + + + + + + + + diff --git a/svg.cpp b/svg.cpp index ab008d2..991a57d 100644 --- a/svg.cpp +++ b/svg.cpp @@ -22,14 +22,14 @@ svg_end() { } void -svg_text(double TEXT_LEFT, double BASELINE, string text) { - cout << " " << text << ""; +svg_text(double TEXT_LEFT, double BASELINE, string text, size_t bukva_scale) { + cout << " " << text << ""; } -void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT){ - cout << "\n"; +void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT, string grad){ + cout << "\n"; } void @@ -43,8 +43,11 @@ show_histogram_svg(const vector& bins) { const auto BLOCK_WIDTH = 10; const double SCALE = IMAGE_WIDTH - TEXT_WIDTH; + size_t grad = 0; double max_count = 0; + size_t bukva_scale = 12; + cin >> bukva_scale; for (double x: bins) { if (x > max_count) { max_count = x; @@ -56,8 +59,9 @@ show_histogram_svg(const vector& bins) { double top = 0; for (size_t i = 0; i < bins.size(); i++) { const double bin_width = SCALE * ( bins[i] / max_count); - svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); + grad = (11 - (bins[i] * 9) / max_count); + svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]), bukva_scale); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, to_string(grad)); top += BIN_HEIGHT; cout << endl; cout << bin_width; diff --git a/unittest.cbp b/unittest.cbp index 7f9621b..e720704 100644 --- a/unittest.cbp +++ b/unittest.cbp @@ -31,6 +31,12 @@ + + + + + diff --git a/unittest.cpp b/unittest.cpp index 99ba89b..3192ce9 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -6,17 +6,19 @@ TEST_CASE("distinct positive numbers") { double min = 0; double max = 0; - std::vectortest = {0}; - bool flag; - find_minmax({1, 2}, min, max); CHECK(min == 1); CHECK(max == 2); - +} +TEST_CASE("distinct negative numbers") { + double min = 0; + double max = 0; find_minmax({-1, -2, -3, -4, -5}, min, max); CHECK(min == -5); CHECK(max == -1); - +} +TEST_CASE("distinct null vector") { + double min = 0; + double max = 0; CHECK(!find_minmax({}, min, max)); - CHECK(true); - } +}