/[pgestraier]/trunk/t/pgest.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/pgest.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by dpavlin, Wed Jul 6 14:47:56 2005 UTC revision 32 by dpavlin, Wed Jul 6 15:15:04 2005 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 67;  use Test::More tests => 73;
6    
7  BEGIN {  BEGIN {
8          use_ok('DBI');          use_ok('DBI');
# Line 25  if ($pwd !~ m#^/#) { Line 25  if ($pwd !~ m#^/#) {
25  ok($pwd, "pwd: $pwd");  ok($pwd, "pwd: $pwd");
26  my $index = "$pwd/../data/casket/";  my $index = "$pwd/../data/casket/";
27    
28  my $sql = "select * from pgest('$index',?,?,?,?,?,?) as (id text)";  my $sql = "select id from pgest('$index',?,?,?,?,?,array['\@id']) as (id text)";
29  diag "$sql";  diag "$sql";
30    
31  my $sth = $dbh->prepare($sql) || die $dbh->errstr();  my $sth = $dbh->prepare($sql) || die $dbh->errstr();
32  ok($sth, "sth");  ok($sth, "sth");
33    
34  sub pgest {  sub pgest {
35          $sth->execute(@_, "{'\@id'}" ) || die $sth->errstr();          $sth->execute(@_) || die $sth->errstr();
36          {          {
37                  no warnings;                  no warnings;
38                  ok($sth, "execute(".join(",",@_).")");                  ok($sth, "execute(".join(",",@_).")");
39          }          }
40    
41          my @arr;          my @arr;
42          while (my $row = $sth->fetchrow_hashref() ) {          while (my ($id) = $sth->fetchrow_array() ) {
43                  push @arr, $row;                  push @arr, $id;
44          }          }
45          ok(@arr, "pgest results: ".($#arr + 1));          ok(@arr, "pgest results: ".($#arr + 1));
46    
# Line 113  cmp_ok($hits, '==', pgest('blade runner' Line 113  cmp_ok($hits, '==', pgest('blade runner'
113    
114  cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d");  cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d");
115  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
116    
117    # test sort
118    my @arr_asc = pgest('blade runner', undef, '@id NUMA', undef, undef);
119    my @arr_desc = pgest('blade runner', undef, '@id NUMD', undef, undef);
120    
121    cmp_ok(@arr_asc, '==', @arr_desc, "same number of results");
122    my $errors = 0;
123    foreach my $i (0 .. $#arr_asc) {
124            my ($a, $b) = ($arr_asc[$i], $arr_desc[$#arr_desc - $i]);
125            if ($a ne $b) {
126                    $errors++;
127                    diag "element $i: $a != $b";
128            }
129    }
130    
131    cmp_ok($errors, '==', 0, "errors in ordering");

Legend:
Removed from v.31  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26