code: корректировка
Этот коммит содержится в:
@@ -39,6 +39,7 @@
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Unit filename="unittest.cbp" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
||||
@@ -7104,4 +7104,3 @@ DOCTEST_SUPPRESS_COMMON_WARNINGS_POP
|
||||
#undef NOMINMAX
|
||||
#undef DOCTEST_UNDEF_NOMINMAX
|
||||
#endif // DOCTEST_UNDEF_NOMINMAX
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#include "histogram.h"
|
||||
#include <vector>
|
||||
void find_minmax(const std::vector <double> &numbers, double &min, double &max)
|
||||
void find_minmax(const std::vector <double> &numbers, double &min, double &max, bool &res)
|
||||
{
|
||||
if (numbers.size()==0)
|
||||
{
|
||||
res = true;
|
||||
return;
|
||||
}
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers)
|
||||
@@ -19,7 +24,8 @@ void find_minmax(const std::vector <double> &numbers, double &min, double &max)
|
||||
std::vector<std::size_t> make_histogram(const std::vector<double> &numbers, std::size_t bin_count)
|
||||
{
|
||||
double min, max;
|
||||
find_minmax(numbers, min, max);
|
||||
bool res = false;
|
||||
find_minmax(numbers, min, max, res);
|
||||
double bin_size = (max - min) / bin_count;
|
||||
std::vector <std::size_t> bins (bin_count);
|
||||
|
||||
|
||||
1
main.cpp
1
main.cpp
@@ -29,6 +29,7 @@ input_data()
|
||||
int
|
||||
main()
|
||||
{
|
||||
bool res = false;
|
||||
Input in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_text(bins);
|
||||
|
||||
1
text.cpp
1
text.cpp
@@ -8,6 +8,7 @@ const std::size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
void
|
||||
show_histogram_text(const std::vector <std::size_t> &bins)
|
||||
{
|
||||
std::cout<<std::endl;
|
||||
std::size_t max_count = bins[0];
|
||||
for (std::size_t i = 0; i < bins.size(); i++)
|
||||
{
|
||||
|
||||
57
unittest.cpp
57
unittest.cpp
@@ -3,10 +3,65 @@
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
find_minmax({1, 2}, min, max, res);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(res==0);
|
||||
}
|
||||
|
||||
TEST_CASE("negative numbers") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-1, -2}, min, max, res);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
CHECK(res==0);
|
||||
}
|
||||
|
||||
TEST_CASE("empty array") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
std::vector<double> numbers;
|
||||
find_minmax(numbers, min, max, res);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
CHECK(res==1);
|
||||
}
|
||||
|
||||
TEST_CASE("1 number") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-1}, min, max, res);
|
||||
CHECK(min == -1);
|
||||
CHECK(max == -1);
|
||||
CHECK(res==0);
|
||||
}
|
||||
|
||||
TEST_CASE("same number") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1,1,1,1}, min, max, res);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 1);
|
||||
CHECK(res==0);
|
||||
}
|
||||
|
||||
TEST_CASE("same number but zero") {
|
||||
bool res = false;
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({0,0,0,0}, min, max, res);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
CHECK(res==0);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user