laba34 (BuntovaMS) 2 недель назад
Родитель 71d0c43a9b
Сommit 3cf1ec4504

@ -1,14 +1,20 @@
#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) {
if (x < min) min = x;
if (x > max) max = x;
}
return true;
}
vector<size_t> make_histogram(size_t number, vector<double> vec) {

@ -1,6 +1,6 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
using namespace std;
void find_minmax(vector<double> vec, double& min, double& max);
bool find_minmax(vector<double> vec, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -8,28 +8,29 @@ struct Input {
size_t bin_count{};
};
Input input_data() {
Input in;
Input input_data(std::istream& in) {
Input data;
size_t number_count;
cerr << "Enter the number of elements: ";
cin >> number_count;
in >> number_count;
in.numbers.resize(number_count);
data.numbers.resize(number_count);
cerr << "\nEnter " << number_count << " elements:" << endl;
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
in >> data.numbers[i];
}
cerr << "Enter the number of bins: ";
cin >> in.bin_count;
in >> data.bin_count;
return in;
return data;
}
int main() {
auto in = input_data();
using namespace std;
auto in = input_data(cin);
auto bins = make_histogram(in.bin_count, in.numbers);
show_histogram_svg(bins);
return 0;

@ -30,12 +30,12 @@ TEST_CASE("vector of one elements"){
find_minmax({3}, min, max);
CHECK(min == max);
}
TEST_CASE("mixed positive and negative numbers") {
TEST_CASE("empty vector") {
double min = 0;
double max = 0;
find_minmax({-1, 2, 0, -3, 5}, min, max);
CHECK(min == -3);
CHECK(max == 5);
vector<double>empty;
bool result = find_minmax(empty, min, max);
CHECK(!result);
}
TEST_CASE("vector with all negative numbers") {

Двоичные данные
unittest/bin/Debug/unittest.exe

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/svg.o

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/unittest.o

Двоичный файл не отображается.

@ -35,10 +35,7 @@
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../histogram.cpp" />
<Unit filename="../histogram.h" />
<Unit filename="../marks.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../histogram_internal.h" />
<Unit filename="../svg.cpp" />
<Unit filename="../svg.h">
<Option target="&lt;{~None~}&gt;" />

@ -66,23 +66,23 @@
<string>
<math.h>
1748243704 source:c:\users\u111-15\desktop\lab34\laba01\histogram.cpp
1748439317 source:c:\users\u111-15\desktop\lab34\laba01\histogram.cpp
"histogram.h"
1748243654 c:\users\u111-15\desktop\lab34\laba01\histogram.h
<vector>
<iostream>
1748386434 source:c:\users\u111-15\desktop\lab34\laba01\svg.cpp
1748437296 source:c:\users\u111-15\desktop\lab34\laba01\svg.cpp
"svg.h"
1748242438 c:\users\u111-15\desktop\lab34\laba01\svg.h
1748436616 c:\users\u111-15\desktop\lab34\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
1748213520 source:c:\users\u111-15\desktop\lab34\laba01\unittest.cpp
1748439285 source:c:\users\u111-15\desktop\lab34\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
@ -131,5 +131,72 @@
<sys/time.h>
<unistd.h>
1748243718 c:\users\u111-15\desktop\lab34\laba01\histogram_internal.h
1748439317 c:\users\u111-15\desktop\lab34\laba01\histogram_internal.h
1748850515 source:c:\users\home\desktop\lab3444\laba01\histogram.cpp
"histogram.h"
1748850541 c:\users\home\desktop\lab3444\laba01\histogram.h
<vector>
<iostream>
1748439286 source:c:\users\home\desktop\lab3444\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1748430260 c:\users\home\desktop\lab3444\laba01\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>
1748439318 c:\users\home\desktop\lab3444\laba01\histogram_internal.h
1748850295 source:c:\users\home\desktop\lab3444\laba01\svg.cpp
"svg.h"
1748850424 c:\users\home\desktop\lab3444\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>

@ -2,14 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="..\histogram.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="..\svg.cpp" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="227" topLine="0" />
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="..\unittest.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="..\unittest.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1327" topLine="0" />
<Cursor1 position="858" topLine="10" />
</Cursor>
</File>
<File name="..\histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="208" topLine="0" />
</Cursor>
</File>
<File name="..\histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="216" topLine="0" />
</Cursor>
</File>
<File name="..\doctest.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="112412" topLine="2388" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Загрузка…
Отмена
Сохранить