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

Contents of /trunk/t/disjoint.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (show 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 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More;
6 use File::Path qw(rmtree);
7 use blib;
8
9 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>) {
26 chomp;
27 my($weight, $did, $term) = split;
28 my $tid = $tb->insert($weight, docid => $did, term => $term);
29 push @db, [$did, $term, $weight];
30 cmp_ok ($tid, '==', $etid++, "insert $etid");
31 }
32
33 ok(my $sc = $tb->open_scan(), "open_scan");
34
35 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 }
41
42 ok($sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'}),"open_scan IR");
43
44 $tid=0;
45 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 }
49
50 ok($sc = $tb->open_index_scan(['docid', 'term']), "open_index_scan");
51
52 $etid = 1;
53 while (my %tp = $sc->next()) {
54 ok(($tp{_id} == $etid), "next ".$etid++);
55 }
56
57 ok($sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'}),
58 "open_index_scan IR");
59
60 @ndb = (1,4);
61 while (my %tp = $sc->next()) {
62 ok(($tp{_id} == shift(@ndb)+1), "next");
63 }
64
65 ok($tb->close, "close");
66
67 # must have destroyed all handles here !
68 # clean up
69 ok($db->dispose, "dispose");
70 ok((!defined $db), "undef");
71
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