From 5bfd1b3ef9ed3352034d3a586a38d504c4046ab5 Mon Sep 17 00:00:00 2001 From: LedovskojMM Date: Mon, 5 Jun 2023 16:10:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=BD=D0=B4=D0=B8=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D1=83=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogam.cpp | 30 +++++++++++++++++++----------- histogam_internal.h | 5 +++-- lab1.depend | 18 ++++++++++-------- main.cpp | 36 ++++++++++++++++++++++++------------ svg.cpp | 1 + svg.h | 1 + text.cpp | 1 + unittest.cpp | 34 +++++++++++++++++++++++++++++++++- unittest.depend | 6 +++--- 9 files changed, 95 insertions(+), 37 deletions(-) diff --git a/histogam.cpp b/histogam.cpp index d2c9e3e..ac5296a 100644 --- a/histogam.cpp +++ b/histogam.cpp @@ -6,21 +6,28 @@ #include using namespace std; -/*void find_minmax(vector numbers, double& min, double& max) { - min = numbers[0]; - for (auto i = 0; i < numbers.size(); i++) { - if (numbers[i] < min) { - min = numbers[i]; - } +/*bool find_minmax(vector numbers, double& min, double& max) { + if (numbers.empty()) + { + return true; } + else + { + min = numbers[0]; + for (auto i = 0; i < numbers.size(); i++) { + if (numbers[i] < min) { + min = numbers[i]; + } + } - max = numbers[0]; - for (auto i = 0; i < numbers.size(); i++) { - if (numbers[i] > max) { - max = numbers[i]; + max = numbers[0]; + for (auto i = 0; i < numbers.size(); i++) { + if (numbers[i] > max) { + max = numbers[i]; + } } } - + return false; } vector make_histogram(const vector& numbers, size_t bin_count) { @@ -113,3 +120,4 @@ vector make_histogram (vector numbers, size_t bin_count) return bins; } + diff --git a/histogam_internal.h b/histogam_internal.h index 2a76b21..38bf3e8 100644 --- a/histogam_internal.h +++ b/histogam_internal.h @@ -2,8 +2,9 @@ #define HISTOGAM_INTERNAL_H_INCLUDED #include -/* + void find_minmax(std::vector numbers, double& min, double& max); + +/*bool find_minmax(std::vector numbers, double& min, double& max); */ -void find_minmax(std::vector numbers, double& min, double& max); #endif // HISTOGAM_INTERNAL_H_INCLUDED diff --git a/lab1.depend b/lab1.depend index b4eb036..13820bd 100644 --- a/lab1.depend +++ b/lab1.depend @@ -3,22 +3,24 @@ -1685897816 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp +1685968543 source:c:\users\admin\onedrive\Рабочий стол\lab1\main.cpp "histogam.h" "text.h" - "svg.h" "histogam_internal.h" + + + "svg.h" -1685896776 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h +1685967301 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h -1685896777 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp +1685967301 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp @@ -26,7 +28,7 @@ "histogam_internal.h" -1685896776 source:c:\users\admin\onedrive\Рабочий стол\lab1\text.cpp +1685967301 source:c:\users\admin\onedrive\Рабочий стол\lab1\text.cpp @@ -36,10 +38,10 @@ 1685896777 c:\users\admin\onedrive\Рабочий стол\lab1\text.h -1685896777 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h +1685967301 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h -1685896777 source:c:\users\admin\onedrive\Рабочий стол\lab1\svg.cpp +1685967301 source:c:\users\admin\onedrive\Рабочий стол\lab1\svg.cpp @@ -47,7 +49,7 @@ "svg.h" -1685896776 c:\users\admin\onedrive\Рабочий стол\lab1\svg.h +1685967301 c:\users\admin\onedrive\Рабочий стол\lab1\svg.h 1685361112 c:\users\admin\onedrive\Рабочий стол\lab1\curl\include\curl\curl.h "curlver.h" diff --git a/main.cpp b/main.cpp index ed89220..6a70412 100644 --- a/main.cpp +++ b/main.cpp @@ -4,12 +4,12 @@ #include #include "histogam.h" #include "text.h" -#include "svg.h" #include #include "histogam_internal.h" #include #include #include +#include "svg.h" using namespace std; @@ -45,7 +45,8 @@ int main() return 0; } */ -struct Input { +struct Input +{ vector numbers; size_t bin_count{}; }; @@ -54,7 +55,7 @@ Input input_data(istream& in, bool promt) { size_t number_count; - if (promt) + if (promt) { cerr << "Enter number count: "; } @@ -65,7 +66,10 @@ input_data(istream& in, bool promt) { in >> ik.numbers[i]; } - cerr << "Enter bin count: "; + if (promt) + { + cerr << "Enter bin count: "; + } in>> ik.bin_count; return ik; } @@ -74,31 +78,38 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) { size_t data_size = item_size * item_count; stringstream* buffer = reinterpret_cast(ctx); - buffer->write(static_cast(items), data_size); - return 0; + buffer->write(reinterpret_cast(items), data_size); + return data_size; } Input download(const string& address) { -stringstream buffer; + stringstream buffer; CURL *curl = curl_easy_init(); if(curl) { CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, address); + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); res = curl_easy_perform(curl); - curl_easy_cleanup(curl); if (res != CURLE_OK) { - cout << curl_easy_strerror; + fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); exit(1); } - } - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); + if(res == CURLE_OK) + { + long req; + res = curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &req); + if(!res) + cerr<<"Request size: %ld bytes: "<< req; + } + curl_easy_cleanup(curl); + } return input_data(buffer, false); } @@ -118,3 +129,4 @@ int main(int argc, char* argv[]) const auto bins = make_histogram(input.numbers, input.bin_count); show_histogram_svg(bins); } + diff --git a/svg.cpp b/svg.cpp index 3767df5..9d5db91 100644 --- a/svg.cpp +++ b/svg.cpp @@ -139,3 +139,4 @@ show_histogram_svg(const vector& bins) svg_end(); } + diff --git a/svg.h b/svg.h index b06353d..1af028a 100644 --- a/svg.h +++ b/svg.h @@ -6,4 +6,5 @@ show_histogram_svg(const std::vector& bins,double min, double max); */ void show_histogram_svg(const std::vector& bins); + #endif // SVG_H_INCLUDED diff --git a/text.cpp b/text.cpp index 9193bf3..7771c3e 100644 --- a/text.cpp +++ b/text.cpp @@ -69,3 +69,4 @@ void show_histogram_text(vector bins, size_t bin_count) cout << endl; } } + diff --git a/unittest.cpp b/unittest.cpp index 87d0670..8e31da8 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -8,10 +8,42 @@ TEST_CASE("distinct positive numbers") { double min = 0; double max = 0; std::vectorf{1,2}; - CHECK(f.size() != 0); + + find_minmax(f, min, max); + CHECK(min == 1); + CHECK(max == 2); + CHECK(min != max); +} + +TEST_CASE("distinct positive numbers") { + double min = 0; + double max = 0; + std::vectorf{}; + CHECK(find_minmax(f, min, max) != 0); CHECK(f.size() != 1); find_minmax(f, min, max); CHECK(min == 1); CHECK(max == 2); CHECK(min != max); } +TEST_CASE("void vector") { + double min = 3; + double max = 2; + std::vector numbers {}; + bool check = find_minmax(numbers, min, max); + CHECK(check == true); +} +TEST_CASE("vector with same elements") { + double min = 0; + double max = 0; + find_minmax({2,2,2}, min, max); + CHECK(min == 2); + CHECK(max == 2); +} +TEST_CASE("vector with one element") { + double min = 0; + double max = 0; + find_minmax({1}, min, max); + CHECK(min == 1); + CHECK(max == 1); +} diff --git a/unittest.depend b/unittest.depend index 8c7924e..1a45385 100644 --- a/unittest.depend +++ b/unittest.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1682280773 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp +1685962483 source:c:\users\admin\onedrive\Рабочий стол\lab1\histogam.cpp @@ -7,10 +7,10 @@ "histogam_internal.h" -1682273839 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h +1685896776 c:\users\admin\onedrive\Рабочий стол\lab1\histogam.h -1682273796 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h +1685896777 c:\users\admin\onedrive\Рабочий стол\lab1\histogam_internal.h 1682276830 source:c:\users\admin\onedrive\Рабочий стол\lab1\unittest.cpp