1*0Sstevel@tonic-gate#!/usr/bin/perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateuse lib '..'; 4*0Sstevel@tonic-gateuse Memoize; 5*0Sstevel@tonic-gate 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gateprint "1..11\n"; 8*0Sstevel@tonic-gate 9*0Sstevel@tonic-gatesub timelist { 10*0Sstevel@tonic-gate return (time) x $_[0]; 11*0Sstevel@tonic-gate} 12*0Sstevel@tonic-gate 13*0Sstevel@tonic-gatememoize('timelist'); 14*0Sstevel@tonic-gate 15*0Sstevel@tonic-gate@t1 = &timelist(1); 16*0Sstevel@tonic-gatesleep 2; 17*0Sstevel@tonic-gate@u1 = &timelist(1); 18*0Sstevel@tonic-gateprint ((("@t1" eq "@u1") ? '' : 'not '), "ok 1\n"); 19*0Sstevel@tonic-gate 20*0Sstevel@tonic-gate@t7 = &timelist(7); 21*0Sstevel@tonic-gateprint (((@t7 == 7) ? '' : 'not '), "ok 2\n"); 22*0Sstevel@tonic-gate$BAD = 0; 23*0Sstevel@tonic-gatefor ($i = 1; $i < 7; $i++) { 24*0Sstevel@tonic-gate $BAD++ unless $t7[$i-1] == $t7[$i]; 25*0Sstevel@tonic-gate} 26*0Sstevel@tonic-gateprint (($BAD ? 'not ' : ''), "ok 3\n"); 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gatesleep 2; 29*0Sstevel@tonic-gate@u7 = &timelist(7); 30*0Sstevel@tonic-gateprint (((@u7 == 7) ? '' : 'not '), "ok 4\n"); 31*0Sstevel@tonic-gate$BAD = 0; 32*0Sstevel@tonic-gatefor ($i = 1; $i < 7; $i++) { 33*0Sstevel@tonic-gate $BAD++ unless $u7[$i-1] == $u7[$i]; 34*0Sstevel@tonic-gate} 35*0Sstevel@tonic-gateprint (($BAD ? 'not ' : ''), "ok 5\n"); 36*0Sstevel@tonic-gate# Properly memoized? 37*0Sstevel@tonic-gateprint ((("@t7" eq "@u7") ? '' : 'not '), "ok 6\n"); 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gatesub con { 40*0Sstevel@tonic-gate return wantarray() 41*0Sstevel@tonic-gate} 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate# Same arguments yield different results in different contexts? 44*0Sstevel@tonic-gatememoize('con'); 45*0Sstevel@tonic-gate$s = con(1); 46*0Sstevel@tonic-gate@a = con(1); 47*0Sstevel@tonic-gateprint ((($s == $a[0]) ? 'not ' : ''), "ok 7\n"); 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate# Context propagated correctly? 50*0Sstevel@tonic-gateprint ((($s eq '') ? '' : 'not '), "ok 8\n"); # Scalar context 51*0Sstevel@tonic-gateprint ((("@a" eq '1' && @a == 1) ? '' : 'not '), "ok 9\n"); # List context 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate# Context propagated correctly to normalizer? 54*0Sstevel@tonic-gatesub n { 55*0Sstevel@tonic-gate my $arg = shift; 56*0Sstevel@tonic-gate my $test = shift; 57*0Sstevel@tonic-gate if (wantarray) { 58*0Sstevel@tonic-gate print ((($arg eq ARRAY) ? '' : 'not '), "ok $test\n"); # List context 59*0Sstevel@tonic-gate } else { 60*0Sstevel@tonic-gate print ((($arg eq SCALAR) ? '' : 'not '), "ok $test\n"); # Scalar context 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate} 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gatesub f { 1 } 65*0Sstevel@tonic-gatememoize('f', NORMALIZER => 'n'); 66*0Sstevel@tonic-gate$s = f('SCALAR', 10); # Test 10 67*0Sstevel@tonic-gate@a = f('ARRAY' , 11); # Test 11 68*0Sstevel@tonic-gate 69