This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove IGNORABLE files from ExtUtils-Install as per 8db6555210
[perl5.git] / lib / Tie / SubstrHash.t
CommitLineData
2fc7fd3f
JH
1#!/usr/bin/perl -w
2#
3
4BEGIN {
5 chdir 't' if -d 't';
6 @INC = '.';
7 push @INC, '../lib';
8}
9
1725693f 10print "1..20\n";
2fc7fd3f
JH
11
12use strict;
13
14require Tie::SubstrHash;
15
16my %a;
17
18tie %a, 'Tie::SubstrHash', 3, 3, 3;
19
20$a{abc} = 123;
21$a{bcd} = 234;
22
23print "not " unless $a{abc} == 123;
24print "ok 1\n";
25
26print "not " unless keys %a == 2;
27print "ok 2\n";
28
29delete $a{abc};
30
31print "not " unless $a{bcd} == 234;
32print "ok 3\n";
33
34print "not " unless (values %a)[0] == 234;
35print "ok 4\n";
36
37eval { $a{abcd} = 123 };
38print "not " unless $@ =~ /Key "abcd" is not 3 characters long/;
39print "ok 5\n";
40
41eval { $a{abc} = 1234 };
42print "not " unless $@ =~ /Value "1234" is not 3 characters long/;
43print "ok 6\n";
44
45eval { $a = $a{abcd}; $a++ };
46print "not " unless $@ =~ /Key "abcd" is not 3 characters long/;
47print "ok 7\n";
48
49@a{qw(abc cde)} = qw(123 345);
50
51print "not " unless $a{cde} == 345;
52print "ok 8\n";
53
54eval { $a{def} = 456 };
55print "not " unless $@ =~ /Table is full \(3 elements\)/;
56print "ok 9\n";
57
58%a = ();
59
60print "not " unless keys %a == 0;
61print "ok 10\n";
62
63# Tests 11..16 by Linc Madison.
64
65my $hashsize = 119; # arbitrary values from my data
66my %test;
67tie %test, "Tie::SubstrHash", 13, 86, $hashsize;
68
69for (my $i = 1; $i <= $hashsize; $i++) {
70 my $key1 = $i + 100_000; # fix to uniform 6-digit numbers
71 my $key2 = "abcdefg$key1";
72 $test{$key2} = ("abcdefgh" x 10) . "$key1";
73}
74
75for (my $i = 1; $i <= $hashsize; $i++) {
76 my $key1 = $i + 100_000;
77 my $key2 = "abcdefg$key1";
78 unless ($test{$key2}) {
79 print "not ";
80 last;
81 }
82}
83print "ok 11\n";
84
85print "not " unless Tie::SubstrHash::findgteprime(1) == 2;
86print "ok 12\n";
87
88print "not " unless Tie::SubstrHash::findgteprime(2) == 2;
89print "ok 13\n";
90
91print "not " unless Tie::SubstrHash::findgteprime(5.5) == 7;
92print "ok 14\n";
93
94print "not " unless Tie::SubstrHash::findgteprime(13) == 13;
95print "ok 15\n";
96
97print "not " unless Tie::SubstrHash::findgteprime(13.000001) == 17;
98print "ok 16\n";
99
1725693f
JH
100print "not " unless Tie::SubstrHash::findgteprime(114) == 127;
101print "ok 17\n";
102
103print "not " unless Tie::SubstrHash::findgteprime(1000) == 1009;
104print "ok 18\n";
105
106print "not " unless Tie::SubstrHash::findgteprime(1024) == 1031;
107print "ok 19\n";
108
109print "not " unless Tie::SubstrHash::findgteprime(10000) == 10007;
110print "ok 20\n";
111