/[wait]/trunk/t/disjoint.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/disjoint.t

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

revision 88 by dpavlin, Mon May 24 13:44:01 2004 UTC revision 113 by dpavlin, Tue Jul 13 20:28:45 2004 UTC
# Line 1  Line 1 
1  #                              -*- Mode: Perl -*-  #!/usr/bin/perl -w
 # scan.t --  
 # ITIID           : $ITI$ $Header $__Header$  
 # Author          : Ulrich Pfeifer  
 # Created On      : Thu Aug  8 12:14:23 1996  
 # Last Modified By: Ulrich Pfeifer  
 # Last Modified On: Sun Nov 22 18:44:33 1998  
 # Language        : CPerl  
 # Update Count    : 128  
 # Status          : Unknown, Use with caution!  
 #  
 # Copyright (c) 1996-1997, Ulrich Pfeifer  
 #  
   
 ######################### We start with some black magic to print on failure.  
   
 BEGIN { $| = 1; print "1..32\n"; }  
 END {print "not ok 1\n" unless $loaded;  
      system 'rm -rf test' if -d 'test';  
 }  
 #use diagnostics;  
 use WAIT::Database;  
 $loaded = 1;  
 print "ok 1\n";  
   
 ######################### End of black magic.  
   
 $test = 2;  
   
 $db = create WAIT::Database name => 'test';  
 print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++;  
2    
3  $tb = create_table $db name => 'sample', attr => ['docid', 'term'],  use strict;
   djk => ['docid'];  
4    
5  print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++;  use Test::More;
6    use File::Path qw(rmtree);
7    use blib;
8    
9  $etid = 1;  BEGIN { use_ok('WAIT::Database'); }
10    
11    plan tests => 31;
12    
13    if (-e './test') {
14            warn "test directory exists, removing!\n";
15            rmtree('./test',0,1);
16    }
17    
18    ok(my $db = WAIT::Database->create(name => 'test'), "create");
19    
20    ok(my $tb = $db->create_table(name => 'sample', attr => ['docid', 'term'],
21      djk => ['docid']), "create_table");
22    
23    my $etid = 1;
24    my @db;
25  while (<DATA>) {  while (<DATA>) {
26    chomp;    chomp;
27    my($weight, $did, $term) = split;    my($weight, $did, $term) = split;
28    $tid = $tb->insert($weight, docid => $did, term => $term);    my $tid = $tb->insert($weight, docid => $did, term => $term);
29    push @db, [$did, $term, $weight];    push @db, [$did, $term, $weight];
30    print (($tid == $etid++)? "ok $test\n" : "not ok $test\n"); $test++;    cmp_ok ($tid, '==', $etid++, "insert $etid");
31  }  }
32    
33  $sc = $tb->open_scan();  ok(my $sc = $tb->open_scan(), "open_scan");
 print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++;  
34    
35  $tid = 0;  my $tid = 0;
36  while (%tp = $sc->next()) {  while (my %tp = $sc->next()) {
37    printf "%s", (($tp{docid} == $db[$tid]->[0]    ok (
38            and $tp{term} eq $db[$tid]->[1])?          ($tp{docid} == $db[$tid]->[0] and $tp{term} eq $db[$tid]->[1]),
39           "ok $test\n" : "not ok $test\n"); $test++;          "next ".$tid++);
   $tid++;  
40  }  }
41    
42  $sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'});  ok($sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'}),"open_scan IR");
 print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++;  
43    
44  $tid=0;  $tid=0;
45  @ndb = @db[1,4];  my @ndb = @db[1,4];
46  while (%tp = $sc->next()) {  while (my %tp = $sc->next()) {
47    printf "%s",  (($tp{docid} == $ndb[$tid]->[0]    ok(($tp{docid} == $ndb[$tid]->[0] and $tp{term} eq $ndb[$tid]->[1]), "next ".$tid++);
           and $tp{term} eq $ndb[$tid]->[1])?  
          "ok $test\n" : "not ok $test\n"); $test++;  
   $tid++;  
48  }  }
49    
50  $sc = $tb->open_index_scan(['docid', 'term']);  ok($sc = $tb->open_index_scan(['docid', 'term']), "open_index_scan");
 print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++;  
51    
52  $etid = 1;  $etid = 1;
53  while (%tp = $sc->next()) {  while (my %tp = $sc->next()) {
54    print (($tp{_id} == $etid++)?"ok $test\n" : "not ok $test\n"); $test++;    ok(($tp{_id} == $etid), "next ".$etid++);
55  }  }
56    
57  $sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'});  ok($sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'}),
58  print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++;          "open_index_scan IR");
59    
60  @ndb = (1,4);  @ndb = (1,4);
61  while (%tp = $sc->next()) {  while (my %tp = $sc->next()) {
62    print (($tp{_id} == shift(@ndb)+1)?"ok $test\n" : "not ok $test\n"); $test++;    ok(($tp{_id} == shift(@ndb)+1), "next");
63  }  }
64    
65  $status = $tb->close;  ok($tb->close, "close");
 print (($status)? "ok $test\n" : "not ok $test\n"); $test++;  
66    
67  # must have destroyed all handles here !  # must have destroyed all handles here !
68  # clean up  # clean up
69  $status = $db->dispose;  ok($db->dispose, "dispose");
70  print (($status)? "ok $test\n" : "not ok $test\n"); $test++;  ok((!defined $db), "undef");
 print ((!defined $db)? "ok $test\n" : "not ok $test\n"); $test++;  
71    
72  __END__  __END__
73  0.1 1 DB  0.1 1 DB

Legend:
Removed from v.88  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.26