Сравнить коммиты
Ничего общего в коммитах. '49f0b786f8fc29f1a4804e1efa918e2024a60da5' и 'ded2a208f078793eaa1996a28fce68cdca90d88a' имеют совершенно разные истории.
49f0b786f8
...
ded2a208f0
@ -1,6 +0,0 @@
|
||||
/bin
|
||||
/obj
|
||||
lab03.depend
|
||||
unittest.depend
|
||||
unittest.layout
|
||||
unittest.o
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,7 +0,0 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#include <vector>
|
||||
|
||||
void find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
@ -1,76 +0,0 @@
|
||||
#include "svg.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void
|
||||
svg_begin(double width, double height) {
|
||||
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
std::cout << "<svg ";
|
||||
std::cout << "width='" << width << "' ";
|
||||
std::cout << "height='" << height << "' ";
|
||||
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_end() {
|
||||
std::cout << "</svg>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, std::string text) {
|
||||
std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>\n";
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height, std::string stroke, std::string fill){
|
||||
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height
|
||||
<< "' stroke='" << stroke << "' fill='" << fill << "' />\n";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins, const std::string& fill, const std::string& stroke) {
|
||||
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 size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
|
||||
size_t maxlen = 0;
|
||||
for (size_t len : bins)
|
||||
{
|
||||
if (maxlen<len) maxlen = len;
|
||||
}
|
||||
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
size_t wight = bin;
|
||||
if ((maxlen*10) > MAX_ASTERISK){
|
||||
if (maxlen != bin) wight = MAX_ASTERISK * (static_cast <double> (bin/maxlen));
|
||||
else if (maxlen == bin) wight = MAX_ASTERISK;
|
||||
}
|
||||
const double bin_width = BLOCK_WIDTH * wight;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
/*
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
//svg_text(20, 20, std::to_string(bins[0]));
|
||||
//svg_rect(50, 0, bins[0] * 10, 30);*/
|
||||
svg_end();
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void svg_begin(double width, double height);
|
||||
void svg_end();
|
||||
void svg_text(double left, double baseline, std::string text);
|
||||
void svg_rect(double x, double y, double width, double height, std::string stroke, std::string fill);
|
||||
void show_histogram_svg(const std::vector<size_t>& bins, const std::string& fill, const std::string& stroke);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
@ -1,31 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "text.h"
|
||||
|
||||
void show_histogram_text(std::vector<size_t>& bins, size_t bin_count) {
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
// Ïîèñê ìàêñèìàëüíîãî êîëè÷åñâà îöåíîê â îäíîì ñòîëáöå.
|
||||
|
||||
size_t max_count = bins[0];
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
}
|
||||
|
||||
// Ñîçäàíèå ãèñòîãðàììû ïî îöåíêàì.
|
||||
|
||||
size_t height;
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++) {
|
||||
std::cout << bins[i] << "|";
|
||||
height = bins[i];
|
||||
if (max_count > MAX_ASTERISK)
|
||||
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
for (size_t j = 1; j <= height; j++)
|
||||
std::cout << "*";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
#include <vector>
|
||||
|
||||
|
||||
void show_histogram_text(std::vector<size_t>& bins, size_t bin_count);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" 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/unittest" 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" />
|
||||
</Compiler>
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
@ -1,44 +0,0 @@
|
||||
#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("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("single element vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({5}, min, max);
|
||||
CHECK(min == 5);
|
||||
CHECK(max == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("negative numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-3, -1}, min, max);
|
||||
CHECK(min == -3);
|
||||
CHECK(max == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("identical elements") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({4, 4, 4}, min, max);
|
||||
CHECK(min == 4);
|
||||
CHECK(max == 4);
|
||||
}
|
Загрузка…
Ссылка в новой задаче