пункт 6
Этот коммит содержится в:
15
LR3.cbp
15
LR3.cbp
@@ -32,7 +32,22 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="histogram_internal.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "histogram.h"
|
||||
#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];
|
||||
max = numbers[0];
|
||||
for (double x : numbers)
|
||||
{
|
||||
if (x < min)
|
||||
|
||||
3
main.cpp
3
main.cpp
@@ -2,6 +2,7 @@
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -32,6 +33,6 @@ int main()
|
||||
{
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_text(bins);
|
||||
show_histogram_svg(bins);
|
||||
return 0;
|
||||
}
|
||||
|
||||
9
svg.cpp
9
svg.cpp
@@ -31,6 +31,7 @@ void show_histogram_svg(const std::vector<double>& bins) {
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const std::size_t MAX_STAR = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
|
||||
svg_begin(400, 300);
|
||||
double top = 0;
|
||||
@@ -41,5 +42,13 @@ void show_histogram_svg(const std::vector<double>& bins) {
|
||||
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();
|
||||
}
|
||||
|
||||
22
unittest.cpp
22
unittest.cpp
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user