diff --git a/histogram.cpp b/histogram.cpp index 9deefeb..0b5f9d1 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -3,7 +3,7 @@ #include using namespace std; -static void find_minmax(const vector& numbers, double& minN, double& maxN) +void find_minmax(const vector& numbers, double& minN, double& maxN) { minN = numbers[0]; maxN = numbers[0]; diff --git a/histogram_internal.h b/histogram_internal.h index e69de29..54abeff 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -0,0 +1,9 @@ +#ifndef HISTOGRAM_INTERNAL_H_INCLUDED +#define HISTOGRAM_INTERNAL_H_INCLUDED + +#include + +std::vector +find_minmax( const std::vector& numbers, double& minN, double& maxN); + +#endif // HISTOGRAM_INTERNAL_H_INCLUDED diff --git a/unittest.cpp b/unittest.cpp index e69de29..f0883f5 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -0,0 +1,29 @@ +#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 1 element") +{ + double min = 0; + double max = 0; + find_minmax({1}, min, max); + CHECK(min == 1); + CHECK(max == 1); +}