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