/[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

Annotation of /trunk/t/disjoint.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (hide annotations)
Tue Jul 13 20:28:45 2004 UTC (19 years, 10 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1608 byte(s)
IndexScan implementation for BerkeleyDB (from original Ulrich's code)

1 dpavlin 113 #!/usr/bin/perl -w
2 ulpfr 10
3 dpavlin 113 use strict;
4 ulpfr 10
5 dpavlin 113 use Test::More;
6     use File::Path qw(rmtree);
7     use blib;
8 ulpfr 10
9 dpavlin 113 BEGIN { use_ok('WAIT::Database'); }
10 ulpfr 10
11 dpavlin 113 plan tests => 31;
12 ulpfr 10
13 dpavlin 113 if (-e './test') {
14     warn "test directory exists, removing!\n";
15     rmtree('./test',0,1);
16     }
17 ulpfr 10
18 dpavlin 113 ok(my $db = WAIT::Database->create(name => 'test'), "create");
19 ulpfr 10
20 dpavlin 113 ok(my $tb = $db->create_table(name => 'sample', attr => ['docid', 'term'],
21     djk => ['docid']), "create_table");
22 ulpfr 10
23 dpavlin 113 my $etid = 1;
24     my @db;
25 ulpfr 10 while (<DATA>) {
26     chomp;
27     my($weight, $did, $term) = split;
28 dpavlin 113 my $tid = $tb->insert($weight, docid => $did, term => $term);
29 ulpfr 10 push @db, [$did, $term, $weight];
30 dpavlin 113 cmp_ok ($tid, '==', $etid++, "insert $etid");
31 ulpfr 10 }
32    
33 dpavlin 113 ok(my $sc = $tb->open_scan(), "open_scan");
34 ulpfr 10
35 dpavlin 113 my $tid = 0;
36     while (my %tp = $sc->next()) {
37     ok (
38     ($tp{docid} == $db[$tid]->[0] and $tp{term} eq $db[$tid]->[1]),
39     "next ".$tid++);
40 ulpfr 10 }
41    
42 dpavlin 113 ok($sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'}),"open_scan IR");
43 ulpfr 10
44     $tid=0;
45 dpavlin 113 my @ndb = @db[1,4];
46     while (my %tp = $sc->next()) {
47     ok(($tp{docid} == $ndb[$tid]->[0] and $tp{term} eq $ndb[$tid]->[1]), "next ".$tid++);
48 ulpfr 10 }
49    
50 dpavlin 113 ok($sc = $tb->open_index_scan(['docid', 'term']), "open_index_scan");
51 ulpfr 10
52     $etid = 1;
53 dpavlin 113 while (my %tp = $sc->next()) {
54     ok(($tp{_id} == $etid), "next ".$etid++);
55 ulpfr 10 }
56    
57 dpavlin 113 ok($sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'}),
58     "open_index_scan IR");
59 ulpfr 10
60     @ndb = (1,4);
61 dpavlin 113 while (my %tp = $sc->next()) {
62     ok(($tp{_id} == shift(@ndb)+1), "next");
63 ulpfr 10 }
64    
65 dpavlin 113 ok($tb->close, "close");
66 ulpfr 10
67     # must have destroyed all handles here !
68     # clean up
69 dpavlin 113 ok($db->dispose, "dispose");
70     ok((!defined $db), "undef");
71 ulpfr 10
72     __END__
73     0.1 1 DB
74     0.2 1 IR
75     0.3 2 DB
76     0.4 2 KI
77     0.5 3 IR
78     0.6 3 KI

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26