# Ticket #14251: trac_14251-input.patch

File trac_14251-input.patch, 2.1 KB (added by ncohen, 7 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 - ``n`` (integer) -- number of vertices. - ``integers`` -- the list of integers such that there is an edge from `i` to `j` if and only if ``(j-i) in integers``. `i` to `j` if and only if ``(j-i)%n in integers``. EXAMPLE:: sage: digraphs.Circulant(13,[3,5,7]) Circulant graph ([3, 5, 7]): Digraph on 13 vertices TESTS:: sage: digraphs.Circulant(13,[3,5,7,"hey"]) Traceback (most recent call last): ... ValueError: The list must contain only relative integers. sage: digraphs.Circulant(-2,[3,5,7,3]) Traceback (most recent call last): ... ValueError: n must be a positive integer sage: digraphs.Circulant(3,[3,5,7,3.4]) Traceback (most recent call last): ... ValueError: The list must contain only relative integers. """ from sage.graphs.graph_plot import _circle_embedding from sage.rings.integer_ring import ZZ G=DiGraph(n, name="Circulant graph ("+str(integers)+")") # Bad input and loops loops = False if not n in ZZ or n <= 0: raise ValueError("n must be a positive integer") for i in integers: if not i in ZZ: raise ValueError("The list must contain only relative integers.") if (i%n) == 0: loops = True G=DiGraph(n, name="Circulant graph ("+str(integers)+")", loops=loops) _circle_embedding(G, range(n)) for v in range(n): G.add_edges([(v,(v+j)%n) for j in integers])