moved nonpb.pm
[PsN.git] / test / lib / data_test.pm
blobfc2f6ea0d6b5e1cd065821b177f12fc322c00de3
1 #!/usr/bin/perl
3 package data_test;
5 #use FindBin qw($Bin);
6 #use lib "$Bin/../lib";
7 use data;
8 use Cwd;
9 use strict;
11 sub test {
13 my $self = shift;
14 my %parms = @_;
15 my $verbose = $parms{'verbose'};
16 my $directory = $parms{'directory'};
18 my ($tests_passed, $tests_performed) = (0,0);
20 my $data = data -> new( filename => 'data_set_1.dta',
21 directory => $directory.'/files/data_test_dir',
22 idcolumn => 3 );
25 print "\tdata: testing directory member\t\t\t... " if $verbose;
27 my $correct_value = $directory . 'files/data_test_dir/';
28 my $real_value = $data -> directory;
29 if( $correct_value eq $real_value ){
30 print " OK \n" if $verbose;
31 $tests_passed ++;
32 } else {
33 print "FAILED: \n\t$correct_value not equal $real_value\n" if $verbose;
35 $tests_performed ++;
39 print "\tdata: testing full_name\t\t\t\t... " if $verbose;
41 my $correct_value = $directory . 'files/data_test_dir/data_set_1.dta';
42 my $real_value = $data -> full_name;
43 if( $correct_value eq $real_value ){
44 print " OK \n" if $verbose;
45 $tests_passed ++;
46 } else {
47 print "FAILED: $correct_value not equal $real_value\n" if $verbose;
49 $tests_performed ++;
52 print "\tdata: testing bootstrap:ing of data\t\t... " if $verbose;
54 srand(1);
55 my ( $new_datas, $incl_ids, $incl_keys )
56 = $data -> bootstrap( directory => $directory ,
57 name_stub => 'files/data_test_dir/bs_pr' ,
58 samples => 5,
59 target => 'mem');
60 my $failed = 0;
61 foreach my $data ( @{$new_datas} ){
62 unless( ref $data eq 'data' ){
63 print "FAILED: bootstrap doesn't return data objects\n" if $verbose;
64 $failed = 1;
65 last;
68 $tests_passed ++ unless( $failed );
69 $tests_performed ++;
71 last if ( $failed );
73 # {{{ correct_value
74 my $correct_value = [[0,0,3.5,0,17.0,25.0,0,3.0,0,3.0,0,0,3.0,0,20.0,3.2,4.0,11.0,4.0,27.0,0,0,3.5,0,25.0,2.5,17.0,6.0,0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.5,0,0,3.4,2.5,0,0,3.4,0,26.0,3.5,0,0,3.0,0,0,0,2.8,0,7.5,7.5,4.0,22.0,17.5,0,6.0,0,0,0,0,0,35.0,19.0,3.4,0,3.5,0,0,3.2,2.5,3.5,7.5,6.0,3.0,17.5,0,0,2.5,6.0,0,0,0,4.5,2.5,9.5,0,25.0,60.0,35.0,17.0,15.0,0,0,0,6.0,3.0,22.0,0,18.0,7.5,0,3.0,4.5,18.6,1.5,10.0,1.7,4.0,2.4,14.0,0,2.0,4.0,0,0,3.5,28.0,4.0,7.5,3.0,3.0,0,0,7.5,0,0,26.0,0,0,9.0,4.0,0,0,7.5,2.4,70.0,0,0,0,10.0,3.5,0,30.0,3.7,0,0,3.5,9.5,4.0,0,0,7.5,0,9.5,0,0,2.5,0,0,19.0,2.8,70.0,0,6.0,0,2.4,3.5,0,3.0,14.0,20.0,0,3.3,0,0,0,4.0,0,4.0,0,0,1.5,14.0,9.5,0,24.0,9.0,0,2.5,20.0,0,2.0,7.5,0,0,3.0,0,0,25.0,0,6.0,0,3.0,0,0,0,34.0,0,0,24.0,0,0,2.5,9.0,20.0,3.5,0,0,0,0,0,0,0,0,2.8,9.0,0,4.0,0,70.0,11.0,0,0,0,18.0,7.5,0,0,0,27.0,2.8,2.5,0,0,6.0,0,0,3.5,28.0,0,0,2.5,0,17.0,20.0,0,1.5,3.0,0,0,3.0,1.7,0,2.5,0,4.5,2.5,0,0,0,0,3.4,3.4,0,0,0,0,25.0,0,0,3.0,4.4,3.5,0,34.0,27.0,0,4.0,0,0,3.0,2.5,0,0,4.4,6.0,0,15.0,2.5,0,0,26.0,0,0,0,1.7,0,0,0,1.7,4.4,0,20.0,27.0,0,0,0,0,3.0,1.7,4.3,17.5,7.5,0,0,5.0,22.8,2.0,12.0,0,3.0,10.0,5.0,27.0,],];
75 # }}}
77 $failed = 0;
78 # print "[";
79 OUTER: for(my $i = 0; $i <= $#{$incl_ids}; $i++ ){
80 my $ids_inner = $incl_ids -> [$i];
81 # print "[";
82 for(my $j = 0; $j <= $#{$ids_inner};$j++){
83 # print $ids_inner -> [$j] , ",";
84 if( $ids_inner -> [$j] != $correct_value -> [$i] -> [$j] ){
85 print $ids_inner -> [$j], " ", $correct_value -> [$i] -> [$j] , "\n";
86 print "FAILED: bootstrap doesn't include the correct IDs\n" if $verbose;
87 $failed = 1;
88 last OUTER;
91 # print "],";
93 # print "]";
95 $tests_passed ++ unless( $failed );
96 $tests_performed ++;
98 last if ( $failed );
100 print " OK \n";
101 #print "\n", @{@{$incl_ids}[0]}, "\n", @{$incl_keys}, "\n";
104 # resample
106 # case_deletion
108 # copy
110 # count_ind
112 # fractions
114 # factors
116 # find_individual
118 # format_data
120 # have_missing_data
122 # merge
124 # max
126 # min
128 # median
130 # mean
132 # sd
134 # range
136 # recalc_column
138 # renumber_ascending
140 # renumber_descending
142 # subsets
144 # subset
146 # _write
148 # flush
150 # synchronize
152 # _fisher_yates_shuffle
154 # _read_first_individual
156 # _read_header
158 # _read_individual
160 return ( $tests_passed, $tests_performed );