Commit | Line | Data |
6b85e4fe |
1 | use strict; |
5f64702c |
2 | use Config; |
38506751 |
3 | BEGIN { |
4 | require Test::More; |
5 | if ($Config{'useithreads'}) { |
6 | Test::More->import( tests => 53 ); |
7 | } |
8 | else { |
9 | Test::More->import(skip_all => "no useithreads"); |
10 | } |
5f64702c |
11 | } |
12 | |
6b85e4fe |
13 | |
14 | my @array; |
15 | my %hash; |
16 | |
17 | sub hash |
18 | { |
19 | my @val = @_; |
20 | is(keys %hash, 0, "hash empty"); |
21 | $hash{0} = $val[0]; |
22 | is(keys %hash,1, "Assign grows hash"); |
23 | is($hash{0},$val[0],"Value correct"); |
24 | $hash{2} = $val[2]; |
25 | is(keys %hash,2, "Assign grows hash"); |
26 | is($hash{0},$val[0],"Value correct"); |
27 | is($hash{2},$val[2],"Value correct"); |
28 | $hash{1} = $val[1]; |
29 | is(keys %hash,3,"Size correct"); |
30 | my @keys = keys %hash; |
31 | is(join(',',sort @keys),'0,1,2',"Keys correct"); |
32 | my @hval = @hash{0,1,2}; |
33 | is(join(',',@hval),join(',',@val),"Values correct"); |
34 | my $val = delete $hash{1}; |
35 | is($val,$val[1],"Delete value correct"); |
36 | is(keys %hash,2,"Size correct"); |
37 | while (my ($k,$v) = each %hash) |
38 | { |
39 | is($v,$val[$k],"each works"); |
40 | } |
41 | %hash = (); |
42 | is(keys %hash,0,"Clear hash"); |
43 | } |
44 | |
45 | sub array |
46 | { |
47 | my @val = @_; |
48 | is(@array, 0, "array empty"); |
49 | $array[0] = $val[0]; |
50 | is(@array,1, "Assign grows array"); |
51 | is($array[0],$val[0],"Value correct"); |
52 | unshift(@array,$val[2]); |
53 | is($array[0],$val[2],"Unshift worked"); |
54 | is($array[-1],$val[0],"-ve index"); |
55 | push(@array,$val[1]); |
56 | is($array[-1],$val[1],"Push worked"); |
57 | is(@array,3,"Size correct"); |
58 | is(shift(@array),$val[2],"Shift worked"); |
59 | is(@array,2,"Size correct"); |
60 | is(pop(@array),$val[1],"Pop worked"); |
61 | is(@array,1,"Size correct"); |
62 | @array = (); |
63 | is(@array,0,"Clear array"); |
64 | } |
65 | |
66 | ok((require threads::shared),"Require module"); |
67 | |
68 | array(24,[],'Thing'); |
69 | hash(24,[],'Thing'); |
70 | |
5f64702c |
71 | |
6b85e4fe |
72 | import threads::shared; |
73 | share(\@array); |
74 | |
75 | #SKIP: |
76 | # { |
77 | # skip("Wibble",1); |
78 | # ok(0,"No it isn't"); |
79 | # } |
80 | |
81 | array(24,42,'Thing'); |
82 | |
83 | share(\%hash); |
84 | hash(24,42,'Thing'); |
85 | |