Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pgraph/PGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def __str__(self) -> str:
:return: one-line summary of vertex/edge/component counts
:rtype: str

Counts of 1,000 or more have thousands separators.

.. runblock:: pycon

>>> from pgraph import UGraph
Expand All @@ -301,7 +303,7 @@ def __str__(self) -> str:

:seealso: :meth:`show`
"""
s = f"{self.__class__.__name__}: {self.n} {'vertex' if self.n==1 else 'vertices'}, {self.ne} edge{'s'[:self.ne^1]}, {self.nc} component{'s'[:self.nc^1]}"
s = f"{self.__class__.__name__}: {self.n:,} {'vertex' if self.n==1 else 'vertices'}, {self.ne:,} edge{'s'[:self.ne^1]}, {self.nc:,} component{'s'[:self.nc^1]}"
return s

def __repr__(self) -> str:
Expand Down
17 changes: 16 additions & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import numpy.testing as nt

from pgraph import *
from pgraph import DGraph, Edge, UGraph, Vertex

class TestUGraph(unittest.TestCase):

Expand Down Expand Up @@ -51,6 +51,21 @@ def test_str(self):
self.assertEqual(len(lines), 3) # class-name header + one line per vertex
self.assertEqual(lines[0], "DGraph:")


def test_str_has_thousands_separators(self):
# counts of 1,000 or more are easier to read with separators
g = UGraph()
vs = [g.add_vertex() for _ in range(1001)]
self.assertEqual(str(g), "UGraph: 1,001 vertices, 0 edges, 1,001 components")
for a, b in zip(vs, vs[1:]):
g.add_edge(a, b)
self.assertEqual(str(g), "UGraph: 1,001 vertices, 1,000 edges, 1 component")
# below a thousand it is as before
h = UGraph()
for _ in range(999):
h.add_vertex()
self.assertEqual(str(h), "UGraph: 999 vertices, 0 edges, 999 components")

def test_attr(self):

g = UGraph()
Expand Down
Loading