Сравнить коммиты
33 Коммитов
933469b806
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| e6cf551e5c | |||
| 670a9f51be | |||
| 85854badfe | |||
| c3dfd48d9c | |||
| dce3a5e3ea | |||
| 09bdc941a0 | |||
| f3ae62da78 | |||
| 96f7324eb0 | |||
| 75383e1fd3 | |||
| f2c4302ba4 | |||
| 677c96e4eb | |||
| 60b185ed4e | |||
| d04adf230e | |||
| 68ebbd1eba | |||
| 0aee2ca9c5 | |||
| e03167e6b7 | |||
| b78aaf0024 | |||
| 5311fee313 | |||
| 451f768394 | |||
| e8f60325e9 | |||
| aa5eb0f096 | |||
| 95a128b320 | |||
| 921a966a37 | |||
| 9a832aeca2 | |||
| 356d6aff92 | |||
| cb7fede4b2 | |||
| 955d11171a | |||
| fcf2ce93ec | |||
| b32452598b | |||
| 22674d1f7c | |||
| 807629dfb5 | |||
| f5b20f01bd | |||
| fcc80d02f1 |
3
Histogram/.gitignore
поставляемый
3
Histogram/.gitignore
поставляемый
@@ -1,2 +1,3 @@
|
||||
bin/
|
||||
obj/
|
||||
obj/
|
||||
curl/
|
||||
@@ -13,7 +13,13 @@
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
<Add option="-DCURL_STATICLIB" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/Histogram" prefix_auto="1" extension_auto="1" />
|
||||
@@ -22,17 +28,34 @@
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
<Add option="-DCURL_STATICLIB" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
<Add library="libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add option="-DCURL_STATICLIB" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
91
Histogram/Histogram.depend
Обычный файл
91
Histogram/Histogram.depend
Обычный файл
@@ -0,0 +1,91 @@
|
||||
# depslib dependency file v1.0
|
||||
1748183279 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
<string>
|
||||
<sstream>
|
||||
<curl/curl.h>
|
||||
|
||||
1745795032 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.h
|
||||
<vector>
|
||||
|
||||
1745791758 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\text.h
|
||||
<vector>
|
||||
|
||||
1747164718 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
<string>
|
||||
<vector>
|
||||
|
||||
1745841059 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\svg.h
|
||||
<iostream>
|
||||
<string>
|
||||
<vector>
|
||||
|
||||
1746443355 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745841101 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<string>
|
||||
"svg.h"
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\curl.h
|
||||
"curlver.h"
|
||||
"system.h"
|
||||
<stdio.h>
|
||||
<limits.h>
|
||||
<sys/param.h>
|
||||
<sys/types.h>
|
||||
<time.h>
|
||||
<winsock2.h>
|
||||
<ws2tcpip.h>
|
||||
<sys/select.h>
|
||||
<sys/socket.h>
|
||||
<sys/time.h>
|
||||
"easy.h"
|
||||
"multi.h"
|
||||
"urlapi.h"
|
||||
"options.h"
|
||||
"header.h"
|
||||
"websockets.h"
|
||||
"mprintf.h"
|
||||
"typecheck-gcc.h"
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\curlver.h
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\system.h
|
||||
<ConditionalMacros.h>
|
||||
<inttypes.h>
|
||||
<inttypes.h>
|
||||
<sys/types.h>
|
||||
<sys/socket.h>
|
||||
<sys/poll.h>
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\easy.h
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\multi.h
|
||||
"curl.h"
|
||||
|
||||
1747048791 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\urlapi.h
|
||||
"curl.h"
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\options.h
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\header.h
|
||||
|
||||
1747048791 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\websockets.h
|
||||
|
||||
1747048790 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\mprintf.h
|
||||
<stdarg.h>
|
||||
<stdio.h>
|
||||
"curl.h"
|
||||
|
||||
1747048791 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\curl\include\curl\typecheck-gcc.h
|
||||
|
||||
45
Histogram/Histogram.layout
Обычный файл
45
Histogram/Histogram.layout
Обычный файл
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="text.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="93" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="17" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="931" topLine="12" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1632" topLine="55" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="323" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="116" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="33" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
Двоичные данные
Histogram/bin/Debug/Histogram.exe
Двоичные данные
Histogram/bin/Debug/Histogram.exe
Двоичный файл не отображается.
71
Histogram/histogram.cpp
Обычный файл
71
Histogram/histogram.cpp
Обычный файл
@@ -0,0 +1,71 @@
|
||||
#include "histogram.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "svg.h"
|
||||
|
||||
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max) {
|
||||
if (numbers.empty()) {
|
||||
min = max = 0;
|
||||
return 0;
|
||||
}
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double number : numbers) {
|
||||
if (number < min) {
|
||||
min = number;
|
||||
}
|
||||
if (number > max) {
|
||||
max = number;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count) {
|
||||
std::vector<size_t> bins(bin_count, 0);
|
||||
if (numbers.empty() || bin_count == 0) {
|
||||
return bins;
|
||||
}
|
||||
double min, max;
|
||||
find_minmax(numbers, min, max);
|
||||
if (max == min) {
|
||||
|
||||
return bins;
|
||||
|
||||
return bins;
|
||||
|
||||
}
|
||||
double bin_width = (max - min) / bin_count;
|
||||
for (double number : numbers) {
|
||||
size_t bin_index = static_cast<size_t>((number - min) / bin_width);
|
||||
if (bin_index >= bin_count) {
|
||||
|
||||
bin_index = bin_count - 1;
|
||||
|
||||
bin_index = bin_count - 1;
|
||||
|
||||
}
|
||||
bins[bin_index]++;
|
||||
}
|
||||
return bins;
|
||||
};
|
||||
|
||||
|
||||
void show_histogram_svg(const std::vector<size_t>& bins) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
for (size_t i = 0; i < bins.size(); ++i) {
|
||||
const double bin_width = BLOCK_WIDTH * bins[i];
|
||||
const double top = i * BIN_HEIGHT;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#aaffaa");
|
||||
}
|
||||
svg_end();
|
||||
}
|
||||
|
||||
5
Histogram/histogram.h
Обычный файл
5
Histogram/histogram.h
Обычный файл
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||
3
Histogram/histogram_internal.h
Обычный файл
3
Histogram/histogram_internal.h
Обычный файл
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
size_t find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||
@@ -1,86 +1,82 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include <curl/curl.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
struct Input{
|
||||
std::vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
Input input_data(std::istream& in, bool prompt) {
|
||||
size_t number_count;
|
||||
if (prompt){
|
||||
std::cerr << "Enter number count: ";
|
||||
}
|
||||
in >> number_count;
|
||||
|
||||
if (prompt){
|
||||
std::cerr << "Enter numbers: \n";
|
||||
}
|
||||
|
||||
Input result;
|
||||
result.numbers.resize(number_count);
|
||||
for (size_t i = 0; i < number_count; ++i) {
|
||||
in >> result.numbers[i];
|
||||
}
|
||||
|
||||
if (prompt){
|
||||
std::cerr << "Enter bucket: ";
|
||||
}
|
||||
|
||||
in >> result.bin_count;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
size_t write_data(void*items,size_t item_size, size_t item_count, void* ctx){
|
||||
size_t data_size = item_size * item_count;
|
||||
std::stringstream* buffer = static_cast<std::stringstream*>(ctx);
|
||||
(*buffer).write(reinterpret_cast<const char*>(items), data_size);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
Input download(const std::string&address){
|
||||
std::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){
|
||||
std::cerr << curl_easy_strerror(res);
|
||||
curl_easy_cleanup(curl);
|
||||
exit(1);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
|
||||
int number_count, bucket;
|
||||
|
||||
cerr << "Enter number count: "; cin >> number_count;
|
||||
|
||||
std::cerr << "Enter numbers: \n";
|
||||
vector <double> numbers(number_count);
|
||||
for (int i = 0; i < number_count; i++) cin >> numbers[i];
|
||||
|
||||
float min = numbers[0];
|
||||
float max = numbers[0];
|
||||
|
||||
for (float x : numbers)
|
||||
{
|
||||
if (x < min) min = x;
|
||||
else if (x > max) max = x;
|
||||
}
|
||||
|
||||
if (max == min) {// ïðîâåðêà íà àíîìàëèþ
|
||||
std::cout << " Unable to create a histogram." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cerr << "Enter bucket: "; cin >> bucket;
|
||||
|
||||
float k = (max - min) / bucket;
|
||||
|
||||
if (numbers.empty()) {//áûëè ëè ââåäåíû ÷èñëà
|
||||
std::cout << "Empty. unable to create histogram." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
vector <int> stolb(bucket);
|
||||
vector <int> proz(stolb);
|
||||
|
||||
for (int j = 0; j < bucket; j++) stolb[j] = 0;
|
||||
|
||||
for (int i = 0; i < number_count; i++)
|
||||
{
|
||||
bool flag = false;
|
||||
for (int j = 0; (j < bucket && !flag); j++)
|
||||
{
|
||||
if (numbers[i] >= (min + k * j) && numbers[i] < (min + k * (1 + j)))
|
||||
{
|
||||
stolb[j]++;
|
||||
flag = true;
|
||||
|
||||
}
|
||||
}
|
||||
if (!flag) stolb[bucket - 1]++;
|
||||
}
|
||||
|
||||
int maxlen = 0;
|
||||
for (int j = 0; j < bucket; j++)
|
||||
{
|
||||
if (maxlen < stolb[j]) maxlen = stolb[j];
|
||||
}
|
||||
|
||||
for (int j = 0; j < bucket; j++)
|
||||
{
|
||||
if (stolb[j] < 100) cout << " ";
|
||||
if (stolb[j] < 10) cout << "";
|
||||
cout << stolb[j] << " |";
|
||||
size_t height = stolb[j];
|
||||
if (maxlen > MAX_ASTERISK)
|
||||
{
|
||||
if (maxlen != stolb[j]) height = MAX_ASTERISK * (static_cast <float>(stolb[j]) / maxlen);
|
||||
else if (maxlen == stolb[j]) height = MAX_ASTERISK;
|
||||
}
|
||||
for (int i = 0; i < height; i++) cout << "*";
|
||||
cout << "\n";
|
||||
int main(int argc, char* argv[]) {
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
} else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
|
||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Двоичные данные
Histogram/obj/Debug/main.o
Двоичные данные
Histogram/obj/Debug/main.o
Двоичный файл не отображается.
46
Histogram/svg.cpp
Обычный файл
46
Histogram/svg.cpp
Обычный файл
@@ -0,0 +1,46 @@
|
||||
#include "svg.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void svg_begin(double width, double height) {
|
||||
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
std::cout << "<svg ";
|
||||
std::cout << "width='" << width << "' ";
|
||||
std::cout << "height='" << height << "' ";
|
||||
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
void svg_end() {
|
||||
std::cout << "</svg>\n";
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height, std::string stroke, std::string fill) {
|
||||
std::cout << "<rect x='" << x<< "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />\n";
|
||||
}
|
||||
|
||||
void svg_text(double left, double baseline, std::string text) {
|
||||
std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>\n";
|
||||
}
|
||||
void show_histogram_svg(const std::vector<size_t>& bins) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
for (size_t i = 0; i < bins.size(); ++i) {
|
||||
const double bin_width = BLOCK_WIDTH * bins[i];
|
||||
const double top = i * BIN_HEIGHT;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "black", "#aaffaa");
|
||||
}
|
||||
svg_end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
10
Histogram/svg.h
Обычный файл
10
Histogram/svg.h
Обычный файл
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void svg_begin(double width, double height);
|
||||
void svg_end();
|
||||
void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
|
||||
void svg_text(double left, double baseline, std::string text);
|
||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||
Двоичные данные
Histogram/svg.o
Обычный файл
Двоичные данные
Histogram/svg.o
Обычный файл
Двоичный файл не отображается.
30
Histogram/text.cpp
Обычный файл
30
Histogram/text.cpp
Обычный файл
@@ -0,0 +1,30 @@
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(const std::vector<size_t>& bins) {
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
size_t max_bin = 0;
|
||||
for (size_t bin : bins) {
|
||||
if (bin > max_bin) {
|
||||
max_bin = bin;
|
||||
}
|
||||
|
||||
for (size_t bin_value : bins) {
|
||||
if (bin_value < 100) std::cout << " ";
|
||||
if (bin_value < 10) std::cout << " ";
|
||||
std::cout << bin_value << " |";
|
||||
size_t height = bin_value;
|
||||
if (max_bin > MAX_ASTERISK) {
|
||||
height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin_value) / max_bin));
|
||||
}
|
||||
for (size_t i = 0; i < height; ++i) {
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
4
Histogram/text.h
Обычный файл
4
Histogram/text.h
Обычный файл
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
void show_histogram_text(const std::vector<size_t>& bins);
|
||||
|
||||
Двоичные данные
bin/Debug/unittest.exe
Обычный файл
Двоичные данные
bin/Debug/unittest.exe
Обычный файл
Двоичный файл не отображается.
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Двоичные данные
obj/Debug/Histogram/histogram.o
Обычный файл
Двоичные данные
obj/Debug/Histogram/histogram.o
Обычный файл
Двоичный файл не отображается.
Двоичные данные
obj/Debug/unittest.o
Обычный файл
Двоичные данные
obj/Debug/unittest.o
Обычный файл
Двоичный файл не отображается.
41
unittest.cbp
Обычный файл
41
unittest.cbp
Обычный файл
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="Histogram/histogram.cpp" />
|
||||
<Unit filename="Histogram/histogram_internal.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
44
unittest.cpp
Обычный файл
44
unittest.cpp
Обычный файл
@@ -0,0 +1,44 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "Histogram/histogram_internal.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("single element vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({5}, min, max);
|
||||
CHECK(min == 5);
|
||||
CHECK(max == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-3, -1}, min, max);
|
||||
CHECK(min == -3);
|
||||
CHECK(max == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("identical elements") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({4, 4, 4}, min, max);
|
||||
CHECK(min == 4);
|
||||
CHECK(max == 4);
|
||||
}
|
||||
61
unittest.depend
Обычный файл
61
unittest.depend
Обычный файл
@@ -0,0 +1,61 @@
|
||||
# depslib dependency file v1.0
|
||||
1745791868 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.cpp
|
||||
"histogram.h"
|
||||
<vector>
|
||||
<algorithm>
|
||||
|
||||
1745791871 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram.h
|
||||
<vector>
|
||||
|
||||
1745793818 source:c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\unittest.cpp
|
||||
"doctest.h"
|
||||
"Histogram/histogram_internal.h"
|
||||
|
||||
1745792535 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1745792105 c:\users\yaros_tm2sc6p\Ðàáî÷èé ñòîë\cs-lab34\histogram\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
10
unittest.layout
Обычный файл
10
unittest.layout
Обычный файл
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="271" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
Ссылка в новой задаче
Block a user