Commit | Line | Data |
---|---|---|
2fc7fd3f JH |
1 | #!/usr/bin/perl -w |
2 | # | |
3 | ||
4 | BEGIN { | |
5 | chdir 't' if -d 't'; | |
6 | @INC = '.'; | |
7 | push @INC, '../lib'; | |
8 | } | |
9 | ||
1725693f | 10 | print "1..20\n"; |
2fc7fd3f JH |
11 | |
12 | use strict; | |
13 | ||
14 | require Tie::SubstrHash; | |
15 | ||
16 | my %a; | |
17 | ||
18 | tie %a, 'Tie::SubstrHash', 3, 3, 3; | |
19 | ||
20 | $a{abc} = 123; | |
21 | $a{bcd} = 234; | |
22 | ||
23 | print "not " unless $a{abc} == 123; | |
24 | print "ok 1\n"; | |
25 | ||
26 | print "not " unless keys %a == 2; | |
27 | print "ok 2\n"; | |
28 | ||
29 | delete $a{abc}; | |
30 | ||
31 | print "not " unless $a{bcd} == 234; | |
32 | print "ok 3\n"; | |
33 | ||
34 | print "not " unless (values %a)[0] == 234; | |
35 | print "ok 4\n"; | |
36 | ||
37 | eval { $a{abcd} = 123 }; | |
38 | print "not " unless $@ =~ /Key "abcd" is not 3 characters long/; | |
39 | print "ok 5\n"; | |
40 | ||
41 | eval { $a{abc} = 1234 }; | |
42 | print "not " unless $@ =~ /Value "1234" is not 3 characters long/; | |
43 | print "ok 6\n"; | |
44 | ||
45 | eval { $a = $a{abcd}; $a++ }; | |
46 | print "not " unless $@ =~ /Key "abcd" is not 3 characters long/; | |
47 | print "ok 7\n"; | |
48 | ||
49 | @a{qw(abc cde)} = qw(123 345); | |
50 | ||
51 | print "not " unless $a{cde} == 345; | |
52 | print "ok 8\n"; | |
53 | ||
54 | eval { $a{def} = 456 }; | |
55 | print "not " unless $@ =~ /Table is full \(3 elements\)/; | |
56 | print "ok 9\n"; | |
57 | ||
58 | %a = (); | |
59 | ||
60 | print "not " unless keys %a == 0; | |
61 | print "ok 10\n"; | |
62 | ||
63 | # Tests 11..16 by Linc Madison. | |
64 | ||
65 | my $hashsize = 119; # arbitrary values from my data | |
66 | my %test; | |
67 | tie %test, "Tie::SubstrHash", 13, 86, $hashsize; | |
68 | ||
69 | for (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 | ||
75 | for (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 | } | |
83 | print "ok 11\n"; | |
84 | ||
85 | print "not " unless Tie::SubstrHash::findgteprime(1) == 2; | |
86 | print "ok 12\n"; | |
87 | ||
88 | print "not " unless Tie::SubstrHash::findgteprime(2) == 2; | |
89 | print "ok 13\n"; | |
90 | ||
91 | print "not " unless Tie::SubstrHash::findgteprime(5.5) == 7; | |
92 | print "ok 14\n"; | |
93 | ||
94 | print "not " unless Tie::SubstrHash::findgteprime(13) == 13; | |
95 | print "ok 15\n"; | |
96 | ||
97 | print "not " unless Tie::SubstrHash::findgteprime(13.000001) == 17; | |
98 | print "ok 16\n"; | |
99 | ||
1725693f JH |
100 | print "not " unless Tie::SubstrHash::findgteprime(114) == 127; |
101 | print "ok 17\n"; | |
102 | ||
103 | print "not " unless Tie::SubstrHash::findgteprime(1000) == 1009; | |
104 | print "ok 18\n"; | |
105 | ||
106 | print "not " unless Tie::SubstrHash::findgteprime(1024) == 1031; | |
107 | print "ok 19\n"; | |
108 | ||
109 | print "not " unless Tie::SubstrHash::findgteprime(10000) == 10007; | |
110 | print "ok 20\n"; | |
111 |