@@ -389,6 +389,27 @@ void test_graph_dijkstra(bool extra_tests) {
389389 graph_free (dijkstra_result );
390390}
391391
392+ void test_graph_kruskal () {
393+ puts ("== Graph kruskal test" );
394+ Graph * g = graph_create ();
395+ graph_add_edge_with_weight (g , 1 , 2 , 10 );
396+ graph_add_edge_with_weight (g , 1 , 3 , 20 );
397+ graph_add_edge_with_weight (g , 2 , 3 , 5 );
398+ graph_add_edge_with_weight (g , 3 , 4 , 30 );
399+ graph_add_edge_with_weight (g , 4 , 1 , 9 );
400+ graph_add_edge_with_weight (g , 5 , 1 , 7 );
401+
402+ printf (":: input graph\n" );
403+ graph_print (g );
404+
405+ printf (":: kruskal tree\n" );
406+ Graph * g_kruskal = graph_kruskal (g );
407+ graph_print (g_kruskal );
408+
409+ graph_free (g );
410+ graph_free (g_kruskal );
411+ }
412+
392413
393414bool should_run_extra_tests (int argc , char * argv []) {
394415 // Iterate through the command-line arguments starting from argv[1]
@@ -413,6 +434,7 @@ int main(int argc, char *argv[]) {
413434 test_graph_topological_sort ();
414435 test_graph_dijkstra (extra_tests );
415436 test_graph_edges_ordered ();
437+ test_graph_kruskal ();
416438 if (should_run_extra_tests (argc , argv )) {
417439 test_graph_export ();
418440 }
0 commit comments