diff --git a/LABA1.cpp b/LABA1.cpp index 76a75a1..06dc84c 100644 --- a/LABA1.cpp +++ b/LABA1.cpp @@ -3,6 +3,7 @@ #include #include "histogram.h" #include "text.h" + using namespace std; @@ -67,6 +68,7 @@ struct Input { Input input_data() { Input in; + Input in2; int VecSize = 0; cin >> VecSize; in.marks.resize(VecSize); diff --git a/LABA1.sln b/LABA1.sln index c0717d7..ead127d 100644 --- a/LABA1.sln +++ b/LABA1.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LABA1", "LABA1.vcxproj", "{D164F324-4243-431D-90CA-53E6B0D0180A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unittest", "unittest.vcxproj", "{A913469C-7807-4128-B5B5-C49C6B34CDE3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -21,6 +23,14 @@ Global {D164F324-4243-431D-90CA-53E6B0D0180A}.Release|x64.Build.0 = Release|x64 {D164F324-4243-431D-90CA-53E6B0D0180A}.Release|x86.ActiveCfg = Release|Win32 {D164F324-4243-431D-90CA-53E6B0D0180A}.Release|x86.Build.0 = Release|Win32 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Debug|x64.ActiveCfg = Debug|x64 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Debug|x64.Build.0 = Debug|x64 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Debug|x86.ActiveCfg = Debug|Win32 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Debug|x86.Build.0 = Debug|Win32 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Release|x64.ActiveCfg = Release|x64 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Release|x64.Build.0 = Release|x64 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Release|x86.ActiveCfg = Release|Win32 + {A913469C-7807-4128-B5B5-C49C6B34CDE3}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LABA1.vcxproj b/LABA1.vcxproj index 930fdc7..7caaa2e 100644 --- a/LABA1.vcxproj +++ b/LABA1.vcxproj @@ -127,7 +127,9 @@ + + diff --git a/LABA1.vcxproj.filters b/LABA1.vcxproj.filters index daf0a2f..4390fef 100644 --- a/LABA1.vcxproj.filters +++ b/LABA1.vcxproj.filters @@ -18,5 +18,11 @@ Исходные файлы + + Исходные файлы + + + Исходные файлы + \ No newline at end of file diff --git a/histogram.cpp b/histogram.cpp index 38ded28..a4c686b 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -3,18 +3,21 @@ using namespace std; void FindMinMax(const vector& marks, double& min, double& max) { max = 0; - min = marks[0]; - for (double x : marks) { - if (x > max) { - max = x; - } - if (x < min) { - min = x; + min = 0; + if (marks.size() = 0) { + min = marks[0]; + for (double x : marks) { + if (x > max) { + max = x; + } + if (x < min) { + min = x; + } } } -}; +} -static vector MakeHistogram(const vector& marks, int NCharts) { +vector MakeHistogram(const vector& marks, int NCharts) { double interval = 0, i = 0, min = 0, max = 0; vector chart(NCharts); FindMinMax(marks, min, max); @@ -27,4 +30,4 @@ static vector MakeHistogram(const vector& marks, int NCharts) { chart[i] += 1; } return chart; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/histogram.h b/histogram.h index 1199262..8d36e6e 100644 --- a/histogram.h +++ b/histogram.h @@ -1,8 +1,9 @@ #ifndef HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED -#include "histogram.cpp" //, . ! + #include +void FindMinMax(const std::vector& marks, double& min, double& max); std::vector MakeHistogram(const std::vector& marks, int NCharts); #endif // HISTOGRAM_H_INCLUDED \ No newline at end of file diff --git a/histogram_internal.h b/histogram_internal.h index 312b93b..4a2e17e 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -1,6 +1,5 @@ #ifndef HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED -#include "histogram.cpp" #include void FindMinMax(const std::vector& marks, double& min, double& max); diff --git a/text.cpp b/text.cpp index 8e7e29c..08012f0 100644 --- a/text.cpp +++ b/text.cpp @@ -1,3 +1,4 @@ +#include #include "histogram.h" using namespace std; diff --git a/text.h b/text.h index 77324a7..7ce729d 100644 --- a/text.h +++ b/text.h @@ -1,8 +1,8 @@ #ifndef TEXT_H_INCLUDED #define TEXT_H_INCLUDED -#include "text.cpp" //, . ! + #include -void show_histogram_text(const vector& marks, const vector& chart); +void show_histogram_text(const std::vector& marks, const std::vector& chart); #endif // TEXT_H_INCLUDED \ No newline at end of file diff --git a/unittest.cpp b/unittest.cpp index 13ed78d..03054ec 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -13,21 +13,13 @@ TEST_CASE("distinct positive numbers") { CHECK(max == 2); } -/* -Если вектор пуст, искусственно добавляем в него значения -Проверяем, равны ли min и max этим искусственным значениям -*/ + TEST_CASE("empty vector") { double min = 0; double max = 0; - vector fortest; - if (fortest.size() == 0) { - fortest.push_back(90); - fortest.push_back(100); - } - FindMinMax(fortest, min, max); - CHECK(min != 90); - CHECK(max != 100); + FindMinMax({ }, min, max); + CHECK(min != 0); + CHECK(max != 0); } TEST_CASE("one element") { diff --git a/unittest.vcxproj b/unittest.vcxproj index 36c44ba..6245a90 100644 --- a/unittest.vcxproj +++ b/unittest.vcxproj @@ -127,6 +127,7 @@ + diff --git a/unittest.vcxproj.filters b/unittest.vcxproj.filters index 31017b9..95e7855 100644 --- a/unittest.vcxproj.filters +++ b/unittest.vcxproj.filters @@ -18,5 +18,8 @@ Исходные файлы + + Исходные файлы + \ No newline at end of file