TU-Programmieren_2/exercise6/task2.test.cpp
2025-04-09 10:22:44 +02:00

70 lines
2.0 KiB
C++

/// @file
/// @brief Task2: tests
#include "task2.Circle.hpp"
#include "task2.Line.hpp"
#include "task2.Polyline.hpp"
#include "task2.aliases.hpp"
#include <cassert> // assert
#include <iostream> // std::cout, sts::endl
#include <string> // std::string
bool contains(const std::string& str, const std::string& pattern) { return str.find(pattern) != std::string::npos; }
bool check_defaults(const std::string& str) {
if (!contains(str, "stroke-width='1'"))
return false;
if (!contains(str, "fill='none'"))
return false;
if (!contains(str, "stroke='black'"))
return false;
return true;
}
int main() {
{ // LineElement
auto line = task2::Line{{0, 0}, {11, 12}};
auto elem = task2::LineElement(line);
auto openstr = elem.open();
assert(check_defaults(openstr));
assert(openstr.starts_with("<line"));
assert(contains(openstr, "x1='0'"));
assert(contains(openstr, "y1='0'"));
assert(contains(openstr, "x2='11'"));
assert(contains(openstr, "y2='12'"));
assert(openstr.ends_with("/>"));
assert(elem.text().empty() && elem.close().empty());
}
{ // CircleElement
auto circle = task2::Circle{{5, 6}, 5};
auto elem = task2::CircleElement(circle);
auto openstr = elem.open();
assert(check_defaults(openstr));
assert(openstr.starts_with("<circle"));
assert(contains(openstr, "cx='5'"));
assert(contains(openstr, "cy='6'"));
assert(contains(openstr, "r='5'"));
assert(openstr.ends_with("/>"));
assert(elem.text().empty() && elem.close().empty());
}
{ // PolylineElement
auto polyline = task2::Polyline{{1, 2}, {3, 4}, {5, 6}};
auto elem = task2::PolylineElement(polyline);
auto openstr = elem.open();
assert(check_defaults(openstr));
assert(openstr.starts_with("<polyline"));
assert(contains(openstr, "points="));
assert(contains(openstr, "1,2 3,4 5,6"));
assert(openstr.ends_with("/>"));
assert(elem.text().empty() && elem.close().empty());
}
std::cout << "task2.test.cpp: all asserts passed" << std::endl;
return 0;
}