code: откат к начальному коду
Этот коммит содержится в:
@@ -4,8 +4,15 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
void find_minmax(const vector<double> numbers, double& min, double& max) {
|
bool find_minmax(vector<double> numbers, double& min, double& max) {
|
||||||
|
if (numbers.empty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
for (auto i = 0; i < numbers.size(); i++) {
|
for (auto i = 0; i < numbers.size(); i++) {
|
||||||
if (numbers[i] < min) {
|
if (numbers[i] < min) {
|
||||||
@@ -19,9 +26,9 @@ void find_minmax(const vector<double> numbers, double& min, double& max) {
|
|||||||
max = numbers[i];
|
max = numbers[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
||||||
|
|
||||||
vector<size_t> bins(bin_count);
|
vector<size_t> bins(bin_count);
|
||||||
@@ -63,3 +70,4 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|||||||
}
|
}
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#include <vector>
|
#include <vector>
|
||||||
void find_minmax(std::vector<double> numbers, double& min, double& max);
|
bool find_minmax(std::vector<double> numbers, double& min, double& max);
|
||||||
|
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -42,3 +42,4 @@ int main()
|
|||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\main.cpp
|
1685964158 source:c:\users\hp\desktop\lab-03\project3\main.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
<vector>
|
<vector>
|
||||||
<cmath>
|
<cmath>
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
<string>
|
<string>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
|
|
||||||
1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h
|
1685965388 c:\users\hp\desktop\lab-03\project3\histogram.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
1685969843 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
<vector>
|
<vector>
|
||||||
<cmath>
|
<cmath>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
<conio.h>
|
<conio.h>
|
||||||
|
|
||||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\text.cpp
|
1685964158 source:c:\users\hp\desktop\lab-03\project3\text.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
<vector>
|
<vector>
|
||||||
<cmath>
|
<cmath>
|
||||||
@@ -30,15 +30,17 @@
|
|||||||
1682273446 c:\users\hp\desktop\lab-03\project3\text.h
|
1682273446 c:\users\hp\desktop\lab-03\project3\text.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
1685969642 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1685883368 source:c:\users\hp\desktop\lab-03\project3\svg.cpp
|
1685943355 source:c:\users\hp\desktop\lab-03\project3\svg.cpp
|
||||||
<iostream>
|
|
||||||
"svg.h"
|
|
||||||
<math.h>
|
<math.h>
|
||||||
|
<iostream>
|
||||||
|
<conio.h>
|
||||||
|
<vector>
|
||||||
<string>
|
<string>
|
||||||
|
"svg.h"
|
||||||
|
|
||||||
1685882979 c:\users\hp\desktop\lab-03\project3\svg.h
|
1685964255 c:\users\hp\desktop\lab-03\project3\svg.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
|
|||||||
@@ -2,34 +2,39 @@
|
|||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="175" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1322" topLine="27" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="171" topLine="0" />
|
<Cursor1 position="171" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
|
<File name="histogram.cpp" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1715" topLine="45" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="svg.cpp" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="0" topLine="24" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="text.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1534" topLine="17" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="171" topLine="0" />
|
<Cursor1 position="171" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="text.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="95" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="127" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="histogram.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="367" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="175" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
83
svg.cpp
83
svg.cpp
@@ -1,7 +1,9 @@
|
|||||||
|
/*#include <math.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "svg.h"
|
#include <conio.h>
|
||||||
#include <math.h>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "svg.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -61,3 +63,80 @@ void show_histogram_svg(const vector<size_t>& bins) {
|
|||||||
}
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "svg.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_begin(double width, double height)
|
||||||
|
{
|
||||||
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
|
cout << "<svg ";
|
||||||
|
cout << "width='" << width << "' ";
|
||||||
|
cout << "height='" << height << "' ";
|
||||||
|
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||||
|
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_end()
|
||||||
|
{
|
||||||
|
cout << "</svg>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_text(double left, double baseline, string text)
|
||||||
|
{
|
||||||
|
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
|
||||||
|
{
|
||||||
|
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fill<<"' />";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_svg(const vector<size_t>& bins)
|
||||||
|
{
|
||||||
|
const auto IMAGE_WIDTH = 400;
|
||||||
|
const auto IMAGE_HEIGHT = 300;
|
||||||
|
const auto TEXT_LEFT = 20;
|
||||||
|
const auto TEXT_BASELINE = 20;
|
||||||
|
const auto TEXT_WIDTH = 50;
|
||||||
|
const auto BIN_HEIGHT = 30;
|
||||||
|
const auto BLOCK_WIDTH = 10;
|
||||||
|
const auto BLACK = "black";
|
||||||
|
const auto RED = "red";
|
||||||
|
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
||||||
|
|
||||||
|
|
||||||
|
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||||
|
|
||||||
|
double top = 0;
|
||||||
|
double max_count = bins[0];
|
||||||
|
for (size_t i = 0; i < bins.size(); i++)
|
||||||
|
{
|
||||||
|
if (max_count<bins[i])
|
||||||
|
{
|
||||||
|
max_count=bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t bin : bins)
|
||||||
|
{
|
||||||
|
double bin_width = (MAX_WIDTH)*(bin/max_count);
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BLACK, RED);
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg_end();
|
||||||
|
}
|
||||||
|
|||||||
1
text.cpp
1
text.cpp
@@ -20,4 +20,3 @@ void show_histogram_text(vector <size_t> bins, size_t bin_count ) {
|
|||||||
cout << "\n";
|
cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
49
unitest.cpp
49
unitest.cpp
@@ -3,14 +3,51 @@
|
|||||||
#include "doctest.h"
|
#include "doctest.h"
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
TEST_CASE("distinct positive numbers") {
|
#include <iostream>
|
||||||
|
#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 min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
std::vector<double>mas{1,2};
|
find_minmax({1, 2}, min, max);
|
||||||
CHECK(mas.size() != 0);
|
|
||||||
CHECK(mas.size() != 1);
|
|
||||||
find_minmax(mas, min, max);
|
|
||||||
CHECK(min == 1);
|
CHECK(min == 1);
|
||||||
CHECK(max == 2);
|
CHECK(max == 2);
|
||||||
CHECK(min != max);
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with one element")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({1}, min, max);
|
||||||
|
CHECK(min == 1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("vector with same elements")
|
||||||
|
{
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({2,2,2}, min, max);
|
||||||
|
CHECK(min == 2);
|
||||||
|
CHECK(max == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("void vector")
|
||||||
|
{
|
||||||
|
double min = 3;
|
||||||
|
double max = 2;
|
||||||
|
std::vector<double> numbers {};
|
||||||
|
bool check = find_minmax(numbers, min, max);
|
||||||
|
CHECK(check == true);
|
||||||
|
}
|
||||||
|
TEST_CASE("distinct negative numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, -2}, min, max);
|
||||||
|
CHECK(min == -2);
|
||||||
|
CHECK(max == -1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1682275493 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
1685969843 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||||
<iostream>
|
<iostream>
|
||||||
<vector>
|
<vector>
|
||||||
<cmath>
|
<cmath>
|
||||||
"histogram.h"
|
"histogram.h"
|
||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
|
<conio.h>
|
||||||
|
|
||||||
1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h
|
1685965388 c:\users\hp\desktop\lab-03\project3\histogram.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
1685969642 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682275379 source:c:\users\hp\desktop\lab-03\project3\unitest.cpp
|
1685970405 source:c:\users\hp\desktop\lab-03\project3\unitest.cpp
|
||||||
"doctest.h"
|
"doctest.h"
|
||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
<vector>
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
1682274805 c:\users\hp\desktop\lab-03\project3\doctest.h
|
1682274805 c:\users\hp\desktop\lab-03\project3\doctest.h
|
||||||
<signal.h>
|
<signal.h>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user