NemykinNO 2 лет назад
Родитель 0a7ae92249
Сommit 34d9e3f393

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -0,0 +1,33 @@
# depslib dependency file v1.0
1685858392 source:c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\histogram.cpp
<math.h>
<iostream>
<conio.h>
<vector>
"histogram.h"
1685858387 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\histogram.h
<vector>
1685861365 source:c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\main.cpp
<vector>
<math.h>
<iostream>
<conio.h>
<fstream>
"histogram.h"
"text.h"
"svg.h"
1685858389 source:c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\text.cpp
<math.h>
<iostream>
<conio.h>
<vector>
"text.h"
1685858378 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\text.h
<vector>
1685862500 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\svg.h

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="167" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="137" topLine="0" />
</Cursor>
</File>
<File name="ddd.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1587" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="1" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1589" topLine="2" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="216" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="148" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="377" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="327" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -0,0 +1,63 @@
#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 colour = "black", string fill = "black")
{
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke = '"<<colour <<"' 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 MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
double top = 0;
double max_count = bins[0];
for (size_t i = 0; i < bins.size(); i++)
{
if (bins[i] > max_count)
max_count = bins[i];
}
svg_begin(400, 300);
for (size_t bin : bins)
{
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "#DAF7A6", "#33DDFF");
top += BIN_HEIGHT;
}

@ -0,0 +1,7 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
void
show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H_INCLUDED

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="unitest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/unitest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/unitest" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unitest.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,53 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
#include <vector>
#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 max = 0;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}
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);
}

@ -0,0 +1,68 @@
# depslib dependency file v1.0
1686063069 source:c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\histogram.cpp
<math.h>
<iostream>
<conio.h>
<vector>
"histogram.h"
"histogram_internal.h"
1685970924 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\histogram.h
<vector>
1685970476 source:c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\unitest.cpp
"doctest.h"
"histogram_internal.h"
<vector>
<iostream>
"doctest.h"
"histogram_internal.h"
1685861557 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1685970915 c:\users\nn110\onedrive\Ðàáî÷èé ñòîë\lab3\histogram_internal.h
<vector>
Загрузка…
Отмена
Сохранить