1 |
# -*- Mode: Perl -*- |
2 |
# scan.t -- |
3 |
# ITIID : $ITI$ $Header $__Header$ |
4 |
# Author : Ulrich Pfeifer |
5 |
# Created On : Thu Aug 8 12:14:23 1996 |
6 |
# Last Modified By: Ulrich Pfeifer |
7 |
# Last Modified On: Sun Nov 22 18:44:29 1998 |
8 |
# Language : CPerl |
9 |
# Update Count : 111 |
10 |
# Status : Unknown, Use with caution! |
11 |
# |
12 |
# Copyright (c) 1996-1997, Ulrich Pfeifer |
13 |
# |
14 |
######################### We start with some black magic to print on failure. |
15 |
|
16 |
BEGIN { $| = 1; print "1..32\n"; } |
17 |
END {print "not ok 1\n" unless $loaded; |
18 |
system 'rm -rf test' if -d 'test'; |
19 |
} |
20 |
#use diagnostics; |
21 |
use WAIT::Database; |
22 |
$loaded = 1; |
23 |
print "ok 1\n"; |
24 |
|
25 |
######################### End of black magic. |
26 |
|
27 |
$test = 2; |
28 |
|
29 |
$db = create WAIT::Database name => 'test'; |
30 |
print ((defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
31 |
|
32 |
$tb = create_table $db name => 'sample', attr => ['docid', 'term']; |
33 |
print ((defined $tb)? "ok $test\n" : "not ok $test\n"); $test++; |
34 |
|
35 |
$etid = 1; |
36 |
while (<DATA>) { |
37 |
chomp; |
38 |
my($did, $term) = split; |
39 |
$tid = $tb->insert(docid => $did, term => $term); |
40 |
push @db, [$did, $term]; |
41 |
print (($tid == $etid++)? "ok $test\n" : "not ok $test\n"); $test++; |
42 |
} |
43 |
|
44 |
$sc = $tb->open_scan(); |
45 |
print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++; |
46 |
|
47 |
$tid = 0; |
48 |
while (%tp = $sc->next()) { |
49 |
printf "%s", (($tp{docid} == $db[$tid]->[0] |
50 |
and $tp{term} eq $db[$tid]->[1])? |
51 |
"ok $test\n" : "not ok $test\n"); $test++; |
52 |
$tid++; |
53 |
} |
54 |
|
55 |
$sc = $tb->open_scan(sub {$_[0]->{term} eq 'IR'}); |
56 |
print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++; |
57 |
|
58 |
$tid=0; |
59 |
@ndb = @db[1,4]; |
60 |
while (%tp = $sc->next()) { |
61 |
printf "%s", (($tp{docid} == $ndb[$tid]->[0] |
62 |
and $tp{term} eq $ndb[$tid]->[1])? |
63 |
"ok $test\n" : "not ok $test\n"); $test++; |
64 |
$tid++; |
65 |
} |
66 |
|
67 |
$sc = $tb->open_index_scan(['docid', 'term']); |
68 |
print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++; |
69 |
|
70 |
$etid = 1; |
71 |
while (%tp = $sc->next()) { |
72 |
print (($tp{_id} == $etid++)?"ok $test\n" : "not ok $test\n"); $test++; |
73 |
} |
74 |
|
75 |
$sc = $tb->open_index_scan(['docid', 'term'], sub {$_[0]->{term} eq 'IR'}); |
76 |
print ((defined $sc)? "ok $test\n" : "not ok $test\n"); $test++; |
77 |
|
78 |
@ndb = (1,4); |
79 |
while (%tp = $sc->next()) { |
80 |
print (($tp{_id} == shift(@ndb)+1)?"ok $test\n" : "not ok $test\n"); $test++; |
81 |
} |
82 |
|
83 |
$status = $tb->close; |
84 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
85 |
|
86 |
# must have destroyed all handles here ! |
87 |
# clean up |
88 |
$status = $db->dispose; |
89 |
print (($status)? "ok $test\n" : "not ok $test\n"); $test++; |
90 |
print ((!defined $db)? "ok $test\n" : "not ok $test\n"); $test++; |
91 |
|
92 |
__END__ |
93 |
1 DB |
94 |
1 IR |
95 |
2 DB |
96 |
2 KI |
97 |
3 IR |
98 |
3 KI |