ModuleBuildBioperl -> Bio::Root::Build
[bioperl-network.git] / t / Graph-MD5.t
blob5cd69edfb7fdf5170cb016f2346032d81058605e
1 # This is -*-Perl-*- code#
2 # Bioperl Test Harness Script for Modules#
3 # $Id$
5 use vars qw($NUMTESTS $DEBUG $ERROR);
6 use strict;
7 $DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
9 BEGIN {
10         # to handle systems with no installed Test module
11         # we include the t dir (where a copy of Test.pm is located)
12         # as a fallback
13         eval { require Test; };
14         $ERROR = 0;
15         if ( $@ ) {
16                 use lib 't';
17         }
18         use Test;
19         $NUMTESTS  = 20;
20         plan tests => $NUMTESTS;
21         eval { require Graph::Undirected; };
22         if ( $@ ) {
23                 warn("Graph required by the bioperl-network package, skipping tests");
24                 $ERROR = 1;
25         }
26         eval { require Digest::MD5; };
27         if ( $@ ) {
28                 warn("Digest::MD5 required for these tests, skipping tests");
29                 $ERROR = 1;
30         }
33 END {
34         foreach ( $Test::ntest..$NUMTESTS) {
35                 skip("Missing dependencies. Skipping tests",1);
36         }
38 exit 0 if $ERROR == 1;
41 # The purpose of these tests is to check to see if bugs have been 
42 # fixed in Perl's Graph, particularly refvertexed bugs
44 my $g = Graph::Undirected->new(refvertexed => 1);
46 ok 1;
48 my $seq1 = Digest::MD5->new;
49 my $seq2 = Digest::MD5->new;
50 my $seq3 = Digest::MD5->new;
51 my $seq4 = Digest::MD5->new;
53 my $str = "ljfgouyouiyougs";
55 $g->add_vertices($seq1,$seq2,$seq3,$seq4);
56 $g->add_edges([$seq1,$seq2],[$seq3,$seq4],[$seq3,$seq2]);
58 my @vs = $g->vertices; # OK
59 ok $vs[0]->add($str);
61 my $c = $g->complete; # OK
62 @vs = $c->vertices;
63 ok $vs[0]->add($str);
65 my $comp = $g->complement; # OK
66 @vs = $comp->vertices;
67 ok $vs[0]->add($str);
69 @vs = $g->interior_vertices; # OK
70 ok $vs[0]->add($str);
72 my $apsp = $g->APSP_Floyd_Warshall;
73 @vs = $apsp->path_vertices($seq1,$seq4); # OK
74 ok $vs[0]->add($str);
76 my $seq = $g->random_vertex; # OK
77 ok $seq->add($str);
79 my $t = Graph::Traversal::DFS->new($g);
80 $t->dfs;
81 @vs = $t->seen;
82 ok scalar @vs, 4;
83 for my $seq (@vs) {
84         ok $seq->add($str); # NOT OK in version .73
87 @vs = $g->articulation_points; 
88 ok scalar @vs, 2;
89 ok $vs[0]->add($str); # OK in version .70
90 ok $vs[1]->add($str);
92 my @cc = $g->connected_components;
93 for my $ref (@cc) {
94         for my $seq (@$ref) {
95                 ok $seq->add($str); # OK in version .70
96         }
99 my @bs = $g->bridges;
100 ok $bs[0][0]->add($str); # NOT OK in version .73
102 my $cg = $g->connected_graph;
103 @vs = $cg->vertices;
104 # ok $vs[0]->add($str); # is my usage correct?
106 my @spd = $g->SP_Dijkstra($seq1,$seq4); # OK in version .70
108 my @spbf = $g->SP_Bellman_Ford($seq1,$seq4); # OK in version .70
110 __END__