| 1461 | |
| 1462 | |
| 1463 | def test_get_index_utility_function() -> None: |
| 1464 | root = Node(0) |
| 1465 | root.left = Node(1) |
| 1466 | root.right = Node(2) |
| 1467 | root.left.left = Node(3) |
| 1468 | root.right.right = Node(4) |
| 1469 | |
| 1470 | assert get_index(root, root) == 0 |
| 1471 | assert get_index(root, root.left) == 1 |
| 1472 | assert get_index(root, root.right) == 2 |
| 1473 | assert get_index(root, root.left.left) == 3 |
| 1474 | assert get_index(root, root.right.right) == 6 |
| 1475 | |
| 1476 | with pytest.raises(NodeReferenceError) as err1: |
| 1477 | get_index(root.left, root.right) |
| 1478 | assert str(err1.value) == "given nodes are not in the same tree" |
| 1479 | |
| 1480 | with pytest.raises(NodeTypeError) as err2: |
| 1481 | get_index(root, None) # type: ignore |
| 1482 | assert str(err2.value) == "descendent must be a Node instance" |
| 1483 | |
| 1484 | with pytest.raises(NodeTypeError) as err3: |
| 1485 | get_index(None, root.left) # type: ignore |
| 1486 | assert str(err3.value) == "root must be a Node instance" |
| 1487 | |
| 1488 | |
| 1489 | def test_get_parent_utility_function() -> None: |