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