6.4. Saturation Testing

For string inputs, Perl can succinctly generate random strings of a given length:

{
my @visible = grep /[[:print:]]/, map chr, 0..255;
sub randstring { join '', map $visible[rand @visible],
                              1 .. shift }
}

and the entire set of alphabetic strings of a given length:

sub permstring { 'a'x$_[0] .. 'z'x$_[0] }

although the memory required won't make this useful for a length of more than about five.[5] See also the CPAN module String::Random.

[5] You could avoid the memory problem (in version 5.005 or later) by using the expression inside a foreach loop instead of a subroutine, but then you'd get clobbered by the amount of time to go through the loop. The finite nature of the universe has a way of catching up with you.

For simulating interactive sessions with users, you may want the CPAN module Expect.pm by Austin Schutz. It inherits its name from the popular Tcl tool called expect.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset