final
Этот коммит содержится в:
10
.gitignore
поставляемый
Обычный файл
10
.gitignore
поставляемый
Обычный файл
@@ -0,0 +1,10 @@
|
|||||||
|
/bin
|
||||||
|
/obj
|
||||||
|
/lab01.depend
|
||||||
|
/lab01.layout
|
||||||
|
/main.exe
|
||||||
|
/main.o
|
||||||
|
/unittest.depend
|
||||||
|
/unittest.layout
|
||||||
|
/unittest1.depend
|
||||||
|
|
||||||
@@ -5,24 +5,30 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
bool
|
||||||
find_minmax(const vector<double>& numbers, double& min1, double& max1)
|
find_minmax(const vector<double>& numbers, double& min1, double& max1)
|
||||||
{
|
{
|
||||||
|
if (numbers.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
max1 = numbers[0];
|
max1 = numbers[0];
|
||||||
min1 = numbers[0];
|
min1 = numbers[0];
|
||||||
|
}
|
||||||
for(size_t i = 0; i < numbers.size(); i++)
|
for(size_t i = 0; i < numbers.size(); i++)
|
||||||
{
|
{
|
||||||
if (numbers[i] > max1) max1 = numbers[i];
|
if (numbers[i] > max1) max1 = numbers[i];
|
||||||
if (numbers[i] < min1) min1 = numbers[i];
|
if (numbers[i] < min1) min1 = numbers[i];
|
||||||
}
|
}
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<double>
|
vector<double>
|
||||||
make_histogram(const vector<double>& numbers, size_t bin_count)
|
make_histogram(const vector<double>& numbers, size_t bin_count)
|
||||||
{
|
{
|
||||||
double min1, max1;
|
double min1, max1;
|
||||||
find_minmax(numbers, min1, max1);
|
if (!find_minmax(numbers, min1, max1))
|
||||||
|
cout << "error in find_minmax: empty vector";
|
||||||
|
|
||||||
vector<double> bins;
|
vector<double> bins;
|
||||||
bins.resize(bin_count);
|
bins.resize(bin_count);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void
|
bool
|
||||||
find_minmax(const std::vector<double>& numbers, double& min1, double& max1);
|
find_minmax(const std::vector<double>& numbers, double& min1, double& max1);
|
||||||
|
|||||||
15
svg.cpp
15
svg.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -28,6 +29,13 @@ void svg_rect(double x, double y, double width, double height, string stroke = "
|
|||||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='#" << fill << fill << fill << "' />";
|
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='#" << fill << fill << fill << "' />";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void color_find(double bin, int maxb, int& color){
|
||||||
|
color = (10 - (bin * 9) / maxb);
|
||||||
|
if (color < 0) { cout << "cant take color";
|
||||||
|
color = 9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(const vector<double>& bins) {
|
show_histogram_svg(const vector<double>& bins) {
|
||||||
|
|
||||||
@@ -43,20 +51,21 @@ show_histogram_svg(const vector<double>& bins) {
|
|||||||
|
|
||||||
double top = 0;
|
double top = 0;
|
||||||
const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
|
const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
|
||||||
double maxb = bins[0];
|
int maxb = bins[0];
|
||||||
|
int color;
|
||||||
|
|
||||||
for (size_t j = 1; j < bins.size(); j++)
|
for (size_t j = 1; j < bins.size(); j++)
|
||||||
{
|
{
|
||||||
if (bins[j] > maxb) maxb = bins[j];
|
if (bins[j] > maxb) maxb = bins[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
double maxb1 = maxb * BLOCK_WIDTH;
|
int maxb1 = maxb * BLOCK_WIDTH;
|
||||||
|
|
||||||
for (size_t bin : bins) {
|
for (size_t bin : bins) {
|
||||||
|
|
||||||
double bin_width;
|
double bin_width;
|
||||||
|
|
||||||
int color = (10 - (bin * 9) / maxb);
|
color_find(bin, maxb, color);
|
||||||
|
|
||||||
if (maxb1 > MAX_ASTERISK)
|
if (maxb1 > MAX_ASTERISK)
|
||||||
{
|
{
|
||||||
|
|||||||
4
svg_internal.h
Обычный файл
4
svg_internal.h
Обычный файл
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
void
|
||||||
|
color_find(double bin, int maxb, int& color);
|
||||||
@@ -6,9 +6,7 @@
|
|||||||
TEST_CASE("distinct positive numbers") {
|
TEST_CASE("distinct positive numbers") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
find_minmax({1, 2}, min, max);
|
CHECK(find_minmax({}, min, max) == false);
|
||||||
CHECK(min == 1);
|
|
||||||
CHECK(max == 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("distinct identical numbers") {
|
TEST_CASE("distinct identical numbers") {
|
||||||
|
|||||||
38
unittest1.cbp
Обычный файл
38
unittest1.cbp
Обычный файл
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="unittest1" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gfortran" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/unittest1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gfortran" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/unittest1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gfortran" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
</Compiler>
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
28
unittest1.cpp
Обычный файл
28
unittest1.cpp
Обычный файл
@@ -0,0 +1,28 @@
|
|||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "svg_internal.h"
|
||||||
|
|
||||||
|
TEST_CASE("color standart") {
|
||||||
|
int color = 0;
|
||||||
|
color_find(1, 5, color);
|
||||||
|
CHECK(color == 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("color equal") {
|
||||||
|
int color = 0;
|
||||||
|
color_find(5, 5, color);
|
||||||
|
CHECK(color == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("color sr") {
|
||||||
|
int color = 0;
|
||||||
|
color_find(3, 5, color);
|
||||||
|
CHECK(color == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("color nonsr") {
|
||||||
|
int color = 0;
|
||||||
|
color_find(7, 5, color);
|
||||||
|
CHECK(color == 9);
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user