Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / t / PopGen / Coalescent.t
blob94aacce0d84b754cba746c2968051c0da4524da2
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7     use lib '.';
8         use Bio::Root::Test;
9         
10         test_begin(-tests => 13);
11         
12         use_ok('Bio::PopGen::Simulation::Coalescent');
13         use_ok('Bio::PopGen::Statistics');
14         use_ok('Bio::TreeIO');
17 my $ssize = 5;
18 my $sim = Bio::PopGen::Simulation::Coalescent->new(-sample_size => $ssize);
19 my $stats = Bio::PopGen::Statistics->new();
20 my $tree = $sim->next_tree;
22 is($tree->get_nodes, ($ssize * 2 - 1));
24 my $FILE1 = test_output_file();
25 my $treeio = Bio::TreeIO->new(-format => 'newick', -file => ">$FILE1");
27 $treeio->write_tree($tree);
28 undef $treeio;
30 ok(-s $FILE1);
31 my $mutcount = 100;
32 $sim->add_Mutations($tree, $mutcount);
34 my $leaves = [$tree->get_leaf_nodes];
35 # $stats->verbose(1);
36 my $pi = $stats->pi($leaves);
37 is( $pi > 0 , 1, 'pi');
40 # theta is num seg sites / sum(1/(numsams-1))
41 my $theta = $stats->theta(scalar @$leaves, $mutcount);
42 is($theta,48, 'theta');
44 my $tD = Bio::PopGen::Statistics->tajima_D($leaves);
45 is(defined $tD,1, 'tajimaD');
47 my $seg_sites = Bio::PopGen::Statistics->segregating_sites_count($leaves);
48 is($seg_sites,$mutcount,
49    'all the mutations should be polymorphic (by definition)');
50 my $single = Bio::PopGen::Statistics->singleton_count($leaves);
51 my $flD = Bio::PopGen::Statistics->fu_and_li_D($leaves,$single);
52 is(defined $flD,1,'fu and li D');
54 my $flD_star = $stats->fu_and_li_D_star($leaves);
55 is(defined $flD_star,1,'fu and li D*');
57 my $flF = $stats->fu_and_li_F($leaves,$single);
58 is(defined $flF, 1,'fu and li F');
60 my $flFstar = $stats->fu_and_li_F_star($leaves);
61 is(defined $flF, 1,'fu and li F');