Array tests now pass
[dbsrgits/DBM-Deep.git] / t / 05_bigarray.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 plan tests => 4;
11 use t::common qw( new_fh );
12
13 use_ok( 'DBM::Deep' );
14
15 diag "This test can take up to a minute to run. Please be patient.";
16
17 my ($fh, $filename) = new_fh();
18 my $db = DBM::Deep->new(
19         file => $filename,
20         type => DBM::Deep->TYPE_ARRAY,
21 );
22
23 ##
24 # put/get many keys
25 ##
26 my $max_keys = 4000;
27
28 for ( 0 .. $max_keys ) {
29     $db->put( $_ => $_ * 2 );
30 }
31
32 my $count = -1;
33 for ( 0 .. $max_keys ) {
34     $count = $_;
35     unless ( $db->get( $_ ) == $_ * 2 ) {
36         last;
37     };
38 }
39 is( $count, $max_keys, "We read $count keys" );
40
41 cmp_ok( scalar(@$db), '==', $max_keys + 1, "Number of elements is correct" );
42 $db->clear;
43 cmp_ok( scalar(@$db), '==', 0, "Number of elements after clear() is correct" );