master
Varvara (ZeninaVA) 1 месяц назад
Родитель 9333e93a79
Сommit 7892d51950

@ -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

@ -32,7 +32,22 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -0,0 +1,33 @@
# depslib dependency file v1.0
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
"histogram.h"
1747403061 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
<vector>
<iostream>
1746444035 source:c:\users\professional\desktop\cs-lab34\lab1\text.cpp
"text.h"
"histogram.h"
<iostream>
<vector>
<string>
1747403061 c:\users\professional\desktop\cs-lab34\lab1\text.h
<iostream>
<vector>
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\main.cpp
"histogram.h"
"text.h"
"svg.h"
1747403061 c:\users\professional\desktop\cs-lab34\lab1\svg.h
<iostream>
<vector>
<string>
<math.h>
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\svg.cpp
"svg.h"

@ -1,6 +1,7 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
struct Input { struct Input {
vector<double> vec; vector<double> vec;
size_t korz{}; size_t korz{};
@ -19,6 +20,7 @@ Input input_data() {
cin >> in.korz; cin >> in.korz;
return in; return in;
} }
int main() { int main() {
auto in = input_data(); auto in = input_data();
auto bins = make_histogram(in.korz, in.vec); auto bins = make_histogram(in.korz, in.vec);

@ -44,7 +44,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 GREEN = "green" const auto GREEN = "green";
const auto RED = "red"; const auto RED = "red";
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH; const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;

@ -1,6 +1,5 @@
#ifndef SVG_H_INCLUDED #ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED #define SVG_H_INCLUDED
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <string> #include <string>

@ -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++) {
@ -80,4 +79,5 @@ void show_histogram(std::vector<size_t> bins) {
std::cout << std::endl; std::cout << std::endl;
} }
} }
}
}

@ -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

@ -31,6 +31,9 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -3,6 +3,8 @@
#include "doctest.h" #include "doctest.h"
#include "histogram_internal.h" #include "histogram_internal.h"
using namespace std;
TEST_CASE("distinct positive numbers") { TEST_CASE("distinct positive numbers") {
double min = 0; double min = 0;
double max = 0; double max = 0;
@ -10,12 +12,13 @@ TEST_CASE("distinct positive numbers") {
CHECK(min == 1); CHECK(min == 1);
CHECK(max == 2); CHECK(max == 2);
} }
TEST_CASE("distinct negative numbers"){
TEST_CASE("empty vector"){
double min = 0; double min = 0;
double max = 0; double max = 0;
find_minmax({-1, -2}, min, max); vector<double> empty;
CHECK(min == -2); bool result = find_minmax(empty, min, max);
CHECK(max == -1); CHECK(!result);
} }
TEST_CASE("vector of the same elements"){ TEST_CASE("vector of the same elements"){
double min = 0; double min = 0;
@ -53,3 +56,9 @@ TEST_CASE("vector with zero") {
CHECK(min == -1); CHECK(min == -1);
CHECK(max == 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);
}

@ -1,8 +1,60 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
1746270053 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp 1746444035 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
"histogram.h" "histogram.h"
<cmath>
1746269334 c:\users\professional\desktop\cs-lab34\lab1\histogram.h 1746443248 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
<vector> <vector>
<iostream> <iostream>
1746447653 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
"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>
1746447694 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h

@ -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

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить