Ticket #14251: trac_14251-input.patch

File trac_14251-input.patch, 2.1 KB (added by ncohen, 6 years ago)
  • sage/graphs/digraph_generators.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1362936713 -3600
    # Node ID 7155a996555d877a85937ea4bd614acdb7b9b379
    # Parent  54ba71ab92f2c6e76d37dba445f807737651fe92
    Circulant digraphs -- bad input
    
    diff --git a/sage/graphs/digraph_generators.py b/sage/graphs/digraph_generators.py
    a b  
    392392        - ``n`` (integer) -- number of vertices.
    393393
    394394        - ``integers`` -- the list of integers such that there is an edge from
    395           `i` to `j` if and only if ``(j-i) in integers``.
     395          `i` to `j` if and only if ``(j-i)%n in integers``.
    396396
    397397        EXAMPLE::
    398398
    399399            sage: digraphs.Circulant(13,[3,5,7])
    400400            Circulant graph ([3, 5, 7]): Digraph on 13 vertices
     401
     402        TESTS::
     403
     404            sage: digraphs.Circulant(13,[3,5,7,"hey"])
     405            Traceback (most recent call last):
     406            ...
     407            ValueError: The list must contain only relative integers.
     408            sage: digraphs.Circulant(-2,[3,5,7,3])
     409            Traceback (most recent call last):
     410            ...
     411            ValueError: n must be a positive integer
     412            sage: digraphs.Circulant(3,[3,5,7,3.4])
     413            Traceback (most recent call last):
     414            ...
     415            ValueError: The list must contain only relative integers.
    401416        """
    402417        from sage.graphs.graph_plot import _circle_embedding
     418        from sage.rings.integer_ring import ZZ
    403419
    404         G=DiGraph(n, name="Circulant graph ("+str(integers)+")")
     420        # Bad input and loops
     421        loops = False
     422        if not n in ZZ or n <= 0:
     423            raise ValueError("n must be a positive integer")
     424
     425        for i in integers:
     426            if not i in ZZ:
     427                raise ValueError("The list must contain only relative integers.")
     428            if (i%n) == 0:
     429                loops = True
     430
     431        G=DiGraph(n, name="Circulant graph ("+str(integers)+")", loops=loops)
     432
    405433        _circle_embedding(G, range(n))
    406 
    407434        for v in range(n):
    408435            G.add_edges([(v,(v+j)%n) for j in integers])
    409436