Сравнить коммиты
7 Коммитов
c8a6ffa64e
...
e21d76458b
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
e21d76458b | ||
|
|
5674291233 | ||
|
|
97f925d3dd | ||
|
|
cec2dbfb0e | ||
|
|
789608bb21 | ||
|
|
f04f03e39d | ||
|
|
b65861bb23 |
Двоичные данные
project/.gitignore
поставляемый
Двоичные данные
project/.gitignore
поставляемый
Двоичный файл не отображается.
@@ -2,38 +2,58 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#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)
|
||||||
|
{
|
||||||
|
bool check;
|
||||||
|
if(numbers.size()==0)
|
||||||
|
{
|
||||||
|
|
||||||
|
check = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
for (double x : numbers) {
|
for (double x : numbers)
|
||||||
if (x < min) {
|
{
|
||||||
|
if (x < min)
|
||||||
|
{
|
||||||
min = x;
|
min = x;
|
||||||
}
|
}
|
||||||
else if (x > max) {
|
else if (x > max)
|
||||||
|
{
|
||||||
max = x;
|
max = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return check;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t>
|
vector<size_t>
|
||||||
make_histogram(vector<double> numbers, size_t bin_count) {
|
make_histogram(vector<double> numbers, size_t bin_count)
|
||||||
|
{
|
||||||
vector <size_t> bins(bin_count);
|
vector <size_t> bins(bin_count);
|
||||||
double min, max;
|
double min, max;
|
||||||
find_minmax(numbers, min, max);
|
bool check;
|
||||||
|
check = find_minmax(numbers, min, max);
|
||||||
size_t countt;
|
size_t countt;
|
||||||
double bin_size = (max - min) / bin_count;
|
double bin_size = (max - min) / bin_count;
|
||||||
for (size_t i = 0; i < numbers.size(); i++) {
|
for (size_t i = 0; i < numbers.size(); i++)
|
||||||
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||||
|
{
|
||||||
auto lo = min + j * bin_size;
|
auto lo = min + j * bin_size;
|
||||||
auto hi = min + (j + 1) * bin_size;
|
auto hi = min + (j + 1) * bin_size;
|
||||||
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||||
|
{
|
||||||
bins[j]++;
|
bins[j]++;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found)
|
||||||
|
{
|
||||||
bins[bin_count - 1]++;
|
bins[bin_count - 1]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
{
|
||||||
show_histogram_svg(bins);
|
size_t data_size = item_size * item_count;
|
||||||
return 0;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,12 @@
|
|||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
|
<Add directory="curl/include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add library="libcurl.dll.a" />
|
||||||
|
<Add directory="curl/lib" />
|
||||||
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release">
|
<Target title="Release">
|
||||||
<Option output="bin/Release/project" prefix_auto="1" extension_auto="1" />
|
<Option output="bin/Release/project" prefix_auto="1" extension_auto="1" />
|
||||||
@@ -32,7 +37,31 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename=".gitignore" />
|
||||||
|
<Unit filename="emptiness.cpp" />
|
||||||
|
<Unit filename="emptiness.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="histogram_internal.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="tasktest.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="test.cpp" />
|
||||||
|
<Unit filename="text.cpp" />
|
||||||
|
<Unit filename="text.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Extensions />
|
<Extensions />
|
||||||
</Project>
|
</Project>
|
||||||
</CodeBlocks_project_file>
|
</CodeBlocks_project_file>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "emptiness.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -41,7 +42,7 @@ show_histogram_svg(const vector<size_t>& bins) {
|
|||||||
const auto TEXT_WIDTH = 50;
|
const auto TEXT_WIDTH = 50;
|
||||||
const auto BIN_HEIGHT = 30;
|
const auto BIN_HEIGHT = 30;
|
||||||
const auto BLOCK_WIDTH = 10;
|
const auto BLOCK_WIDTH = 10;
|
||||||
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
const double MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||||
@@ -54,8 +55,7 @@ double max_count = bins[0];
|
|||||||
}
|
}
|
||||||
for (size_t bin : bins) {
|
for (size_t bin : bins) {
|
||||||
const double bin_width = MAX_WIDTH * (bin/max_count);
|
const double bin_width = MAX_WIDTH * (bin/max_count);
|
||||||
const double emptiness_width = MAX_WIDTH - bin_width;
|
double emptiness_width = emptiness(MAX_WIDTH,bin_width);
|
||||||
svg_rect(0, top, emptiness_width, BIN_HEIGHT, "white", "#ffffff");
|
|
||||||
svg_text(TEXT_LEFT + MAX_WIDTH, top + TEXT_BASELINE, to_string(bin));
|
svg_text(TEXT_LEFT + MAX_WIDTH, top + TEXT_BASELINE, to_string(bin));
|
||||||
svg_rect(emptiness_width, top, bin_width, BIN_HEIGHT, "red", "#aaffaa");
|
svg_rect(emptiness_width, top, bin_width, BIN_HEIGHT, "red", "#aaffaa");
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
|
|||||||
40
unittest.cpp
40
unittest.cpp
@@ -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);
|
|
||||||
}
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user