diff --git a/histogram.cpp b/histogram.cpp index 78f4edf..ea77ff7 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -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) { diff --git a/histogram_internal.h b/histogram_internal.h index 3b50f2f..8f08842 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -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 diff --git a/main.cpp b/main.cpp index 3980e6b..c6d45a3 100644 --- a/main.cpp +++ b/main.cpp @@ -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; diff --git a/unittest.cpp b/unittest.cpp index 37074ec..8fb0b85 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -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") { diff --git a/unittest/bin/Debug/unittest.exe b/unittest/bin/Debug/unittest.exe index f8ce217..b86656d 100644 Binary files a/unittest/bin/Debug/unittest.exe and b/unittest/bin/Debug/unittest.exe differ diff --git a/unittest/obj/Debug/histogram.o b/unittest/obj/Debug/histogram.o index 0f902e2..7f8800f 100644 Binary files a/unittest/obj/Debug/histogram.o and b/unittest/obj/Debug/histogram.o differ diff --git a/unittest/obj/Debug/svg.o b/unittest/obj/Debug/svg.o index f0ed65d..106faa8 100644 Binary files a/unittest/obj/Debug/svg.o and b/unittest/obj/Debug/svg.o differ diff --git a/unittest/obj/Debug/unittest.o b/unittest/obj/Debug/unittest.o index 2a29363..ba28a1c 100644 Binary files a/unittest/obj/Debug/unittest.o and b/unittest/obj/Debug/unittest.o differ diff --git a/unittest/unittest.cbp b/unittest/unittest.cbp index 0154cc0..d8e24c4 100644 --- a/unittest/unittest.cbp +++ b/unittest/unittest.cbp @@ -35,10 +35,7 @@ <Option target="<{~None~}>" /> </Unit> <Unit filename="../histogram.cpp" /> - <Unit filename="../histogram.h" /> - <Unit filename="../marks.h"> - <Option target="<{~None~}>" /> - </Unit> + <Unit filename="../histogram_internal.h" /> <Unit filename="../svg.cpp" /> <Unit filename="../svg.h"> <Option target="<{~None~}>" /> diff --git a/unittest/unittest.depend b/unittest/unittest.depend index e19dca0..2c86ee1 100644 --- a/unittest/unittest.depend +++ b/unittest/unittest.depend @@ -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> diff --git a/unittest/unittest.layout b/unittest/unittest.layout index acc1997..9ca38f6 100644 --- a/unittest/unittest.layout +++ b/unittest/unittest.layout @@ -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>