/[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 114 - (show annotations)
Tue Jul 13 21:27:27 2004 UTC (19 years, 9 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1664 byte(s)
enought for today, still not passing all tests

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

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26