Skip to content

Commit 5916039

Browse files
meatballsmarcharper
authored andcommitted
Add test for __repr__ method
1 parent 7fcb3a5 commit 5916039

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

axelrod/tests/unit/test_graph.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,25 @@ def test_in_dict(self):
147147
self.assertEqual(g.in_mapping[key], expected_in_mapping[key])
148148

149149
def test_repr(self):
150-
pass
150+
# Undirected graph with no vertices
151+
g = graph.Graph()
152+
self.assertEqual(str(g), '<Graph: None>')
153+
154+
# Directed graph with no vertices
155+
g = graph.Graph(directed=True)
156+
self.assertEqual(str(g), '<Graph: None>')
157+
158+
# Undirected graph with vertices and unweighted edges
159+
g = graph.Graph(edges=[[1, 2], [2, 3]])
160+
self.assertEqual(str(g), '<Graph: [[1, 2], [2, 3]]>')
161+
162+
# Undirected graph with vertices and weighted edges
163+
g = graph.Graph(edges=[[1, 2, 10], [2, 3, 5]])
164+
self.assertEqual(str(g), '<Graph: [[1, 2, 10], [2, 3, 5]]>')
165+
166+
# Directed graph with vertices and weighted edges
167+
g = graph.Graph(edges=[[1, 2, 10], [2, 3, 5]], directed=True)
168+
self.assertEqual(str(g), '<Graph: [[1, 2, 10], [2, 3, 5]]>')
151169

152170
def test_cycle(self):
153171
g = graph.cycle(1, directed=False)

0 commit comments

Comments
 (0)