diff --git a/histogram.cpp b/histogram.cpp index cf4a912..ce7a325 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,6 +1,6 @@ #include "histogram.h" -void find_minmax(std::vector& vec, double& min, double& max) { +void find_minmax(std::vector vec, double& min, double& max) { min = vec[0]; @@ -11,8 +11,8 @@ void find_minmax(std::vector& vec, double& min, double& max) { } } -std::vector make_histogram(size_t number, std::vector& vec) { - std::vector bins(number); +vector make_histogram(size_t number, vector vec) { + vector bins(number); if (vec.empty()) return bins; double mn, mx; diff --git a/histogram.h b/histogram.h index 8d2cfd4..fc94053 100644 --- a/histogram.h +++ b/histogram.h @@ -4,6 +4,7 @@ #include #include -std::vector make_histogram(size_t number, std::vector& vec); +using namespace std; +vector make_histogram(size_t number, vector vec); #endif // HISTOGRAM_H_INCLUDED diff --git a/histogram_internal.h b/histogram_internal.h index 5bbe4ff..4567891 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,6 +1,6 @@ #ifndef HISTOGRAM_INTERNAL_H_INCLUDED #define HISTOGRAM_INTERNAL_H_INCLUDED -void find_minmax(std::vector& vec, double& min, double& max); +void find_minmax(std::vector vec, double& min, double& max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/text.cpp b/text.cpp index 3ca4555..add972a 100644 --- a/text.cpp +++ b/text.cpp @@ -1,7 +1,7 @@ #include "text.h" #include -void show_histogram(const std::vector& bins) { +void show_histogram(const vector& bins) { bool gigant = false; diff --git a/text.h b/text.h index f1c59f4..df05754 100644 --- a/text.h +++ b/text.h @@ -3,6 +3,6 @@ #include -void show_histogram(const std::vector& bins); +void show_histogram(const vector& bins); #endif // TEXT_H_INCLUDED diff --git a/unittest.cpp b/unittest.cpp index e69de29..37074ec 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,55 @@ +#define DOCTEST_CONFIG_NO_MULTITHREADING +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.h" +#include "histogram_internal.h" + +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("distinct negative numbers"){ + double min = 0; + double max = 0; + find_minmax({-1, -2}, min, max); + CHECK(min == -2); + CHECK(max == -1); +} +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); +} diff --git a/unittest/bin/Debug/unittest.exe b/unittest/bin/Debug/unittest.exe new file mode 100644 index 0000000..d854462 Binary files /dev/null and b/unittest/bin/Debug/unittest.exe differ diff --git a/unittest/obj/Debug/histogram.o b/unittest/obj/Debug/histogram.o index efab4b0..e1f6ebb 100644 Binary files a/unittest/obj/Debug/histogram.o and b/unittest/obj/Debug/histogram.o differ diff --git a/unittest/obj/Debug/unittest.o b/unittest/obj/Debug/unittest.o index d7e28df..51853c6 100644 Binary files a/unittest/obj/Debug/unittest.o and b/unittest/obj/Debug/unittest.o differ diff --git a/unittest/unittest.depend b/unittest/unittest.depend new file mode 100644 index 0000000..0627a11 --- /dev/null +++ b/unittest/unittest.depend @@ -0,0 +1,59 @@ +# depslib dependency file v1.0 +1748213255 source:c:\users\home\desktop\lab34\laba01\histogram.cpp + "histogram.h" + +1748213210 c:\users\home\desktop\lab34\laba01\histogram.h + + + +1748213127 source:c:\users\home\desktop\lab34\laba01\unittest.cpp + "doctest.h" + "histogram_internal.h" + +1748211324 c:\users\home\desktop\lab34\laba01\doctest.h + + + + + + + "doctest_fwd.h" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +1748213259 c:\users\home\desktop\lab34\laba01\histogram_internal.h +