Сравнить коммиты
7 Коммитов
c8a6ffa64e
...
e21d76458b
Автор | SHA1 | Дата |
---|---|---|
![]() |
e21d76458b | 2 лет назад |
![]() |
5674291233 | 2 лет назад |
![]() |
97f925d3dd | 2 лет назад |
![]() |
cec2dbfb0e | 2 лет назад |
![]() |
789608bb21 | 2 лет назад |
![]() |
f04f03e39d | 2 лет назад |
![]() |
b65861bb23 | 2 лет назад |
Двоичный файл не отображается.
@ -1,32 +1,83 @@
|
|||||||
|
#include <curl/curl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "emptiness.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
struct Input {
|
struct Input
|
||||||
|
{
|
||||||
vector<double> numbers;
|
vector<double> numbers;
|
||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(){
|
input_data(istream& tin, bool prompt)
|
||||||
|
{
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
|
if (prompt)
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
tin >> number_count;
|
||||||
Input in;
|
Input in;
|
||||||
in.numbers.resize(number_count);
|
in.numbers.resize(number_count);
|
||||||
for(int i;i<number_count;i++)
|
for(int i; i<number_count; i++)
|
||||||
{
|
{
|
||||||
cin >> in.numbers[i];
|
tin >> in.numbers[i];
|
||||||
}
|
}
|
||||||
|
if (prompt)
|
||||||
cerr << "Enter bin count: ";
|
cerr << "Enter bin count: ";
|
||||||
cin >> in.bin_count;
|
tin >> in.bin_count;
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
int main()
|
|
||||||
{ Input in = input_data();
|
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
{
|
||||||
|
size_t data_size = item_size * item_count;
|
||||||
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input
|
||||||
|
download(const string& address)
|
||||||
|
{
|
||||||
|
stringstream buffer;
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if(curl)
|
||||||
|
{
|
||||||
|
CURLcode res;
|
||||||
|
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);
|
||||||
|
if (res != CURLE_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
|
}
|
||||||
|
return input_data(buffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
Input input;
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
input = download(argv[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
input = input_data(cin, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,38 @@
|
|||||||
#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 "project\emptiness.h"
|
||||||
#include "project\histogram_internal.h"
|
#include "project\histogram_internal.h"
|
||||||
|
|
||||||
TEST_CASE("distinct positive numbers") {
|
TEST_CASE("difference check") {
|
||||||
|
double a = 20;
|
||||||
|
double b = 10;
|
||||||
|
double c = emptiness(a,b);
|
||||||
|
CHECK(c == 10);
|
||||||
|
CHECK(c > 0);
|
||||||
|
}
|
||||||
|
TEST_CASE("more then 0 check") {
|
||||||
|
double a = 20;
|
||||||
|
double b = 10;
|
||||||
|
double c = emptiness(a,b);
|
||||||
|
CHECK(c > 0);
|
||||||
|
}
|
||||||
|
TEST_CASE("less then 0 check") {
|
||||||
|
double a = 10;
|
||||||
|
double b = 20;
|
||||||
|
double c = emptiness(a,b);
|
||||||
|
CHECK(c < 0);
|
||||||
|
}
|
||||||
|
TEST_CASE("not 0 check") {
|
||||||
|
double a = 20;
|
||||||
|
double b = 10;
|
||||||
|
double c = emptiness(a,b);
|
||||||
|
CHECK(c != 0);
|
||||||
|
}
|
||||||
|
TEST_CASE("is massif full") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
std::vector<double>v{2,1};
|
std::vector<double>v{};
|
||||||
CHECK(v.size() != 0);
|
bool c = find_minmax(v,min,max);
|
||||||
CHECK(v.size() != 1);
|
CHECK(c == false);
|
||||||
find_minmax({1, 2}, min, max);
|
}
|
||||||
CHECK(min == 1);
|
|
||||||
CHECK(max == 2);
|
|
||||||
CHECK(min != max);
|
|
||||||
}
|
|
||||||
|
Загрузка…
Ссылка в новой задаче