Ticket #10900: trac_10900.patch

File trac_10900.patch, 7.4 KB (added by ncohen, 10 years ago)
  • sage/graphs/base/c_graph.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1299736826 -28800
    # Node ID 299c2995b46c8fb70a1785c46017e67227c67ea5
    # Parent  361a4ad7d52c69b64ae2e658ffd0820af0d87e93
    trac 10900 -- 100% doctest coverage for graphs
    
    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/c_graph.pyx
    a b  
    28852885    - ``test_in`` -- boolean; whether we want to consider the in-neighbors of
    28862886      the graph to be traversed. For undirected graphs, we consider both
    28872887      the in- and out-neighbors.
     2888
     2889    EXAMPLE::
     2890
     2891        sage: g = graphs.PetersenGraph()
     2892        sage: list(g.breadth_first_search(0))
     2893        [0, 1, 4, 5, 2, 6, 3, 9, 7, 8]
    28882894    """
    28892895
    28902896    cdef graph
     
    29252931        - ``ignore_direction`` -- boolean (default: ``False``). This is only
    29262932          relevant to digraphs. If ``graph`` is a digraph, ignore all
    29272933          orientations and consider the graph as undirected.
     2934
     2935        EXAMPLE::
     2936       
     2937            sage: g = graphs.PetersenGraph()
     2938            sage: list(g.breadth_first_search(0))
     2939            [0, 1, 4, 5, 2, 6, 3, 9, 7, 8]
    29282940        """
    29292941        self.graph = graph
    29302942        self.direction = direction
     
    29462958    def __iter__(self):
    29472959        r"""
    29482960        Return an iterator object over a traversal of a graph.
     2961
     2962        EXAMPLE::
     2963       
     2964            sage: g = graphs.PetersenGraph()
     2965            sage: g.breadth_first_search(0)
     2966            <generator object breadth_first_search at ...
    29492967        """
    29502968        return self
    29512969
    29522970    def __next__(self):
    29532971        r"""
    29542972        Return the next vertex in a traversal of a graph.
     2973
     2974        EXAMPLE::
     2975       
     2976            sage: g = graphs.PetersenGraph()
     2977            sage: g.breadth_first_search(0)
     2978            <generator object breadth_first_search at ...
     2979            sage: g.breadth_first_search(0).next()
     2980            0
    29552981        """
    29562982        cdef int v_int
    29572983        cdef int w_int
  • sage/graphs/base/dense_graph.pyx

    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/dense_graph.pyx
    a b  
    156156        Memory usage is
    157157       
    158158        O(  (nverts + extra_vertices)^2  ).
    159        
     159
     160        EXAMPLE::
     161
     162            sage: from sage.graphs.base.dense_graph import DenseGraph
     163            sage: D = DenseGraph(nverts = 10, extra_vertices = 10)
    160164        """
    161165        if nverts == 0 and extra_vertices == 0:
    162166            raise RuntimeError('Dense graphs must allocate space for vertices!')
  • sage/graphs/base/graph_backends.py

    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/graph_backends.py
    a b  
    480480    def __init__(self):
    481481        """
    482482        Issue deprecation warnings for the old networkx XGraph formats
     483
     484        EXAMPLE::
     485
     486            sage: from sage.graphs.base.graph_backends import NetworkXGraphDeprecated
     487            sage: NetworkXGraphDeprecated()
     488            doctest:...
     489            <class 'sage.graphs.base.graph_backends.NetworkXGraphDeprecated'>
    483490        """
    484491        import warnings
    485492        from sage.misc.misc import deprecation
     
    532539    def __init__(self):
    533540        """
    534541        Issue deprecation warnings for the old networkx XDiGraph formats
     542
     543        EXAMPLE::
     544
     545            sage: from sage.graphs.base.graph_backends import NetworkXDiGraphDeprecated
     546            sage: NetworkXDiGraphDeprecated()
     547            doctest:...
     548            <class 'sage.graphs.base.graph_backends.NetworkXDiGraphDeprecated'>
    535549        """
    536550        import warnings
    537551        from sage.misc.misc import deprecation
     
    913927        """
    914928        Iterate over the incoming edges incident to a sequence of vertices.
    915929        Special case, only for internal use.
     930
     931        EXAMPLE::
     932
     933            sage: g = DiGraph(graphs.PetersenGraph(), implementation="networkx")._backend
     934            sage: sorted(list(g.iterator_in_edges([0,1], True)))
     935            [(0, 1, None), (1, 0, None), (2, 1, None), (4, 0, None), (5, 0, None), (6, 1, None)]
    916936        """
    917937        try:
    918938            assert(not isinstance(self._nxg, (NetworkXGraphDeprecated, NetworkXDiGraphDeprecated)))
     
    955975        """
    956976        Iterate over the outbound edges incident to a sequence of vertices.
    957977        Special case, only for internal use.
     978
     979        EXAMPLE::
     980
     981            sage: g = DiGraph(graphs.PetersenGraph(), implementation="networkx")._backend
     982            sage: sorted(list(g.iterator_out_edges([0,1], True)))
     983            [(0, 1, None), (0, 4, None), (0, 5, None), (1, 0, None), (1, 2, None), (1, 6, None)]
    958984        """
    959985        try:
    960986            assert(not isinstance(self._nxg, (NetworkXGraphDeprecated, NetworkXDiGraphDeprecated)))
  • sage/graphs/base/sparse_graph.pyx

    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/sparse_graph.pyx
    a b  
    285285        Memory usage is roughly
    286286       
    287287        O(  (nverts + extra_vertices)*expected_degree + num_arcs  ).
    288        
    289         """
     288
     289        EXAMPLE::
     290
     291            sage: from sage.graphs.base.sparse_graph import SparseGraph
     292            sage: S = SparseGraph(nverts = 10, expected_degree = 3, extra_vertices = 10)
     293
     294         """
    290295        cdef int i = 1
    291296        if nverts == 0 and extra_vertices == 0:
    292297            raise RuntimeError('Sparse graphs must allocate space for vertices!')
  • sage/graphs/generic_graph.py

    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/generic_graph.py
    a b  
    1330213302
    1330313303    def _keys_for_vertices(self):
    1330413304        """
    13305         Returns a function mapping each vertex to a unique and hopefully readable string
     13305        Returns a function mapping each vertex to a unique and hopefully
     13306        readable string
     13307
     13308        EXAMPLE::
     13309
     13310            sage: g = graphs.Grid2dGraph(5,5)
     13311            sage: g._keys_for_vertices()
     13312            <function key at ...
    1330613313        """
    1330713314        from sage.graphs.dot2tex_utils import key, key_with_hash
    1330813315        if len(set(key(v) for v in self)) < len(self.vertices()):
  • sage/graphs/generic_graph_pyx.pyx

    diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/generic_graph_pyx.pyx
    a b  
    483483
    484484        This constructor only checks there is no inconsistency in the
    485485        input : `G` and `H` are both graphs or both digraphs.
     486
     487        EXAMPLE::
     488
     489            sage: g = graphs.PetersenGraph()
     490            sage: g.subgraph_search(graphs.CycleGraph(5))
     491            Subgraph of (Petersen graph): Graph on 5 vertices
    486492        """
    487493        if sum([G.is_directed(), H.is_directed()]) == 1:
    488494            raise ValueError("One graph can not be directed while the other is not.")
     
    596602        Cython constructor
    597603
    598604        This method initializes all the C values.
     605
     606        EXAMPLE::
     607
     608            sage: g = graphs.PetersenGraph()
     609            sage: g.subgraph_search(graphs.CycleGraph(5))
     610            Subgraph of (Petersen graph): Graph on 5 vertices
    599611        """
    600612
    601613        # Storing the number of vertices