1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#include <filesystem>
#include <format>
#include <fstream>
#include <stdexcept>
#include <string_view>
#include <unordered_set>
#include "test_utilities.h"
const std::unordered_set<std::string_view> node_shapes_consisting_of_ellipse = {
"ellipse", //
"oval", //
"circle", //
"doublecircle", //
"point", //
};
const std::unordered_set<std::string_view>
node_shapes_consisting_of_ellipse_and_polyline = {
"Mcircle", //
};
const std::unordered_set<std::string_view> node_shapes_consisting_of_path = {
"cylinder", //
};
const std::unordered_set<std::string_view> node_shapes_consisting_of_polygon = {
"box", //
"polygon", //
"egg", //
"triangle", //
"diamond", //
"trapezium", //
"parallelogram", //
"house", //
"pentagon", //
"hexagon", //
"septagon", //
"octagon", //
"doubleoctagon", //
"tripleoctagon", //
"invtriangle", //
"invtrapezium", //
"invhouse", //
"rect", //
"rectangle", //
"square", //
"star", //
"cds", //
"rpromoter", //
"rarrow", //
"larrow", //
"lpromoter", //
"folder", //
};
const std::unordered_set<std::string_view>
node_shapes_consisting_of_polygon_and_polyline = {
"Mdiamond", //
"Msquare", //
"underline", //
"note", //
"tab", //
"box3d", //
"component", //
"promoter", //
"terminator", //
"utr", //
"primersite", //
"restrictionsite", //
"fivepoverhang", //
"threepoverhang", //
"noverhang", //
"assembly", //
"signature", //
"insulator", //
"ribosite", //
"rnastab", //
"proteasesite", //
"proteinstab", //
};
const std::unordered_set<std::string_view> node_shapes_without_svg_shape = {
"plaintext", //
"plain", //
"none", //
};
const std::unordered_set<std::string_view> all_node_shapes = {
"box", //
"polygon", //
"ellipse", //
"oval", //
"circle", //
"point", //
"egg", //
"triangle", //
"plaintext", //
"plain", //
"diamond", //
"trapezium", //
"parallelogram", //
"house", //
"pentagon", //
"hexagon", //
"septagon", //
"octagon", //
"doublecircle", //
"doubleoctagon", //
"tripleoctagon", //
"invtriangle", //
"invtrapezium", //
"invhouse", //
"Mdiamond", //
"Msquare", //
"Mcircle", //
"rect", //
"rectangle", //
"square", //
"star", //
"none", //
"underline", //
"cylinder", //
"note", //
"tab", //
"folder", //
"box3d", //
"component", //
"promoter", //
"cds", //
"terminator", //
"utr", //
"primersite", //
"restrictionsite", //
"fivepoverhang", //
"threepoverhang", //
"noverhang", //
"assembly", //
"signature", //
"insulator", //
"ribosite", //
"rnastab", //
"proteasesite", //
"proteinstab", //
"rpromoter", //
"rarrow", //
"larrow", //
"lpromoter" //
};
static const std::unordered_set<std::string_view>
node_shapes_containing_multiple_same_shapes_with_different_fill = {
"cylinder", // two paths
"doublecircle", // two ellipses
"doubleoctagon", // two polygons
"tripleoctagon", // three polygons
};
bool contains_polygon_shape(const std::string_view shape) {
return node_shapes_consisting_of_polygon.contains(shape) ||
node_shapes_consisting_of_polygon_and_polyline.contains(shape);
}
bool contains_polyline_shape(const std::string_view shape) {
return node_shapes_consisting_of_ellipse_and_polyline.contains(shape) ||
node_shapes_consisting_of_polygon_and_polyline.contains(shape);
}
bool contains_ellipse_shape(const std::string_view shape) {
return node_shapes_consisting_of_ellipse.contains(shape) ||
node_shapes_consisting_of_ellipse_and_polyline.contains(shape);
}
bool contains_multiple_shapes_with_different_fill(
const std::string_view shape) {
return node_shapes_containing_multiple_same_shapes_with_different_fill
.contains(shape) ||
contains_polyline_shape(shape);
}
bool is_polygon_shape(const std::string_view shape) {
return node_shapes_consisting_of_polygon.contains(shape);
}
const std::unordered_set<std::string_view> primitive_polygon_arrow_shapes = {
"crow", "diamond", "inv", "normal", "vee"};
const std::unordered_set<std::string_view>
primitive_polygon_and_polyline_arrow_shapes = {"box", "tee"};
const std::unordered_set<std::string_view> all_primitive_arrow_shapes = {
"box", "crow", "curve", "diamond", "dot", "icurve",
"inv", "none", "normal", "tee", "vee"};
const std::unordered_set<std::string_view>
primitive_arrow_shapes_without_closed_svg_shape = {"curve", "icurve",
"none"};
const std::unordered_set<std::string_view> all_arrow_shape_modifiers = {
"", "o", "l", "r"};
const std::unordered_set<std::string_view> all_rank_directions = {"TB", "BT",
"LR", "RL"};
const std::unordered_set<std::string_view> all_edge_directions = {
"forward", "back", "both", "none"};
void write_to_file(const std::filesystem::path &directory,
const std::filesystem::path &filename,
const std::string_view text) {
std::filesystem::create_directories(directory);
const std::filesystem::path test_artifacts_path = directory / filename;
std::ofstream outfile{test_artifacts_path};
if (!outfile.is_open()) {
throw std::runtime_error{std::format("Could not create output file \"{}\"",
test_artifacts_path.native())};
}
outfile << text;
}
|