StepanishchevVR 12 месяцев назад
Родитель 1e096e7bdc
Сommit 6b0a51458b

@ -32,7 +32,22 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Extensions /> <Extensions />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

@ -1,9 +1,10 @@
#include "histogram.h" #include "histogram.h"
#include <vector> #include <vector>
static void find_minmax(const std::vector<double>& numbers, double& min, double& max) void find_minmax(const std::vector<double>& numbers, double& min, double& max)
{ {
min = numbers[0]; min = numbers[0];
max = numbers[0];
for (double x : numbers) for (double x : numbers)
{ {
if (x < min) if (x < min)

@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h"
using namespace std; using namespace std;
@ -32,6 +33,6 @@ int main()
{ {
auto in = input_data(); auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins); show_histogram_svg(bins);
return 0; return 0;
} }

@ -31,6 +31,7 @@ void show_histogram_svg(const std::vector<double>& bins) {
const auto TEXT_WIDTH = 50; const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10; const auto BLOCK_WIDTH = 10;
const std::size_t MAX_STAR = IMAGE_WIDTH - TEXT_WIDTH;
svg_begin(400, 300); svg_begin(400, 300);
double top = 0; double top = 0;
@ -41,5 +42,13 @@ void show_histogram_svg(const std::vector<double>& bins) {
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
std::size_t max_star_search=bins[0];
for (std::size_t i=0; i < bins.size(); i++){
if (max_star_search < bins[i]){
max_star_search=bins[i];
}
}
svg_end(); svg_end();
} }

@ -0,0 +1,22 @@
#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);
}
Загрузка…
Отмена
Сохранить