Сравнить коммиты
13 Коммитов
968cd5f984
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| d9a2b3648a | |||
| 85eb559f72 | |||
| 9f5bbe976c | |||
| b1c26a9503 | |||
| ee9b12fc4f | |||
| 30304c0921 | |||
| bb51ae70ea | |||
| 7892d51950 | |||
| ccff7aed06 | |||
| 9333e93a79 | |||
| d2fae250dc | |||
| 3f8b583bef | |||
| 455b1f3e75 |
4
.gitignore
поставляемый
4
.gitignore
поставляемый
@@ -1,3 +1,5 @@
|
|||||||
/bin
|
/bin
|
||||||
/obj
|
/obj
|
||||||
/lab1.layout
|
/lab1.layout
|
||||||
|
/curl
|
||||||
|
/lab1.depend
|
||||||
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -1,6 +1,10 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
|
||||||
void find_minmax(vector<double> vec, double& min, double& max) {
|
bool find_minmax(vector<double> vec, double& min, double& max) {
|
||||||
|
if (vec.size() == 0) {
|
||||||
|
cerr << "Empty vec";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
min = vec[0];
|
min = vec[0];
|
||||||
max = vec[0];
|
max = vec[0];
|
||||||
for (double x : vec) {
|
for (double x : vec) {
|
||||||
@@ -12,8 +16,8 @@ void find_minmax(vector<double> vec, double& min, double& max) {
|
|||||||
max = x;
|
max = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t> make_histogram(size_t number, vector<double> vec) {
|
vector<size_t> make_histogram(size_t number, vector<double> vec) {
|
||||||
vector<size_t> bins(number);
|
vector<size_t> bins(number);
|
||||||
double mn, mx;
|
double mn, mx;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define HISTOGRAM_H_INCLUDED
|
#define HISTOGRAM_H_INCLUDED
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
vector<size_t> make_histogram(size_t number, vector<double> vec);
|
vector<size_t> make_histogram(size_t number, vector<double> vec);
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
void find_minmax(std::vector<double> vec, double& min, double& max);
|
bool find_minmax(std::vector<double> vec, double& min, double& max);
|
||||||
|
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|||||||
20
lab1.cbp
20
lab1.cbp
@@ -31,8 +31,28 @@
|
|||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
|
<Add directory="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add library="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/lib/libcurl.dll.a" />
|
||||||
|
<Add directory="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/lib" />
|
||||||
|
</Linker>
|
||||||
|
<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="text.cpp" />
|
||||||
|
<Unit filename="text.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|||||||
85
lab1.depend
Обычный файл
85
lab1.depend
Обычный файл
@@ -0,0 +1,85 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
|
||||||
|
1747403716 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\text.cpp
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1747403716 c:\users\professional\desktop\cs-lab34\lab1\text.h
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1747651892 source:c:\users\professional\desktop\cs-lab34\lab1\main.cpp
|
||||||
|
<curl/curl.h>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1747403716 c:\users\professional\desktop\cs-lab34\lab1\svg.h
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
<math.h>
|
||||||
|
|
||||||
|
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\svg.cpp
|
||||||
|
"svg.h"
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\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"
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\curlver.h
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\system.h
|
||||||
|
<ConditionalMacros.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<inttypes.h>
|
||||||
|
<sys/types.h>
|
||||||
|
<sys/socket.h>
|
||||||
|
<sys/poll.h>
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\easy.h
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\multi.h
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\urlapi.h
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\options.h
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\header.h
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\websockets.h
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\mprintf.h
|
||||||
|
<stdarg.h>
|
||||||
|
<stdio.h>
|
||||||
|
"curl.h"
|
||||||
|
|
||||||
|
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\typecheck-gcc.h
|
||||||
|
|
||||||
179
main.cpp
179
main.cpp
@@ -1,159 +1,68 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
vector<double> numbers;
|
vector<double> vec;
|
||||||
size_t bin_count{};
|
size_t korz{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input input_data(istream &in, bool prompt) {
|
||||||
input_data() {
|
Input data;
|
||||||
size_t number_count, bin_count;
|
size_t n, korz;
|
||||||
double minl, maxl, bin_size;
|
|
||||||
|
|
||||||
|
if (prompt) {
|
||||||
|
cerr << "Number of elements: ";
|
||||||
|
}
|
||||||
|
in >> n;
|
||||||
|
data.vec.resize(n);
|
||||||
|
|
||||||
cerr << "Enter the number of elements: ";
|
if (prompt) {
|
||||||
cin >> number_count;
|
cerr << "Elements: ";
|
||||||
|
}
|
||||||
Input in;
|
for (size_t i = 0; i < n; i++) {
|
||||||
in.numbers.resize(number_count);
|
in >> data.vec[i];
|
||||||
|
|
||||||
vector<double> numbers(number_count);
|
|
||||||
|
|
||||||
cerr << "\nEnter " << number_count << " elements:" << endl;
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
|
||||||
cin >> in.numbers[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prompt) {
|
||||||
|
cerr << "Enter bin count: ";
|
||||||
|
}
|
||||||
|
in >> korz;
|
||||||
|
data.korz = korz;
|
||||||
|
|
||||||
cerr << "Enter the number of bins: ";
|
return data;
|
||||||
cin >> in.bin_count;
|
|
||||||
|
|
||||||
return in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int main(int argc, char* argv[]) {
|
||||||
find_minmax(const vector<double>& numbers, double& minl, double& maxl) {
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
minl = numbers[0];
|
|
||||||
maxl = numbers[0];
|
|
||||||
|
|
||||||
for (double x : numbers) {
|
if (argc > 1) {
|
||||||
if (x < minl) {
|
const char *url = argv[1];
|
||||||
minl = x;
|
|
||||||
} else {
|
CURL *curl = curl_easy_init();
|
||||||
if (x > maxl) {
|
if (curl) {
|
||||||
maxl = x;
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<size_t>
|
return 0;
|
||||||
make_histogram(const vector<double>& numbers, size_t& bin_count) {
|
|
||||||
double minn, maxn;
|
|
||||||
find_minmax(numbers, minn, maxn);
|
|
||||||
|
|
||||||
double bin_size = (maxn - minn) / bin_count;
|
|
||||||
|
|
||||||
vector<size_t> bins(bin_count, 0);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < numbers.size(); i++) {
|
|
||||||
bool found = false;
|
|
||||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
|
||||||
auto lo = minn + j * bin_size;
|
|
||||||
auto hi = minn + (j + 1) * bin_size;
|
|
||||||
if ((numbers[i] >= lo) && (numbers[i] <= hi)) {
|
|
||||||
bins[j]++;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
bins[bin_count - 1]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
show_histogram_text(const vector<size_t> bins, size_t bin_count) {
|
|
||||||
size_t max_count = bins[0];
|
|
||||||
for (size_t i = 1; i < bin_count; i++) {
|
|
||||||
if (bins[i] > max_count) {
|
|
||||||
max_count = bins[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t SCREEN_WIDTH = 80;
|
auto in_with_prompt = input_data(cin, true);
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
auto bins_with_prompt = make_histogram(in_with_prompt.korz, in_with_prompt.vec);
|
||||||
|
show_histogram_svg(bins_with_prompt);
|
||||||
|
|
||||||
short space_count;
|
|
||||||
|
|
||||||
cerr << "\nHistogram:" << endl;
|
|
||||||
|
|
||||||
if (max_count <= MAX_ASTERISK) {
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
if (bins[i] < 10) {
|
|
||||||
space_count = 2;
|
|
||||||
} else if (bins[i] >= 10 && bins[i] < 100) {
|
|
||||||
space_count = 1;
|
|
||||||
} else if (bins[i] >= 100 && bins[i] < 1000) {
|
|
||||||
space_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t k = 0; k < space_count; k++) {
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << bins[i];
|
|
||||||
|
|
||||||
cout << "|";
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t j = 0; j < bins[i]; j++) {
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
if (bins[i] < 10) {
|
|
||||||
space_count = 2;
|
|
||||||
} else if (bins[i] >= 10 && bins[i] < 100) {
|
|
||||||
space_count = 1;
|
|
||||||
} else if (bins[i] >= 100 && bins[i] < 1000) {
|
|
||||||
space_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (size_t k = 0; k < space_count; k++) {
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << bins[i];
|
|
||||||
|
|
||||||
cout << "|";
|
|
||||||
|
|
||||||
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count));
|
|
||||||
for (size_t j = 0; j < height; j++) {
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
auto in = input_data();
|
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
||||||
show_histogram_text(bins, in.bin_count);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
73
svg.cpp
Обычный файл
73
svg.cpp
Обычный файл
@@ -0,0 +1,73 @@
|
|||||||
|
#include "svg.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_begin(double width, double height)
|
||||||
|
{
|
||||||
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
|
cout << "<svg ";
|
||||||
|
cout << "width='" << width << "' ";
|
||||||
|
cout << "height='" << height << "' ";
|
||||||
|
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||||
|
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_end()
|
||||||
|
{
|
||||||
|
cout << "</svg>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_text(double left, double baseline, string text)
|
||||||
|
{
|
||||||
|
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
|
||||||
|
{
|
||||||
|
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_svg(const 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;
|
||||||
|
const auto GREEN = "green";
|
||||||
|
const auto RED = "red";
|
||||||
|
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
|
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||||
|
|
||||||
|
double top = 0;
|
||||||
|
double max_count = bins[0];
|
||||||
|
for (size_t i = 0; i < bins.size(); i++)
|
||||||
|
{
|
||||||
|
if (max_count < bins[i])
|
||||||
|
{
|
||||||
|
max_count = bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t bin : bins)
|
||||||
|
{
|
||||||
|
double bin_width = (MAX_WIDTH) * (bin/max_count);
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, GREEN, RED);
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg_end();
|
||||||
|
}
|
||||||
11
svg.h
Обычный файл
11
svg.h
Обычный файл
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef SVG_H_INCLUDED
|
||||||
|
#define SVG_H_INCLUDED
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
void show_histogram_svg(const vector<size_t>& bins);
|
||||||
|
|
||||||
|
#endif // SVG_H_INCLUDED
|
||||||
1
text.cpp
1
text.cpp
@@ -19,7 +19,6 @@ void show_histogram(std::vector<size_t> bins) {
|
|||||||
if (len > spaces) {
|
if (len > spaces) {
|
||||||
spaces = len;
|
spaces = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (spaces == 1) {
|
if (spaces == 1) {
|
||||||
for (size_t i = 0; i < bins.size(); i++) {
|
for (size_t i = 0; i < bins.size(); i++) {
|
||||||
|
|||||||
2
text.h
2
text.h
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
void show_histogram(std::vector<size_t> bins);
|
|
||||||
|
|
||||||
|
void show_histogram(std::vector<size_t> bins);
|
||||||
#endif // TEXT_H_INCLUDED
|
#endif // TEXT_H_INCLUDED
|
||||||
|
|||||||
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.cpp" />
|
||||||
|
<Unit filename="histogram_internal.h" />
|
||||||
|
<Unit filename="unittest.cpp" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
64
unittest.cpp
Обычный файл
64
unittest.cpp
Обычный файл
@@ -0,0 +1,64 @@
|
|||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
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;
|
||||||
|
vector<double> empty;
|
||||||
|
bool result = find_minmax(empty, min, max);
|
||||||
|
CHECK(!result);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of the same elements"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3,3,3}, min, max);
|
||||||
|
CHECK(min == 3);
|
||||||
|
CHECK(max == 3);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector of one elements"){
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({3}, min, max);
|
||||||
|
CHECK(min == max);
|
||||||
|
}
|
||||||
|
TEST_CASE("mixed positive and negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, 2, 0, -3, 5}, min, max);
|
||||||
|
CHECK(min == -3);
|
||||||
|
CHECK(max == 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with all negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-5, -10, -2}, min, max);
|
||||||
|
CHECK(min == -10);
|
||||||
|
CHECK(max == -2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with zero") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({0, -1, 1}, min, max);
|
||||||
|
CHECK(min == -1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
TEST_CASE("vector with procent"){
|
||||||
|
std::vector<size_t> vec {1,2,1};
|
||||||
|
auto res = make_percentages (vec);
|
||||||
|
CHECK(res[0] == 25);
|
||||||
|
|
||||||
|
}
|
||||||
68
unittest.depend
Обычный файл
68
unittest.depend
Обычный файл
@@ -0,0 +1,68 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1746444035 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
<cmath>
|
||||||
|
|
||||||
|
1746443248 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
1746447653 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
|
||||||
|
=======
|
||||||
|
1746274690 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
|
||||||
|
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1746271199 c:\users\professional\desktop\cs-lab34\lab1\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>
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
1746447694 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h
|
||||||
|
=======
|
||||||
|
1746444163 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h
|
||||||
|
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61
|
||||||
|
|
||||||
15
unittest.layout
Обычный файл
15
unittest.layout
Обычный файл
@@ -0,0 +1,15 @@
|
|||||||
|
<?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="1494" topLine="36" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="193" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
Двоичные данные
unittest.o
Обычный файл
Двоичные данные
unittest.o
Обычный файл
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user