Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
54 строки
1.5 KiB
C++
54 строки
1.5 KiB
C++
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
#include <vector>
|
|
#include "doctest.h"
|
|
#include "histogram_internal.h"
|
|
#include "svg.h"
|
|
#include <string>
|
|
|
|
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("negative numbers") {
|
|
double min = 0;
|
|
double max = 0;
|
|
find_minmax({ -10, 10 }, min, max);
|
|
CHECK(min == -10);
|
|
CHECK(max == 10);
|
|
}
|
|
TEST_CASE("one number") {
|
|
double min = 0;
|
|
double max = 0;
|
|
find_minmax({ 2 }, min, max);
|
|
CHECK(min == 2);
|
|
CHECK(max == 2);
|
|
}
|
|
|
|
#include "doctest.h"
|
|
#include "svg.h"
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
TEST_CASE("show_histogram_svg") {
|
|
std::ostringstream oss;
|
|
std::streambuf* p_cout_streambuf = std::cout.rdbuf();
|
|
std::cout.rdbuf(oss.rdbuf());
|
|
show_histogram_svg({1, 2, 3, 4});
|
|
std::cout.rdbuf(p_cout_streambuf);
|
|
std::string result = oss.str();
|
|
std::string expected = "<?xml version='1.0' encoding='UTF-8'?>"
|
|
"<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>"
|
|
"<rect x='30' y='0' width='10' height='30' />"
|
|
"<text x='40' y='20'>1</text><rect x='20' y='30' width='20' height='30' />"
|
|
"<text x='40' y='50'>2</text><rect x='10' y='60' width='30' height='30' />"
|
|
"<text x='40' y='80'>3</text><rect x='0' y='90' width='40' height='30' />"
|
|
"<text x='40' y='110'>4</text></svg>";
|
|
CHECK(result == expected);
|
|
}
|
|
|