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

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 dpavlin 114 #use blib;
8 ulpfr 10
9 dpavlin 113 BEGIN { use_ok('WAIT::Database'); }
10 dpavlin 114 END { system 'rm -rf test' if -d 'test'; ok(1, "rm") }
11 ulpfr 10
12 dpavlin 114 plan tests => 32;
13 ulpfr 10
14 dpavlin 113 if (-e './test') {
15     warn "test directory exists, removing!\n";
16     rmtree('./test',0,1);
17     }
18 ulpfr 10
19 dpavlin 113 ok(my $db = WAIT::Database->create(name => 'test'), "create");
20 ulpfr 10
21 dpavlin 113 ok(my $tb = $db->create_table(name => 'sample', attr => ['docid', 'term'],
22     djk => ['docid']), "create_table");
23 ulpfr 10
24 dpavlin 113 my $etid = 1;
25     my @db;
26 ulpfr 10 while (<DATA>) {
27     chomp;
28     my($weight, $did, $term) = split;
29 dpavlin 113 my $tid = $tb->insert($weight, docid => $did, term => $term);
30 ulpfr 10 push @db, [$did, $term, $weight];
31 dpavlin 113 cmp_ok ($tid, '==', $etid++, "insert $etid");
32 ulpfr 10 }
33    
34 dpavlin 113 ok(my $sc = $tb->open_scan(), "open_scan");
35 ulpfr 10
36 dpavlin 113 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 ulpfr 10 }
42    
43 dpavlin 113 ok($sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'}),"open_scan IR");
44 ulpfr 10
45     $tid=0;
46 dpavlin 113 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 ulpfr 10 }
50    
51 dpavlin 113 ok($sc = $tb->open_index_scan(['docid', 'term']), "open_index_scan");
52 ulpfr 10
53     $etid = 1;
54 dpavlin 113 while (my %tp = $sc->next()) {
55     ok(($tp{_id} == $etid), "next ".$etid++);
56 ulpfr 10 }
57    
58 dpavlin 113 ok($sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'}),
59     "open_index_scan IR");
60 ulpfr 10
61     @ndb = (1,4);
62 dpavlin 113 while (my %tp = $sc->next()) {
63     ok(($tp{_id} == shift(@ndb)+1), "next");
64 ulpfr 10 }
65    
66 dpavlin 113 ok($tb->close, "close");
67 ulpfr 10
68     # must have destroyed all handles here !
69     # clean up
70 dpavlin 113 ok($db->dispose, "dispose");
71     ok((!defined $db), "undef");
72 ulpfr 10
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