| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
"""Tests for topological sort.""" |
| 19 |
|
| 20 |
import pprint |
| 21 |
from unittest import TestCase |
| 22 |
|
| 23 |
from ..errors import GraphCycleError |
| 24 |
from ..graph import NULL_REVISION |
| 25 |
from ..tsort import MergeSorter, TopoSorter, merge_sort, topo_sort |
| 26 |
|
| 27 |
|
| 28 |
class TopoSortTests(TestCase): |
| 29 |
def assertSortAndIterate(self, graph, result_list): |
| 30 |
"""Check that sorting and iter_topo_order on graph works.""" |
| 31 |
self.assertEqual(result_list, topo_sort(graph)) |
| 32 |
self.assertEqual(result_list, list(TopoSorter(graph).iter_topo_order())) |
| 33 |
|
| 34 |
def assertSortAndIterateRaise(self, exception_type, graph): |
| 35 |
"""Try iterating and topo_sorting graph and expect an exception.""" |
| 36 |
self.assertRaises(exception_type, topo_sort, graph) |
| 37 |
self.assertRaises(exception_type, list, TopoSorter(graph).iter_topo_order()) |
| 38 |
|
| 39 |
def assertSortAndIterateOrder(self, graph): |
| 40 |
"""Check topo_sort and iter_topo_order is genuinely topological order. |
| 41 |
|
| 42 |
For every child in the graph, check if it comes after all of it's |
| 43 |
parents. |
| 44 |
""" |
| 45 |
sort_result = topo_sort(graph) |
| 46 |
iter_result = list(TopoSorter(graph).iter_topo_order()) |
| 47 |
for node, parents in graph: |
| 48 |
for parent in parents: |
| 49 |
if sort_result.index(node) < sort_result.index(parent): |
| 50 |
self.fail( |
| 51 |
f"parent {parent} must come before child {node}:\n{sort_result}" |
| 52 |
) |
| 53 |
if iter_result.index(node) < iter_result.index(parent): |
| 54 |
self.fail( |
| 55 |
f"parent {parent} must come before child {node}:\n{iter_result}" |
| 56 |
) |
| 57 |
|
| 58 |
def test_tsort_empty(self): |
| 59 |
"""TopoSort empty list.""" |
| 60 |
self.assertSortAndIterate([], []) |
| 61 |
|
| 62 |
def test_tsort_easy(self): |
| 63 |
"""TopoSort list with one node.""" |
| 64 |
self.assertSortAndIterate({0: []}.items(), [0]) |
| 65 |
|
| 66 |
def test_tsort_cycle(self): |
| 67 |
"""TopoSort traps graph with cycles.""" |
| 68 |
self.assertSortAndIterateRaise(GraphCycleError, {0: [1], 1: [0]}.items()) |
| 69 |
|
| 70 |
def test_tsort_cycle_2(self): |
| 71 |
"""TopoSort traps graph with longer cycle.""" |
| 72 |
self.assertSortAndIterateRaise( |
| 73 |
GraphCycleError, {0: [1], 1: [2], 2: [0]}.items() |
| 74 |
) |
| 75 |
|
| 76 |
def test_topo_sort_cycle_with_tail(self): |
| 77 |
"""TopoSort traps graph with longer cycle.""" |
| 78 |
self.assertSortAndIterateRaise( |
| 79 |
GraphCycleError, {0: [1], 1: [2], 2: [3, 4], 3: [0], 4: []}.items() |
| 80 |
) |
| 81 |
|
| 82 |
def test_tsort_1(self): |
| 83 |
"""TopoSort simple nontrivial graph.""" |
| 84 |
self.assertSortAndIterate( |
| 85 |
{0: [3], 1: [4], 2: [1, 4], 3: [], 4: [0, 3]}.items(), [3, 0, 4, 1, 2] |
| 86 |
) |
| 87 |
|
| 88 |
def test_tsort_partial(self): |
| 89 |
"""Topological sort with partial ordering. |
| 90 |
|
| 91 |
Multiple correct orderings are possible, so test for |
| 92 |
correctness, not for exact match on the resulting list. |
| 93 |
""" |
| 94 |
self.assertSortAndIterateOrder( |
| 95 |
[ |
| 96 |
(0, []), |
| 97 |
(1, [0]), |
| 98 |
(2, [0]), |
| 99 |
(3, [0]), |
| 100 |
(4, [1, 2, 3]), |
| 101 |
(5, [1, 2]), |
| 102 |
(6, [1, 2]), |
| 103 |
(7, [2, 3]), |
| 104 |
(8, [0, 1, 4, 5, 6]), |
| 105 |
] |
| 106 |
) |
| 107 |
|
| 108 |
def test_tsort_unincluded_parent(self): |
| 109 |
"""Sort nodes, but don't include some parents in the output.""" |
| 110 |
self.assertSortAndIterate([(0, [1]), (1, [2])], [1, 0]) |
| 111 |
|
| 112 |
|
| 113 |
class MergeSortTests(TestCase): |
| 114 |
def assertSortAndIterate( |
| 115 |
self, graph, branch_tip, result_list, generate_revno, mainline_revisions=None |
| 116 |
): |
| 117 |
"""Check that merge based sort and iter_topo_order on graph works.""" |
| 118 |
value = merge_sort( |
| 119 |
graph, |
| 120 |
branch_tip, |
| 121 |
mainline_revisions=mainline_revisions, |
| 122 |
generate_revno=generate_revno, |
| 123 |
) |
| 124 |
if result_list != value: |
| 125 |
self.assertEqualDiff(pprint.pformat(result_list), pprint.pformat(value)) |
| 126 |
self.assertEqual( |
| 127 |
result_list, |
| 128 |
list( |
| 129 |
MergeSorter( |
| 130 |
graph, |
| 131 |
branch_tip, |
| 132 |
mainline_revisions=mainline_revisions, |
| 133 |
generate_revno=generate_revno, |
| 134 |
).iter_topo_order() |
| 135 |
), |
| 136 |
) |
| 137 |
|
| 138 |
def test_merge_sort_empty(self): |
| 139 |
|
| 140 |
self.assertSortAndIterate({}, None, [], False) |
| 141 |
self.assertSortAndIterate({}, None, [], True) |
| 142 |
self.assertSortAndIterate({}, NULL_REVISION, [], False) |
| 143 |
self.assertSortAndIterate({}, NULL_REVISION, [], True) |
| 144 |
|
| 145 |
def test_merge_sort_not_empty_no_tip(self): |
| 146 |
|
| 147 |
|
| 148 |
self.assertSortAndIterate({0: []}.items(), None, [], False) |
| 149 |
self.assertSortAndIterate({0: []}.items(), None, [], True) |
| 150 |
|
| 151 |
def test_merge_sort_one_revision(self): |
| 152 |
|
| 153 |
|
| 154 |
self.assertSortAndIterate({"id": []}.items(), "id", [(0, "id", 0, True)], False) |
| 155 |
self.assertSortAndIterate( |
| 156 |
{"id": []}.items(), "id", [(0, "id", 0, (1,), True)], True |
| 157 |
) |
| 158 |
|
| 159 |
def test_sequence_numbers_increase_no_merges(self): |
| 160 |
|
| 161 |
|
| 162 |
self.assertSortAndIterate( |
| 163 |
{"A": [], "B": ["A"], "C": ["B"]}.items(), |
| 164 |
"C", |
| 165 |
[ |
| 166 |
(0, "C", 0, False), |
| 167 |
(1, "B", 0, False), |
| 168 |
(2, "A", 0, True), |
| 169 |
], |
| 170 |
False, |
| 171 |
) |
| 172 |
self.assertSortAndIterate( |
| 173 |
{"A": [], "B": ["A"], "C": ["B"]}.items(), |
| 174 |
"C", |
| 175 |
[ |
| 176 |
(0, "C", 0, (3,), False), |
| 177 |
(1, "B", 0, (2,), False), |
| 178 |
(2, "A", 0, (1,), True), |
| 179 |
], |
| 180 |
True, |
| 181 |
) |
| 182 |
|
| 183 |
def test_sequence_numbers_increase_with_merges(self): |
| 184 |
|
| 185 |
self.assertSortAndIterate( |
| 186 |
{"A": [], "B": ["A"], "C": ["A", "B"]}.items(), |
| 187 |
"C", |
| 188 |
[ |
| 189 |
(0, "C", 0, False), |
| 190 |
(1, "B", 1, True), |
| 191 |
(2, "A", 0, True), |
| 192 |
], |
| 193 |
False, |
| 194 |
) |
| 195 |
self.assertSortAndIterate( |
| 196 |
{"A": [], "B": ["A"], "C": ["A", "B"]}.items(), |
| 197 |
"C", |
| 198 |
[ |
| 199 |
(0, "C", 0, (2,), False), |
| 200 |
(1, "B", 1, (1, 1, 1), True), |
| 201 |
(2, "A", 0, (1,), True), |
| 202 |
], |
| 203 |
True, |
| 204 |
) |
| 205 |
|
| 206 |
def test_merge_sort_race(self): |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
graph = { |
| 217 |
"A": [], |
| 218 |
"B": ["A"], |
| 219 |
"C": ["B"], |
| 220 |
"D": ["B", "C"], |
| 221 |
"F": ["B", "D"], |
| 222 |
} |
| 223 |
self.assertSortAndIterate( |
| 224 |
graph, |
| 225 |
"F", |
| 226 |
[ |
| 227 |
(0, "F", 0, (3,), False), |
| 228 |
(1, "D", 1, (2, 2, 1), False), |
| 229 |
(2, "C", 2, (2, 1, 1), True), |
| 230 |
(3, "B", 0, (2,), False), |
| 231 |
(4, "A", 0, (1,), True), |
| 232 |
], |
| 233 |
True, |
| 234 |
) |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
graph = { |
| 245 |
"A": [], |
| 246 |
"B": ["A"], |
| 247 |
"C": ["B"], |
| 248 |
"X": ["B"], |
| 249 |
"D": ["X", "C"], |
| 250 |
"F": ["B", "D"], |
| 251 |
} |
| 252 |
self.assertSortAndIterate( |
| 253 |
graph, |
| 254 |
"F", |
| 255 |
[ |
| 256 |
(0, "F", 0, (3,), False), |
| 257 |
(1, "D", 1, (2, 1, 2), False), |
| 258 |
(2, "C", 2, (2, 2, 1), True), |
| 259 |
(3, "X", 1, (2, 1, 1), True), |
| 260 |
(4, "B", 0, (2,), False), |
| 261 |
(5, "A", 0, (1,), True), |
| 262 |
], |
| 263 |
True, |
| 264 |
) |
| 265 |
|
| 266 |
def test_merge_depth_with_nested_merges(self): |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
self.assertSortAndIterate( |
| 279 |
{ |
| 280 |
"A": ["D", "B"], |
| 281 |
"B": ["C", "F"], |
| 282 |
"C": ["H"], |
| 283 |
"D": ["H", "E"], |
| 284 |
"E": ["G", "F"], |
| 285 |
"F": ["G"], |
| 286 |
"G": ["H"], |
| 287 |
"H": [], |
| 288 |
}.items(), |
| 289 |
"A", |
| 290 |
[ |
| 291 |
(0, "A", 0, False), |
| 292 |
(1, "B", 1, False), |
| 293 |
(2, "C", 1, True), |
| 294 |
(3, "D", 0, False), |
| 295 |
(4, "E", 1, False), |
| 296 |
(5, "F", 2, True), |
| 297 |
(6, "G", 1, True), |
| 298 |
(7, "H", 0, True), |
| 299 |
], |
| 300 |
False, |
| 301 |
) |
| 302 |
self.assertSortAndIterate( |
| 303 |
{ |
| 304 |
"A": ["D", "B"], |
| 305 |
"B": ["C", "F"], |
| 306 |
"C": ["H"], |
| 307 |
"D": ["H", "E"], |
| 308 |
"E": ["G", "F"], |
| 309 |
"F": ["G"], |
| 310 |
"G": ["H"], |
| 311 |
"H": [], |
| 312 |
}.items(), |
| 313 |
"A", |
| 314 |
[ |
| 315 |
(0, "A", 0, (3,), False), |
| 316 |
(1, "B", 1, (1, 3, 2), False), |
| 317 |
(2, "C", 1, (1, 3, 1), True), |
| 318 |
(3, "D", 0, (2,), False), |
| 319 |
(4, "E", 1, (1, 1, 2), False), |
| 320 |
(5, "F", 2, (1, 2, 1), True), |
| 321 |
(6, "G", 1, (1, 1, 1), True), |
| 322 |
(7, "H", 0, (1,), True), |
| 323 |
], |
| 324 |
True, |
| 325 |
) |
| 326 |
|
| 327 |
def test_dotted_revnos_with_simple_merges(self): |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
self.assertSortAndIterate( |
| 340 |
{ |
| 341 |
"A": [], |
| 342 |
"B": ["A"], |
| 343 |
"C": ["A"], |
| 344 |
"D": ["B"], |
| 345 |
"E": ["C"], |
| 346 |
"F": ["C"], |
| 347 |
"G": ["D", "E"], |
| 348 |
"H": ["F"], |
| 349 |
"I": ["F"], |
| 350 |
"J": ["G", "H"], |
| 351 |
"K": ["I"], |
| 352 |
"L": ["J", "K"], |
| 353 |
}.items(), |
| 354 |
"L", |
| 355 |
[ |
| 356 |
(0, "L", 0, (6,), False), |
| 357 |
(1, "K", 1, (1, 3, 2), False), |
| 358 |
(2, "I", 1, (1, 3, 1), True), |
| 359 |
(3, "J", 0, (5,), False), |
| 360 |
(4, "H", 1, (1, 2, 2), False), |
| 361 |
(5, "F", 1, (1, 2, 1), True), |
| 362 |
(6, "G", 0, (4,), False), |
| 363 |
(7, "E", 1, (1, 1, 2), False), |
| 364 |
(8, "C", 1, (1, 1, 1), True), |
| 365 |
(9, "D", 0, (3,), False), |
| 366 |
(10, "B", 0, (2,), False), |
| 367 |
(11, "A", 0, (1,), True), |
| 368 |
], |
| 369 |
True, |
| 370 |
) |
| 371 |
|
| 372 |
|
| 373 |
self.assertSortAndIterate( |
| 374 |
{ |
| 375 |
"A": [], |
| 376 |
"B": ["A"], |
| 377 |
"C": ["A"], |
| 378 |
"D": ["B"], |
| 379 |
"E": ["C"], |
| 380 |
"F": ["C"], |
| 381 |
"G": ["D", "E"], |
| 382 |
"H": ["F"], |
| 383 |
"I": ["F"], |
| 384 |
"J": ["G", "H"], |
| 385 |
"K": ["I"], |
| 386 |
"L": ["J", "K"], |
| 387 |
"M": ["A"], |
| 388 |
"N": ["L", "M"], |
| 389 |
}.items(), |
| 390 |
"N", |
| 391 |
[ |
| 392 |
(0, "N", 0, (7,), False), |
| 393 |
(1, "M", 1, (1, 4, 1), True), |
| 394 |
(2, "L", 0, (6,), False), |
| 395 |
(3, "K", 1, (1, 3, 2), False), |
| 396 |
(4, "I", 1, (1, 3, 1), True), |
| 397 |
(5, "J", 0, (5,), False), |
| 398 |
(6, "H", 1, (1, 2, 2), False), |
| 399 |
(7, "F", 1, (1, 2, 1), True), |
| 400 |
(8, "G", 0, (4,), False), |
| 401 |
(9, "E", 1, (1, 1, 2), False), |
| 402 |
(10, "C", 1, (1, 1, 1), True), |
| 403 |
(11, "D", 0, (3,), False), |
| 404 |
(12, "B", 0, (2,), False), |
| 405 |
(13, "A", 0, (1,), True), |
| 406 |
], |
| 407 |
True, |
| 408 |
) |
| 409 |
|
| 410 |
def test_end_of_merge_not_last_revision_in_branch(self): |
| 411 |
|
| 412 |
|
| 413 |
self.assertSortAndIterate( |
| 414 |
{ |
| 415 |
"A": ["B"], |
| 416 |
"B": [], |
| 417 |
}, |
| 418 |
"A", |
| 419 |
[(0, "A", 0, False), (1, "B", 0, True)], |
| 420 |
False, |
| 421 |
) |
| 422 |
self.assertSortAndIterate( |
| 423 |
{ |
| 424 |
"A": ["B"], |
| 425 |
"B": [], |
| 426 |
}, |
| 427 |
"A", |
| 428 |
[(0, "A", 0, (2,), False), (1, "B", 0, (1,), True)], |
| 429 |
True, |
| 430 |
) |
| 431 |
|
| 432 |
def test_end_of_merge_multiple_revisions_merged_at_once(self): |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
self.assertSortAndIterate( |
| 447 |
{ |
| 448 |
"A": ["H", "B", "E"], |
| 449 |
"B": ["D", "C"], |
| 450 |
"C": ["D"], |
| 451 |
"D": ["H"], |
| 452 |
"E": ["G", "F"], |
| 453 |
"F": ["G"], |
| 454 |
"G": ["H"], |
| 455 |
"H": [], |
| 456 |
}, |
| 457 |
"A", |
| 458 |
[ |
| 459 |
(0, "A", 0, False), |
| 460 |
(1, "B", 1, False), |
| 461 |
(2, "C", 2, True), |
| 462 |
(3, "D", 1, True), |
| 463 |
(4, "E", 1, False), |
| 464 |
(5, "F", 2, True), |
| 465 |
(6, "G", 1, True), |
| 466 |
(7, "H", 0, True), |
| 467 |
], |
| 468 |
False, |
| 469 |
) |
| 470 |
self.assertSortAndIterate( |
| 471 |
{ |
| 472 |
"A": ["H", "B", "E"], |
| 473 |
"B": ["D", "C"], |
| 474 |
"C": ["D"], |
| 475 |
"D": ["H"], |
| 476 |
"E": ["G", "F"], |
| 477 |
"F": ["G"], |
| 478 |
"G": ["H"], |
| 479 |
"H": [], |
| 480 |
}, |
| 481 |
"A", |
| 482 |
[ |
| 483 |
(0, "A", 0, (2,), False), |
| 484 |
(1, "B", 1, (1, 3, 2), False), |
| 485 |
(2, "C", 2, (1, 4, 1), True), |
| 486 |
(3, "D", 1, (1, 3, 1), True), |
| 487 |
(4, "E", 1, (1, 1, 2), False), |
| 488 |
(5, "F", 2, (1, 2, 1), True), |
| 489 |
(6, "G", 1, (1, 1, 1), True), |
| 490 |
(7, "H", 0, (1,), True), |
| 491 |
], |
| 492 |
True, |
| 493 |
) |
| 494 |
|
| 495 |
def test_mainline_revs_partial(self): |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
self.assertSortAndIterate( |
| 524 |
{"A": ["E", "B"], "B": ["D", "C"], "C": ["D"], "D": ["E"], "E": []}, |
| 525 |
"A", |
| 526 |
[ |
| 527 |
(0, "A", 0, False), |
| 528 |
(1, "B", 0, False), |
| 529 |
(2, "C", 1, True), |
| 530 |
], |
| 531 |
False, |
| 532 |
mainline_revisions=["D", "B", "A"], |
| 533 |
) |
| 534 |
self.assertSortAndIterate( |
| 535 |
{"A": ["E", "B"], "B": ["D", "C"], "C": ["D"], "D": ["E"], "E": []}, |
| 536 |
"A", |
| 537 |
[ |
| 538 |
(0, "A", 0, (4,), False), |
| 539 |
(1, "B", 0, (3,), False), |
| 540 |
(2, "C", 1, (2, 1, 1), True), |
| 541 |
], |
| 542 |
True, |
| 543 |
mainline_revisions=["D", "B", "A"], |
| 544 |
) |
| 545 |
|
| 546 |
def test_mainline_revs_with_none(self): |
| 547 |
|
| 548 |
|
| 549 |
self.assertSortAndIterate( |
| 550 |
{ |
| 551 |
"A": [], |
| 552 |
}, |
| 553 |
"A", |
| 554 |
[ |
| 555 |
(0, "A", 0, True), |
| 556 |
], |
| 557 |
False, |
| 558 |
mainline_revisions=[None, "A"], |
| 559 |
) |
| 560 |
self.assertSortAndIterate( |
| 561 |
{ |
| 562 |
"A": [], |
| 563 |
}, |
| 564 |
"A", |
| 565 |
[ |
| 566 |
(0, "A", 0, (1,), True), |
| 567 |
], |
| 568 |
True, |
| 569 |
mainline_revisions=[None, "A"], |
| 570 |
) |
| 571 |
|
| 572 |
def test_mainline_revs_with_ghost(self): |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
self.assertSortAndIterate( |
| 577 |
{"B": [], "C": ["B"]}.items(), |
| 578 |
"C", |
| 579 |
[ |
| 580 |
(0, "C", 0, (2,), False), |
| 581 |
(1, "B", 0, (1,), True), |
| 582 |
], |
| 583 |
True, |
| 584 |
mainline_revisions=["A", "B", "C"], |
| 585 |
) |
| 586 |
|
| 587 |
def test_parallel_root_sequence_numbers_increase_with_merges(self): |
| 588 |
"""When there are parallel roots, check their revnos.""" |
| 589 |
self.assertSortAndIterate( |
| 590 |
{"A": [], "B": [], "C": ["A", "B"]}.items(), |
| 591 |
"C", |
| 592 |
[ |
| 593 |
(0, "C", 0, (2,), False), |
| 594 |
(1, "B", 1, (0, 1, 1), True), |
| 595 |
(2, "A", 0, (1,), True), |
| 596 |
], |
| 597 |
True, |
| 598 |
) |
| 599 |
|
| 600 |
def test_revnos_are_globally_assigned(self): |
| 601 |
"""Revnos are assigned according to the revision they derive from.""" |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
self.assertSortAndIterate( |
| 620 |
{ |
| 621 |
"J": ["G", "I"], |
| 622 |
"I": [ |
| 623 |
"H", |
| 624 |
], |
| 625 |
"H": ["A"], |
| 626 |
"G": ["D", "F"], |
| 627 |
"F": ["E"], |
| 628 |
"E": ["A"], |
| 629 |
"D": ["A", "C"], |
| 630 |
"C": ["B"], |
| 631 |
"B": ["A"], |
| 632 |
"A": [], |
| 633 |
}.items(), |
| 634 |
"J", |
| 635 |
[ |
| 636 |
(0, "J", 0, (4,), False), |
| 637 |
(1, "I", 1, (1, 3, 2), False), |
| 638 |
(2, "H", 1, (1, 3, 1), True), |
| 639 |
(3, "G", 0, (3,), False), |
| 640 |
(4, "F", 1, (1, 2, 2), False), |
| 641 |
(5, "E", 1, (1, 2, 1), True), |
| 642 |
(6, "D", 0, (2,), False), |
| 643 |
(7, "C", 1, (1, 1, 2), False), |
| 644 |
(8, "B", 1, (1, 1, 1), True), |
| 645 |
(9, "A", 0, (1,), True), |
| 646 |
], |
| 647 |
True, |
| 648 |
) |
| 649 |
|
| 650 |
def test_roots_and_sub_branches_versus_ghosts(self): |
| 651 |
"""Extra roots and their mini branches use the same numbering. |
| 652 |
|
| 653 |
All of them use the 0-node numbering. |
| 654 |
""" |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
self.assertSortAndIterate( |
| 667 |
{ |
| 668 |
"A": [], |
| 669 |
"B": ["A"], |
| 670 |
"C": ["B"], |
| 671 |
"D": [], |
| 672 |
"E": ["D"], |
| 673 |
"F": ["D"], |
| 674 |
"G": ["E", "F"], |
| 675 |
"H": ["C", "G"], |
| 676 |
"I": [], |
| 677 |
"J": ["H", "I"], |
| 678 |
"K": [], |
| 679 |
"L": ["K"], |
| 680 |
"M": ["K"], |
| 681 |
"N": ["L", "M"], |
| 682 |
"O": ["N"], |
| 683 |
"P": ["N"], |
| 684 |
"Q": ["O", "P"], |
| 685 |
"R": ["J", "Q"], |
| 686 |
}.items(), |
| 687 |
"R", |
| 688 |
[ |
| 689 |
(0, "R", 0, (6,), False), |
| 690 |
(1, "Q", 1, (0, 4, 5), False), |
| 691 |
(2, "P", 2, (0, 6, 1), True), |
| 692 |
(3, "O", 1, (0, 4, 4), False), |
| 693 |
(4, "N", 1, (0, 4, 3), False), |
| 694 |
(5, "M", 2, (0, 5, 1), True), |
| 695 |
(6, "L", 1, (0, 4, 2), False), |
| 696 |
(7, "K", 1, (0, 4, 1), True), |
| 697 |
(8, "J", 0, (5,), False), |
| 698 |
(9, "I", 1, (0, 3, 1), True), |
| 699 |
(10, "H", 0, (4,), False), |
| 700 |
(11, "G", 1, (0, 1, 3), False), |
| 701 |
(12, "F", 2, (0, 2, 1), True), |
| 702 |
(13, "E", 1, (0, 1, 2), False), |
| 703 |
(14, "D", 1, (0, 1, 1), True), |
| 704 |
(15, "C", 0, (3,), False), |
| 705 |
(16, "B", 0, (2,), False), |
| 706 |
(17, "A", 0, (1,), True), |
| 707 |
], |
| 708 |
True, |
| 709 |
) |