code; исходный код 3
Этот коммит содержится в:
@@ -1,6 +1,10 @@
|
||||
#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];
|
||||
max = vec[0];
|
||||
for (double x : vec) {
|
||||
@@ -12,8 +16,8 @@ void find_minmax(vector<double> vec, double& min, double& max) {
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<size_t> make_histogram(size_t number, vector<double> vec) {
|
||||
vector<size_t> bins(number);
|
||||
double mn, mx;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define HISTOGRAM_H_INCLUDED
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
vector<size_t> make_histogram(size_t number, vector<double> vec);
|
||||
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#ifndef 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
|
||||
|
||||
15
lab1.cbp
15
lab1.cbp
@@ -32,7 +32,22 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<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="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
33
lab1.depend
Обычный файл
33
lab1.depend
Обычный файл
@@ -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"
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
|
||||
struct Input {
|
||||
vector<double> vec;
|
||||
size_t korz{};
|
||||
@@ -19,6 +20,7 @@ Input input_data() {
|
||||
cin >> in.korz;
|
||||
return in;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.korz, in.vec);
|
||||
|
||||
2
svg.cpp
2
svg.cpp
@@ -44,7 +44,7 @@ show_histogram_svg(const vector<size_t>& bins)
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto GREEN = "green"
|
||||
const auto GREEN = "green";
|
||||
const auto RED = "red";
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
|
||||
|
||||
1
svg.h
1
svg.h
@@ -1,6 +1,5 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
4
text.cpp
4
text.cpp
@@ -19,7 +19,6 @@ void show_histogram(std::vector<size_t> bins) {
|
||||
if (len > spaces) {
|
||||
spaces = len;
|
||||
}
|
||||
|
||||
}
|
||||
if (spaces == 1) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
2
text.h
2
text.h
@@ -3,6 +3,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
void show_histogram(std::vector<size_t> bins);
|
||||
|
||||
void show_histogram(std::vector<size_t> bins);
|
||||
#endif // TEXT_H_INCLUDED
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
<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>
|
||||
|
||||
17
unittest.cpp
17
unittest.cpp
@@ -3,6 +3,8 @@
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
@@ -10,12 +12,13 @@ TEST_CASE("distinct positive numbers") {
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
TEST_CASE("distinct negative numbers"){
|
||||
|
||||
TEST_CASE("empty vector"){
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-1, -2}, min, max);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
vector<double> empty;
|
||||
bool result = find_minmax(empty, min, max);
|
||||
CHECK(!result);
|
||||
}
|
||||
TEST_CASE("vector of the same elements"){
|
||||
double min = 0;
|
||||
@@ -53,3 +56,9 @@ TEST_CASE("vector with zero") {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,60 @@
|
||||
# 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"
|
||||
<cmath>
|
||||
|
||||
1746269334 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
|
||||
1746443248 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
|
||||
<vector>
|
||||
<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
|
||||
|
||||
|
||||
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