Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 8dddad4a08f7c39782445e54a14af930 > files > 137

igraph-devel-0.5.2-5.fc12.i686.rpm

/* -*- mode: C -*-  */
/* 
   IGraph library.
   Copyright (C) 2006  Gabor Csardi <csardi@rmki.kfki.hu>
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
   02110-1301 USA

*/

#include <igraph.h>

int main() {

  igraph_t g;
  int i, ret;
  igraph_bool_t simple;
  
  /* G(n,p) */
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.0, 
			  IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
  if (igraph_ecount(&g) != 0) {
    return 1;
  }
  if (igraph_is_directed(&g)) {
    return 2;
  }
  igraph_destroy(&g);
  
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 1.0,
			  IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
  if (igraph_ecount(&g) != 10*9) {
    return 3;
  }
  if (!igraph_is_directed(&g)) {
    return 4;
  }
  igraph_destroy(&g);

  /* More useful tests */
/*   printf("directed with loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.9999999,
			    IGRAPH_DIRECTED, IGRAPH_LOOPS);
    if (igraph_vcount(&g) != 10) { return 5; }
    if (igraph_ecount(&g) != 10*10) { return 77; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*9) { return 77; }
    igraph_destroy(&g);
  }

/*   printf("directed without loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.9999999,
			    IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
    if (igraph_vcount(&g) != 10) { return 7; }
    if (igraph_ecount(&g) != 10*(10-1)) { return 77; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*9) { return 77; }
    igraph_destroy(&g);
  }
  
/*   printf("undirected with loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.9999999,
			    IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
    if (igraph_vcount(&g) != 10) { return 9; }
    if (igraph_ecount(&g) != 10*(10+1)/2) { return 77; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*(10-1)/2) { return 77; }
    igraph_destroy(&g);
  }

/*   printf("undirected without loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 10, 0.9999999,
			    IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
    if (igraph_vcount(&g) != 10) { return 11; }
    if (igraph_ecount(&g) != 10*(10-1)/2) { return 77; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*(10-1)/2) { return 77; }
    igraph_destroy(&g);
  }    

  /* Create a couple of large graphs too */
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0/100000,
			  IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 25; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0/100000,
			  IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 25; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0/100000,
			  IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 25; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100000, 2.0/100000,
			  IGRAPH_DIRECTED, IGRAPH_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 25; }
  igraph_destroy(&g);
  

  /* --------------------------------------------------------------------- */
  /* G(n,m) */
  
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 0.5,
			  IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
  igraph_destroy(&g);

  /* More useful tests */
/*   printf("directed with loops\n"); */
  for (i=0; i<100; i++) {
    long int ec;
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10*10-1,
			    IGRAPH_DIRECTED, IGRAPH_LOOPS);
    if (igraph_vcount(&g) != 10) { return 13; }
    if (igraph_ecount(&g) != 10*10-1) { return 14; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    igraph_is_simple(&g, &simple);
    if (!simple) { return 27; }
    ec=igraph_ecount(&g);
    if (ec != 10*9 && ec != 10*9-1) { return 15; }
    igraph_destroy(&g);
  }

/*   printf("directed without loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10*9-1,
			    IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
    igraph_is_simple(&g, &simple);
    if (!simple) { return 28; }
    if (igraph_vcount(&g) != 10) { return 16; }
    if (igraph_ecount(&g) != 10*(10-1)-1) { return 17; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*9-1) { return 18; }
    igraph_destroy(&g);
  }
  
/*   printf("undirected with loops\n"); */
  for (i=0; i<100; i++) {
    long int ec;
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10*11/2-1,
			    IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
    if (igraph_vcount(&g) != 10) { return 19; }
    if (igraph_ecount(&g) != 10*(10+1)/2-1) { return 20; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    igraph_is_simple(&g, &simple);
    if (!simple) { return 29; }
    ec=igraph_ecount(&g);
    if (ec != 10*(10-1)/2 && ec != 10*9/2-1) { return 21; }
    igraph_destroy(&g);
  }

/*   printf("undirected without loops\n"); */
  for (i=0; i<100; i++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 10, 10*9/2-1,
			    IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
    igraph_is_simple(&g, &simple);
    if (!simple) { return 30; }
    if (igraph_vcount(&g) != 10) { return 22; }
    if (igraph_ecount(&g) != 10*(10-1)/2-1) { return 23; }
    igraph_simplify(&g, /*multiple=*/0, /*loops=*/1);
    if (igraph_ecount(&g) != 10*(10-1)/2-1) { return 24; }
    igraph_destroy(&g);
  }  

  /* Create a couple of large graphs too */
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0*100000,
			  IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 26; }
  if (igraph_ecount(&g) != 200000) { return 26; }
  igraph_is_simple(&g, &simple);
  if (!simple) { return 31; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0*100000,
			  IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
  igraph_is_simple(&g, &simple);
  if (!simple) { return 32; }
  if (igraph_vcount(&g) != 100000) { return 26; }
  if (igraph_ecount(&g) != 200000) { return 26; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0*100000,
			  IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 26; }
  if (igraph_ecount(&g) != 200000) { return 26; }
  igraph_simplify(&g, 0, 1);	/* only remove loops */
  igraph_is_simple(&g, &simple);
  if (!simple) { return 33; }
  igraph_destroy(&g);
  igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, 100000, 2.0*100000,
			  IGRAPH_DIRECTED, IGRAPH_LOOPS);
  if (igraph_vcount(&g) != 100000) { return 26; }
  if (igraph_ecount(&g) != 200000) { return 26; }
  igraph_simplify(&g, 0, 1);	/* only remove loops */
  igraph_is_simple(&g, &simple);
  if (!simple) { return 34; }
  igraph_destroy(&g);

  return 0;
}