def assert_recon(tree, stree, recon):
    """Assert that a reconciliation is valid"""

    def below(node1, node2):
        """Return True if node1 is below node2"""
        while node1:
            if node1 == node2:
                return True
            node1 = node1.parent
        return False

    for node in tree:
        # Every node in gene tree should be in reconciliation
        assert node in recon

        # Every node should map to a species node equal to or
        # below their parent's mapping
        if node.parent:
            snode = recon[node]
            parent_snode = recon[node.parent]
            assert below(snode, parent_snode)