code: доделано до индивид задания

main
LiTekho 2 лет назад
Родитель 1f1c7b07d7
Сommit 8c602901e5

@ -5,19 +5,30 @@
#include "histogram.h" #include "histogram.h"
using namespace std; using namespace std;
void bool find_minmax(vector<double> numbers, double& min, double& max)
find_minmax(vector<double> numbers, double &min, double &max)
{ {
min = numbers[0]; if (numbers.empty())
max = numbers[0]; {
for (size_t i = 1; i < numbers.size(); i++) return true;
}
else
{ {
if (min > numbers[i]) min = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] < min) {
min = numbers[i]; min = numbers[i];
if (max < numbers[i]) }
}
max = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] > max) {
max = numbers[i]; max = numbers[i];
} }
} }
}
return false;
}
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count) vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count)
{ {

@ -45,8 +45,8 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
{ {
size_t data_size = item_size * item_count; size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx); stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(static_cast<const char*>(items), data_size); buffer->write(reinterpret_cast<const char*>(items), data_size);
return 0; return data_size;
} }
@ -59,18 +59,19 @@ download(const string& address)
if(curl) if(curl)
{ {
CURLcode res; 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); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if (res != CURLE_OK) if (res != CURLE_OK)
{ {
cout << curl_easy_strerror; fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1); exit(1);
} }
} }
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_cleanup(curl);
return input_data(buffer, false); return input_data(buffer, false);
} }

@ -1,18 +1,56 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING #define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h" #include "doctest.h"
#include "histogram_internal.h" #include "histogram_internal.h"
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") TEST_CASE("distinct positive numbers")
{ {
double min = 0; double min = 0;
double max = 0; double max = 0;
std::vector<double>v{1}; find_minmax({1, 2}, min, max);
CHECK(v.size() != 0); CHECK(min == 1);
CHECK(v.size() != 1); CHECK(max == 2);
find_minmax(v, min, max); }
TEST_CASE("vector with one element")
{
double min = 0;
double max = 0;
find_minmax({1}, min, max);
CHECK(min == 1); CHECK(min == 1);
CHECK(max == 1);
}
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); CHECK(max == 2);
CHECK(min != max); }
TEST_CASE("void vector")
{
double min = 3;
double max = 2;
std::vector<double> numbers {};
bool check = find_minmax(numbers, min, max);
CHECK(check == true);
}
TEST_CASE ("distinct negative numbers")
{
double min = 0;
double max = 0;
find_minmax({-1, -2}, min, max);
CHECK(min == -2);
CHECK(max == -1);
} }

@ -1,9 +1,11 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
1682340687 source:c:\users\dell_latitude_e7440\desktop\lab34\unitest.cpp 1685969210 source:c:\users\dell_latitude_e7440\desktop\lab34\unitest.cpp
"doctest.h" "doctest.h"
"histogram_internal.h" "histogram_internal.h"
<vector> <vector>
<iostream> <iostream>
"doctest.h"
"histogram_internal.h"
1682337424 c:\users\dell_latitude_e7440\desktop\lab34\doctest.h 1682337424 c:\users\dell_latitude_e7440\desktop\lab34\doctest.h
<signal.h> <signal.h>
@ -50,10 +52,10 @@
<sys/time.h> <sys/time.h>
<unistd.h> <unistd.h>
1682340272 c:\users\dell_latitude_e7440\desktop\lab34\histogram_internal.h 1685969301 c:\users\dell_latitude_e7440\desktop\lab34\histogram_internal.h
<vector> <vector>
1682341053 source:c:\users\dell_latitude_e7440\desktop\lab34\histogram.cpp 1685969551 source:c:\users\dell_latitude_e7440\desktop\lab34\histogram.cpp
<math.h> <math.h>
<iostream> <iostream>
<conio.h> <conio.h>

Загрузка…
Отмена
Сохранить