Moved bignum from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / ext / Memoize / t / tie_ndbm.t
CommitLineData
a0cb3900 1#!/usr/bin/perl
2
484fdf61 3use lib qw(. ..);
a0cb3900 4use Memoize 0.45 qw(memoize unmemoize);
5use Fcntl;
6# use Memoize::NDBM_File;
7# $Memoize::NDBM_File::Verbose = 0;
8
9sub i {
10 $_[0];
11}
12
13sub c119 { 119 }
14sub c7 { 7 }
15sub c43 { 43 }
16sub c23 { 23 }
17sub c5 { 5 }
18
19sub n {
20 $_[0]+1;
21}
22
23eval {require Memoize::NDBM_File};
24if ($@) {
25 print "1..0\n";
0b40f9f8 26 exit 0;
27}
28
29if (! -w $ENV{TMP}) {
30 print "1..0\n";
a0cb3900 31 exit 0;
32}
33
34print "1..4\n";
35
2359510d 36$file = "md$$";
cacf81f4 371 while unlink $file, "$file.dir", "$file.pag", "$file.db";
a0cb3900 38tryout('Memoize::NDBM_File', $file, 1); # Test 1..4
cacf81f4 391 while unlink $file, "$file.dir", "$file.pag", "$file.db";
a0cb3900 40
41sub tryout {
42 my ($tiepack, $file, $testno) = @_;
43
44
899dc88a 45 tie my %cache => $tiepack, $file, O_RDWR | O_CREAT, 0666
46 or die $!;
47
a0cb3900 48 memoize 'c5',
899dc88a 49 SCALAR_CACHE => [HASH => \%cache],
a0cb3900 50 LIST_CACHE => 'FAULT'
51 ;
52
53 my $t1 = c5();
54 my $t2 = c5();
55 print (($t1 == 5) ? "ok $testno\n" : "not ok $testno\n");
56 $testno++;
57 print (($t2 == 5) ? "ok $testno\n" : "not ok $testno\n");
58 unmemoize 'c5';
59
60 # Now something tricky---we'll memoize c23 with the wrong table that
61 # has the 5 already cached.
62 memoize 'c23',
899dc88a 63 SCALAR_CACHE => [HASH => \%cache],
a0cb3900 64 LIST_CACHE => 'FAULT'
65 ;
66
67 my $t3 = c23();
68 my $t4 = c23();
69 $testno++;
70 print (($t3 == 5) ? "ok $testno\n" : "not ok $testno\n");
71 $testno++;
72 print (($t4 == 5) ? "ok $testno\n" : "not ok $testno\n");
73 unmemoize 'c23';
74}
75