int main() { const char *files[] = { "fullmatrix1.dl", "fullmatrix2.dl", "fullmatrix3.dl", "fullmatrix4.dl", "edgelist1.dl", "edgelist2.dl", "edgelist3.dl", "edgelist4.dl", "edgelist5.dl", "edgelist6.dl", "nodelist1.dl", "nodelist2.dl" }; int no_files=sizeof(files)/sizeof(const char*); int i, ret; igraph_t g; FILE *infile; for (i=0; i<no_files; i++) { printf("Doing %s\n", files[i]); infile=fopen(files[i], "r"); if (!infile) { printf("Cannot open file: %s\n", files[i]); exit(1+i); } igraph_read_graph_dl(&g, infile, /*directed=*/ 1); ret=fclose(infile); if (ret) { printf("Cannot close file: %s\n", files[i]); exit(11+i); } igraph_write_graph_edgelist(&g, stdout); igraph_destroy(&g); } if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 1; return 0; }
int main() { igraph_i_set_attribute_table(&igraph_cattribute_table); if (test_graph_from_leda_tutorial()) return 1; if (!IGRAPH_FINALLY_STACK_EMPTY) { printf("Finally stack still has %d elements.\n", IGRAPH_FINALLY_STACK_SIZE()); return 4; } return 0; }
int main() { igraph_t g; igraph_matrix_t mat; int m[4][4] = { { 0, 1, 2, 0 }, { 2, 0, 0, 1 }, { 0, 0, 1, 0 }, { 0, 1, 0, 0 } }; long int i, j; igraph_matrix_init(&mat, 4, 4); for (i=0; i<4; i++) for (j=0; j<4; j++) MATRIX(mat, i, j) = m[i][j]; igraph_i_set_attribute_table(&igraph_cattribute_table); /* [ 0 1 2 0 ] [ 2 0 0 1 ] [ 0 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_DIRECTED, 0); print(&g); igraph_destroy(&g); /* [ 0 1 2 0 ] [ - 0 0 1 ] [ - - 1 0 ] [ - - - 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_UPPER, 0); print(&g); igraph_destroy(&g); /* [ 0 - - - ] [ 2 0 - - ] [ 0 0 1 - ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_LOWER, 0); print(&g); igraph_destroy(&g); /* [ 0 1 0 0 ] [ 1 0 0 1 ] [ 0 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MIN, 0); print(&g); igraph_destroy(&g); /* [ 0 2 2 0 ] [ 2 0 0 1 ] [ 2 0 1 0 ] [ 0 1 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_MAX, 0); print(&g); igraph_destroy(&g); /* [ 0 3 2 0 ] [ 3 0 0 2 ] [ 2 0 1 0 ] [ 0 2 0 0 ] */ igraph_weighted_adjacency(&g, &mat, IGRAPH_ADJ_PLUS, 0); print(&g); igraph_destroy(&g); igraph_matrix_destroy(&mat); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 1; return 0; }
int main() { igraph_t g; igraph_vector_t bet, bet2, weights, edges; igraph_vector_t bbet, bbet2; igraph_real_t nontriv[] = { 0, 19, 0, 16, 0, 20, 1, 19, 2, 5, 3, 7, 3, 8, 4, 15, 4, 11, 5, 8, 5, 19, 6, 7, 6, 10, 6, 8, 6, 9, 7, 20, 9, 10, 9, 20, 10, 19, 11, 12, 11, 20, 12, 15, 13, 15, 14, 18, 14, 16, 14, 17, 15, 16, 17, 18 }; igraph_real_t nontriv_weights[] = { 0.5249, 1, 0.1934, 0.6274, 0.5249, 0.0029, 0.3831, 0.05, 0.6274, 0.3831, 0.5249, 0.0587, 0.0579, 0.0562, 0.0562, 0.1934, 0.6274, 0.6274, 0.6274, 0.0418, 0.6274, 0.3511, 0.3511, 0.1486, 1, 1, 0.0711, 0.2409 }; igraph_real_t nontriv_res[] = { 20, 0, 0, 0, 0, 19, 80, 85, 32, 0, 10, 75, 70, 0, 36, 81, 60, 0, 19, 19, 86 }; /*******************************************************/ igraph_barabasi_game(/* graph= */ &g, /* n= */ 1000, /* power= */ 1, /* m= */ 3, /* outseq= */ 0, /* outpref= */ 0, /* A= */ 1, /* directed= */ 0, /* algo= */ IGRAPH_BARABASI_BAG, /* start_from= */ 0); igraph_simplify(&g, /* multiple= */ 1, /* loops= */ 1, /*edge_comb=*/ 0); igraph_vector_init(&bet, 0); igraph_vector_init(&bbet, 0); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bet, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 2, /* weights= */ 0, /* nobigint= */ 1); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bbet, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 2, /* weights= */ 0, /* nobigint= */ 0); check(&bet, &bbet, 10); igraph_vector_destroy(&bet); igraph_vector_destroy(&bbet); igraph_destroy(&g); /*******************************************************/ igraph_tree(&g, 20000, 10, IGRAPH_TREE_UNDIRECTED); igraph_vector_init(&bet, 0); igraph_vector_init(&bbet, 0); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bet, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 3, /* weights= */ 0, /* nobigint= */ 1); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bbet, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 3, /* weights= */ 0, /* nobigint= */ 0); check(&bet, &bbet, 20); igraph_vector_init(&bet2, 0); igraph_vector_init(&bbet2, 0); igraph_vector_init(&weights, igraph_ecount(&g)); igraph_vector_fill(&weights, 1.0); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bet2, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 3, /* weights= */ &weights, /* nobigint= */ 1); igraph_betweenness_estimate(/* graph= */ &g, /* res= */ &bbet2, /* vids= */ igraph_vss_all(), /* directed = */ 0, /* cutoff= */ 3, /* weights= */ &weights, /* nobigint= */ 0); if (!igraph_vector_all_e(&bet, &bet2)) { return 1; } /* if (!igraph_vector_all_e(&bbet, &bbet2)) { */ /* return 2; */ /* } */ check(&bet, &bbet, 30); check(&bet2, &bbet2, 40); igraph_vector_destroy(&bet); igraph_vector_destroy(&bet2); igraph_vector_destroy(&bbet); igraph_vector_destroy(&bbet2); igraph_vector_destroy(&weights); igraph_destroy(&g); /* Non-trivial weighted graph */ igraph_vector_view(&edges, nontriv, sizeof(nontriv)/sizeof(igraph_real_t)); igraph_create(&g, &edges, 0, /* directed= */ 0); igraph_vector_view(&weights, nontriv_weights, sizeof(nontriv_weights)/sizeof(igraph_real_t)); igraph_vector_init(&bet, 0); igraph_vector_init(&bbet, 0); igraph_betweenness(/*graph=*/ &g, /*res=*/ &bet, /*vids=*/ igraph_vss_all(), /*directed=*/0, /*weights=*/ &weights, /*nobigint=*/ 1); igraph_betweenness(/*graph=*/ &g, /*res=*/ &bbet, /*vids=*/ igraph_vss_all(), /*directed=*/0, /*weights=*/ &weights, /*nobigint=*/ 0); igraph_vector_view(&bet2, nontriv_res, sizeof(nontriv_res)/sizeof(igraph_real_t)); if (!igraph_vector_all_e(&bet, &bet2)) { return 2; } check(&bet, &bbet, 50); igraph_vector_destroy(&bet); igraph_vector_destroy(&bbet); igraph_destroy(&g); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 3; return 0; }
int main() { igraph_vector_ptr_t v1, v2; igraph_vector_ptr_t v3=IGRAPH_VECTOR_PTR_NULL; int i; void ** ptr; int d1=1, d2=2, d3=3, d4=4, d5=5; char *block1=0, *block2=0; /* igraph_vector_ptr_init, igraph_vector_ptr_destroy */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_destroy(&v1); igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_free_all, igraph_vector_ptr_destroy_all */ igraph_vector_ptr_init(&v1, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_free_all(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_reserve */ igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_reserve(&v1, 5); igraph_vector_ptr_reserve(&v1, 15); igraph_vector_ptr_reserve(&v1, 1); igraph_vector_ptr_reserve(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_empty, igraph_vector_ptr_clear */ igraph_vector_ptr_init(&v1, 10); if (igraph_vector_ptr_empty(&v1)) { return 1; } igraph_vector_ptr_clear(&v1); if (!igraph_vector_ptr_empty(&v1)) { return 2; } /* igraph_vector_ptr_size */ if (igraph_vector_ptr_size(&v1) != 0) { return 3; } igraph_vector_ptr_resize(&v1, 10); if (igraph_vector_ptr_size(&v1) != 10) { return 4; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_push_back */ igraph_vector_ptr_init(&v1, 0); for (i=0; i<10; i++) { igraph_vector_ptr_push_back(&v1, (void*)malloc(i*10)); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_e */ igraph_vector_ptr_init(&v1, 5); VECTOR(v1)[0]=&d1; VECTOR(v1)[1]=&d2; VECTOR(v1)[2]=&d3; VECTOR(v1)[3]=&d4; VECTOR(v1)[4]=&d5; if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_set */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_null */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_null(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if (VECTOR(v1)[i] != 0) { return 10; } } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_resize */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_resize(&v1, 10); igraph_vector_ptr_resize(&v1, 15); igraph_vector_ptr_resize(&v1, 5); if (igraph_vector_ptr_size(&v1) != 5) { return 11; } if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 12; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 13; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 14; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 15; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 16; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_view */ ptr=(void**) malloc(5 * sizeof(void*)); igraph_vector_ptr_view(&v3, ptr, 5); ptr[0]=&d1; ptr[1]=&d2; ptr[2]=&d3; ptr[3]=&d4; ptr[4]=&d5; for (i=0; i<igraph_vector_ptr_size(&v3); i++) { if ( *((int*)VECTOR(v3)[i]) != i+1) { return 17; } } /* igraph_vector_ptr_init_copy */ igraph_vector_ptr_init_copy(&v1, ptr, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)VECTOR(v1)[i]) != i+1) { return 18; } } /* igraph_vector_ptr_copy_to */ igraph_vector_ptr_copy_to(&v1, ptr); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)ptr[i]) != i+1) { return 19; } } free(ptr); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_copy */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_copy(&v2, &v1); igraph_vector_ptr_destroy(&v1); for (i=0; i<igraph_vector_ptr_size(&v2); i++) { if ( *((int*)VECTOR(v2)[i]) != i+1) { return 20; } } /* igraph_vector_ptr_remove */ igraph_vector_ptr_remove(&v2, 0); igraph_vector_ptr_remove(&v2, 3); if ( *((int*)VECTOR(v2)[0]) != 2) { return 21; } if ( *((int*)VECTOR(v2)[1]) != 3) { return 22; } if ( *((int*)VECTOR(v2)[2]) != 4) { return 23; } igraph_vector_ptr_destroy(&v2); /* Testing destructor */ igraph_vector_ptr_init(&custom_destructor_stack, 0); igraph_vector_ptr_init(&v1, 2); block1 = igraph_Calloc(32, char); block2 = igraph_Calloc(64, char); VECTOR(v1)[0] = block1; VECTOR(v1)[1] = block2; if (igraph_vector_ptr_get_item_destructor(&v1) != 0) { return 24; } if (igraph_vector_ptr_set_item_destructor(&v1, &custom_destructor) != 0) { return 25; } /* Okay, let's clear the vector. This should push the blocks in the * custom destructor stack */ igraph_vector_ptr_clear(&v1); /* Put the blocks back and destroy the vector */ igraph_vector_ptr_push_back(&v1, block1); igraph_vector_ptr_push_back(&v1, block2); igraph_vector_ptr_destroy_all(&v1); if (VECTOR(custom_destructor_stack)[0] != block1 || VECTOR(custom_destructor_stack)[1] != block2 || VECTOR(custom_destructor_stack)[2] != block1 || VECTOR(custom_destructor_stack)[3] != block2 ) return 26; igraph_vector_ptr_destroy(&custom_destructor_stack); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 27; return 0; }
int main() { igraph_matrix_t m, m2; igraph_vector_t v; long int i, j, i2, j2; igraph_real_t r1, r2; igraph_matrix_init(&m, 4, 3); byrow(&m); /* igraph_matrix_e */ printf("igraph_matrix_e\n"); apply(m, printf("%i ", (int)igraph_matrix_e(&m, i, j)), printf("\n")); /* igraph_matrix_e_ptr */ printf("igraph_matrix_e_ptr\n"); apply(m, printf("%i ", (int)igraph_matrix_e_ptr(&m, i, j)[0]), printf("\n")); /* igraph_matrix_set */ printf("igraph_matrix_set\n"); apply(m, igraph_matrix_set(&m, i, j, i), (void) 0 ); print_matrix(&m); apply(m, igraph_matrix_set(&m, i, j, j), (void) 0 ); print_matrix(&m); /* igraph_matrix_fill */ printf("igraph_matrix_fill\n"); igraph_matrix_fill(&m, 42); print_matrix(&m); igraph_matrix_fill(&m, -42.1); print_matrix(&m); /* igraph_matrix_update */ printf("igraph_matrix_update\n"); igraph_matrix_init(&m2, 0, 0); byrow(&m); igraph_matrix_update(&m2, &m); print_matrix(&m2); /* igraph_matrix_rbind */ printf("igraph_matrix_rbind\n"); igraph_matrix_rbind(&m2, &m); print_matrix(&m2); printf("\n"); igraph_matrix_resize(&m, 0, igraph_matrix_ncol(&m2)); igraph_matrix_rbind(&m2, &m); print_matrix(&m2); printf("\n"); igraph_matrix_rbind(&m, &m2); print_matrix(&m); /* igraph_matrix_cbind */ printf("igraph_matrix_cbind\n"); igraph_matrix_resize(&m, 4, 3); igraph_matrix_resize(&m2, 4, 2); byrow(&m); byrow(&m2); igraph_matrix_cbind(&m, &m2); print_matrix(&m); /* igraph_matrix_swap */ printf("igraph_matrix_swap\n"); igraph_matrix_update(&m, &m2); igraph_matrix_null(&m); igraph_matrix_swap(&m, &m2); print_matrix(&m); print_matrix(&m2); /* igraph_matrix_get_row */ /* igraph_matrix_set_row */ printf("igraph_matrix_get_row\n"); printf("igraph_matrix_set_row\n"); igraph_vector_init(&v, 0); for (i=0; i<igraph_matrix_nrow(&m); i++) { igraph_matrix_get_row(&m, &v, i); igraph_matrix_set_row(&m2, &v, i); } print_matrix(&m2); /* igraph_matrix_set_col */ printf("igraph_matrix_set_col\n"); igraph_matrix_null(&m2); for (i=0; i<igraph_matrix_ncol(&m); i++) { igraph_matrix_get_col(&m, &v, i); igraph_matrix_set_col(&m2, &v, i); } print_matrix(&m2); /* igraph_matrix_swap_rows */ printf("igraph_matrix_swap_rows\n"); igraph_matrix_swap_rows(&m2, 0, 0); igraph_matrix_swap_rows(&m2, 0, 2); print_matrix(&m2); /* igraph_matrix_swap_cols */ printf("igraph_matrix_swap_cols\n"); igraph_matrix_swap_cols(&m2, 0, 0); igraph_matrix_swap_cols(&m2, 0, 1); print_matrix(&m2); /* igraph_matrix_add_constant */ printf("igraph_matrix_add_constant\n"); igraph_matrix_add_constant(&m2, 0); print_matrix(&m2); igraph_matrix_add_constant(&m2, -1); print_matrix(&m2); /* igraph_matrix_add */ printf("igraph_matrix_add\n"); byrow(&m2); byrow(&m); igraph_matrix_add(&m2, &m); print_matrix(&m2); /* igraph_matrix_sub */ printf("igraph_matrix_sub\n"); igraph_matrix_sub(&m2, &m); print_matrix(&m2); /* igraph_matrix_mul_elements */ printf("igraph_matrix_mul_elements\n"); igraph_matrix_mul_elements(&m2, &m); print_matrix(&m2); /* igraph_matrix_div_elements */ printf("igraph_matrix_div_elements\n"); igraph_matrix_fill(&m, 2); igraph_matrix_div_elements(&m2, &m); print_matrix(&m2); /* igraph_matrix_min */ printf("igraph_matrix_min\n"); if (igraph_matrix_min(&m2) != 0) { return 1; } if (igraph_matrix_min(&m) != 2) { return 1; } /* igraph_matrix_which_min */ printf("igraph_matrix_which_min\n"); igraph_matrix_which_min(&m2, &i, &j); if (i != 0 || j != 0) { return 2; } MATRIX(m2,0,1) = -1; igraph_matrix_which_min(&m2, &i, &j); if (i != 0 || j != 1) { return 2; } MATRIX(m2,3,1) = -2; igraph_matrix_which_min(&m2, &i, &j); if (i != 3 || j != 1) { return 2; } /* igraph_matrix_which_max */ printf("igraph_matrix_which_max\n"); MATRIX(m2,3,0) = 100; igraph_matrix_which_max(&m2, &i, &j); if (i != 3 || j != 0) { return 3; } /* igraph_matrix_minmax */ printf("igraph_matrix_minmax\n"); igraph_matrix_minmax(&m2, &r1, &r2); printf("%g %g\n", r1, r2); /* igraph_matrix_which_minmax */ printf("igraph_matrix_which_minmax\n"); igraph_matrix_which_minmax(&m2, &i, &j, &i2, &j2); if (i != 3 || j != 1 || i2 != 3 || j2 != 0) { return 4; } /* igraph_matrix_isnull */ printf("igraph_matrix_isnull\n"); if (igraph_matrix_isnull(&m2)) { return 5; } igraph_matrix_null(&m); if (!igraph_matrix_isnull(&m)) { return 5; } igraph_matrix_resize(&m2, 5, 0); if (!igraph_matrix_isnull(&m2)) { return 5; } /* igraph_matrix_empty */ printf("igraph_matrix_empty\n"); if (!igraph_matrix_empty(&m2)) { return 6; } igraph_matrix_resize(&m2, 5, 5); if (igraph_matrix_empty(&m2)) { return 6; } /* igraph_matrix_is_symmetric */ printf("igraph_matrix_is_symmetric\n"); byrow(&m2); if (igraph_matrix_is_symmetric(&m2)) { return 7; } igraph_matrix_update(&m, &m2); igraph_matrix_transpose(&m); igraph_matrix_add(&m, &m2); if (!igraph_matrix_is_symmetric(&m)) { return 7; } /* igraph_matrix_prod */ printf("igraph_matrix_prod\n"); igraph_matrix_resize(&m, 3,2); byrow(&m); igraph_matrix_add_constant(&m, 1); print_matrix(&m); printf("product: %g\n", igraph_matrix_prod(&m)); /* igraph_matrix_rowsum */ printf("igraph_matrix_rowsum\n"); igraph_matrix_rowsum(&m, &v); print_vector(&v); /* igraph_matrix_colsum */ printf("igraph_matrix_colsum\n"); igraph_matrix_colsum(&m, &v); print_vector(&v); /* igraph_matrix_contains */ printf("igraph_matrix_contains\n"); if (igraph_matrix_contains(&m, 0)) { return 8; } if (igraph_matrix_contains(&m, 6.0001)) { return 8; } if (igraph_matrix_contains(&m, 7)) { return 8; } if (!igraph_matrix_contains(&m, 1)) { return 8; } if (!igraph_matrix_contains(&m, 6)) { return 8; } /* igraph_matrix_search */ printf("igraph_matrix_search\n"); if (!igraph_matrix_search(&m, 0, 6.0, &i2, &i, &j)) { return 9; } if (i2 != 5 || i != 2 || j != 1) { return 9; } /* igraph_matrix_remove_row */ printf("igraph_matrix_remove_row\n"); igraph_matrix_remove_row(&m, 1); print_matrix(&m); igraph_matrix_resize(&m,5,4); byrow(&m); igraph_matrix_remove_row(&m, 4); print_matrix(&m); igraph_matrix_remove_row(&m, 0); print_matrix(&m); /* igraph_matrix_select_cols */ printf("igraph_matrix_select_cols\n"); igraph_matrix_resize(&m, 6, 5); apply(m, igraph_matrix_set(&m, i, j, j), (void) 0 ); igraph_vector_resize(&v, 3); VECTOR(v)[0]=0; VECTOR(v)[1]=4; VECTOR(v)[2]=2; igraph_matrix_select_cols(&m, &m2, &v); print_matrix(&m2); igraph_vector_resize(&v, 1); igraph_matrix_select_cols(&m, &m2, &v); print_matrix(&m2); igraph_vector_clear(&v); igraph_matrix_select_cols(&m, &m2, &v); if (!igraph_matrix_empty(&m2)) { return 9; } igraph_vector_destroy(&v); igraph_matrix_destroy(&m2); igraph_matrix_destroy(&m); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 10; return 0; }
int main() { igraph_d_indheap_t h; int i; long int idx1, idx2; /* igraph_d_indheap_init, igraph_d_indheap_destroy */ igraph_d_indheap_init(&h, 0); igraph_d_indheap_destroy(&h); igraph_d_indheap_init(&h, 100); igraph_d_indheap_destroy(&h); /* igraph_d_indheap_empty, igraph_d_indheap_size */ igraph_d_indheap_init(&h, 10); if (!igraph_d_indheap_empty(&h)) { return 1; } if (igraph_d_indheap_size(&h) != 0) { return 2; } igraph_d_indheap_push(&h, 10, 0, 0); if (igraph_d_indheap_empty(&h)) { return 3; } if (igraph_d_indheap_size(&h) != 1) { return 4; } /* igraph_d_indheap_push */ igraph_d_indheap_push(&h, 9, 9, 8); igraph_d_indheap_push(&h, 3, 3, 2); igraph_d_indheap_push(&h, 2, 2, 1); igraph_d_indheap_push(&h, 1, 1, 0); igraph_d_indheap_push(&h, 7, 7, 6); igraph_d_indheap_push(&h, 4, 4, 3); igraph_d_indheap_push(&h, 0, 0, 1); igraph_d_indheap_push(&h, 6, 6, 5); igraph_d_indheap_push(&h, 5, 5, 4); igraph_d_indheap_push(&h, 8, 8, 7); /* igraph_d_indheap_max, igraph_d_indheap_delete_max */ while (!igraph_d_indheap_empty(&h)) { printf("% li", (long int)igraph_d_indheap_max(&h)); printf("% li\n", (long int)igraph_d_indheap_delete_max(&h)); } /* igraph_d_indheap_reserve */ igraph_d_indheap_reserve(&h, 5); igraph_d_indheap_reserve(&h, 20); igraph_d_indheap_reserve(&h, 0); igraph_d_indheap_reserve(&h, 3); /* igraph_d_indheap_max_index */ igraph_d_indheap_push(&h, 0, 0, 1); igraph_d_indheap_push(&h, 8, 8, 7); igraph_d_indheap_push(&h, 2, 2, 1); igraph_d_indheap_push(&h, 7, 7, 6); igraph_d_indheap_push(&h, 9, 9, 8); igraph_d_indheap_push(&h, 4, 4, 3); igraph_d_indheap_push(&h, 3, 3, 2); igraph_d_indheap_push(&h, 5, 5, 4); igraph_d_indheap_push(&h, 1, 1, 0); igraph_d_indheap_push(&h, 6, 6, 5); while (!igraph_d_indheap_empty(&h)) { igraph_d_indheap_max_index(&h, &idx1, &idx2); printf(" %li %li", idx1, idx2); igraph_d_indheap_delete_max(&h); } printf("\n"); igraph_d_indheap_destroy(&h); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 5; return 0; }
int main() { igraph_dqueue_t q; int i; /* igraph_dqueue_init, igraph_dqueue_destroy, igraph_dqueue_empty */ igraph_dqueue_init(&q, 5); if (!igraph_dqueue_empty(&q)) { return 1; } igraph_dqueue_destroy(&q); /* igraph_dqueue_push, igraph_dqueue_pop */ igraph_dqueue_init(&q, 4); igraph_dqueue_push(&q, 1); igraph_dqueue_push(&q, 2); igraph_dqueue_push(&q, 3); igraph_dqueue_push(&q, 4); if (igraph_dqueue_pop(&q) != 1) { return 2; } if (igraph_dqueue_pop(&q) != 2) { return 3; } if (igraph_dqueue_pop(&q) != 3) { return 4; } if (igraph_dqueue_pop(&q) != 4) { return 5; } igraph_dqueue_destroy(&q); /* igraph_dqueue_clear, igraph_dqueue_size */ igraph_dqueue_init(&q, 0); if (igraph_dqueue_size(&q) != 0) { return 6; } igraph_dqueue_clear(&q); if (igraph_dqueue_size(&q) != 0) { return 7; } for (i=0; i<10; i++) { igraph_dqueue_push(&q, i); } igraph_dqueue_clear(&q); if (igraph_dqueue_size(&q) != 0) { return 8; } igraph_dqueue_destroy(&q); /* TODO: igraph_dqueue_full */ /* igraph_dqueue_head, igraph_dqueue_back, igraph_dqueue_pop_back */ igraph_dqueue_init(&q, 0); for (i=0; i<10; i++) { igraph_dqueue_push(&q, i); } for (i=0; i<10; i++) { if (igraph_dqueue_head(&q) != 0) { return 9; } if (igraph_dqueue_back(&q) != 9-i) { return 10; } if (igraph_dqueue_pop_back(&q) != 9-i) { return 11; } } igraph_dqueue_destroy(&q); /* print */ igraph_dqueue_init(&q, 4); igraph_dqueue_push(&q, 1); igraph_dqueue_push(&q, 2); igraph_dqueue_push(&q, 3); igraph_dqueue_push(&q, 4); igraph_dqueue_pop(&q); igraph_dqueue_pop(&q); igraph_dqueue_push(&q, 5); igraph_dqueue_push(&q, 6); igraph_dqueue_print(&q); igraph_dqueue_clear(&q); igraph_dqueue_print(&q); igraph_dqueue_destroy(&q); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 12; return 0; }
int main() { igraph_stack_t st; int i; /* igraph_stack_init, igraph_stack_destroy */ igraph_stack_init(&st, 0); igraph_stack_destroy(&st); igraph_stack_init(&st, 10); igraph_stack_destroy(&st); /* igraph_stack_reserve */ igraph_stack_init(&st, 0); igraph_stack_reserve(&st, 10); igraph_stack_reserve(&st, 5); /* igraph_stack_empty */ if (!igraph_stack_empty(&st)) { return 1; } igraph_stack_push(&st, 1); if (igraph_stack_empty(&st)) { return 2; } /* igraph_stack_size */ if (igraph_stack_size(&st) != 1) { return 3; } for (i=0; i<10; i++) { igraph_stack_push(&st, i); } if (igraph_stack_size(&st) != 11) { return 4; } /* igraph_stack_clear */ igraph_stack_clear(&st); if (!igraph_stack_empty(&st)) { return 5; } igraph_stack_push(&st, 100); if (igraph_stack_pop(&st) != 100) { return 6; } igraph_stack_clear(&st); igraph_stack_clear(&st); /* igraph_stack_push, igraph_stack_pop */ for (i=0; i<100; i++) { igraph_stack_push(&st, 100-i); } for (i=0; i<100; i++) { if (igraph_stack_pop(&st) != i+1) { return 7; } } if (!igraph_stack_empty(&st)) { return 8; } igraph_stack_destroy(&st); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 9; return 0; }