r11683@rob-kinyons-powerbook58: rob | 2006-04-28 20:54:09 -0400
[dbsrgits/DBM-Deep.git] / t / 03_bighash.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
86867f3a 5use Test::More tests => 5;
6use Test::Deep;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
eff6a245 11diag "This test can take up to a minute to run. Please be patient.";
12
fde3db1a 13my ($fh, $filename) = new_fh();
ffed8b01 14my $db = DBM::Deep->new(
2a81bf9e 15 file => $filename,
86867f3a 16 type => DBM::Deep->TYPE_HASH,
ffed8b01 17);
ffed8b01 18
19##
20# put/get many keys
21##
a4e2db58 22my $max_keys = 4000;
23
ffed8b01 24for ( 0 .. $max_keys ) {
25 $db->put( "hello $_" => "there " . $_ * 2 );
26}
27
30029562 28my $count = -1;
ffed8b01 29for ( 0 .. $max_keys ) {
30029562 30 $count = $_;
31 unless ( $db->get( "hello $_" ) eq "there " . $_ * 2 ) {
32 last;
33 };
ffed8b01 34}
30029562 35is( $count, $max_keys, "We read $count keys" );
bee3661a 36
86867f3a 37my @keys = sort keys %$db;
38cmp_ok( scalar(@keys), '==', $max_keys + 1, "Number of keys is correct" );
39my @control = sort map { "hello $_" } 0 .. $max_keys;
40cmp_deeply( \@keys, \@control, "Correct keys are there" );
41
bee3661a 42$db->clear;
43cmp_ok( scalar(keys %$db), '==', 0, "Number of keys after clear() is correct" );