|
|
|
@ -3,6 +3,8 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
#include "histogram_internal.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
TEST_CASE("distinct positive numbers") {
|
|
|
|
|
double min = 0;
|
|
|
|
@ -19,15 +21,6 @@ TEST_CASE("negative numbers") {
|
|
|
|
|
CHECK(min == -10);
|
|
|
|
|
CHECK(max == 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("empty numbers") {
|
|
|
|
|
double min = 0;
|
|
|
|
|
double max = 0;
|
|
|
|
|
find_minmax({ }, min, max);
|
|
|
|
|
CHECK(min != 0);
|
|
|
|
|
CHECK(max != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("one number") {
|
|
|
|
|
double min = 0;
|
|
|
|
|
double max = 0;
|
|
|
|
@ -36,9 +29,25 @@ TEST_CASE("one number") {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|