@@ -147,7 +147,25 @@ def test_in_dict(self):
147
147
self .assertEqual (g .in_mapping [key ], expected_in_mapping [key ])
148
148
149
149
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]]>' )
151
169
152
170
def test_cycle (self ):
153
171
g = graph .cycle (1 , directed = False )
0 commit comments