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