1 # $Id: 25-scan.t,v 1.3 2005-12-19 17:40:04 mike Exp $
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl 25-scan.t'
8 use Test::More tests => 81;
10 BEGIN { use_ok('ZOOM') };
12 my $host = "indexdata.com/gils";
14 eval { $conn = new ZOOM::Connection($host, 0) };
15 ok(!$@, "connection to '$host'");
17 my($ss, $n) = scan($conn, "w", 10);
21 my $previous = ""; # Sorts before all legitimate terms
22 foreach my $i (1 .. $n) {
23 my($term, $occ) = $ss->term($i-1);
25 "got term $i of $n: '$term' ($occ occurences)");
26 ok($term ge $previous, "term '$term' ge previous '$previous'");
29 (my $disp, $occ) = $ss->display_term($i-1);
31 "display term $i of $n: '$disp' ($occ occurences)");
32 ok($disp eq $term, "display term $i identical to term");
36 ok(1, "destroyed scanset");
37 eval { $ss->destroy() };
38 ok(defined $@ && $@ =~ /been destroy\(\)ed/,
39 "can't re-destroy scanset");
41 # Now re-scan, but only for words that occur in the title
42 ($ss, $n) = scan($conn, '@attr 1=4 w', 6);
44 $previous = ""; # Sorts before all legitimate terms
45 foreach my $i (1 .. $n) {
46 my($term, $occ) = $ss->term($i-1);
48 "got title term $i of $n: '$term' ($occ occurences)");
49 ok($term ge $previous, "title term '$term' ge previous '$previous'");
51 ok((grep { $term eq $_ } @terms), "title term was in term list");
55 ok(1, "destroyed second scanset");
57 # Now re-do the same scan, but limiting the results to four terms at a
59 $conn->option(number => 4);
60 ($ss, $n) = scan($conn, '@attr 1=4 w', 4);
61 # Get last term and use it as seed for next scan
62 my($term, $occ) = $ss->term($n-1);
63 ok($ss->option("position") == 1,
64 "seed-term is start of returned list");
66 "got last title term '$term' to use as seed");
69 ok(1, "destroyed third scanset");
71 # We want the seed-term to be in "position zero", i.e. just before the start
72 $conn->option(position => 0);
73 ($ss, $n) = scan($conn, "\@attr 1=4 $term", 2);
74 ok($ss->option("position") == 0,
75 "seed-term before start of returned list");
77 # Silly test of option setting and getting
78 $ss->option(position => "fruit");
79 ok($ss->option("position") eq "fruit",
80 "option setting/getting works");
83 ok(1, "destroyed fourth scanset");
85 # Some more testing still to do: see comment in "15-scan.t"
88 my $use_query_for_scan = 0;
90 my($conn, $startterm, $nexpected) = @_;
94 if ($use_query_for_scan) {
95 my $q = new ZOOM::Query::PQF($startterm);
96 $ss = $conn->scan1($q);
98 $ss = $conn->scan($startterm);
101 ok(!$@, "scan for '$startterm'");
102 $use_query_for_scan = !$use_query_for_scan;
105 ok(defined $n, "got size");
106 ok($n == $nexpected, "got $n terms (expected $nexpected)");