File: 04_randpattern.t

package info (click to toggle)
libstring-random-perl 1%3A0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 168 kB
  • ctags: 14
  • sloc: perl: 347; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use strict;
use warnings;

use Test::More tests => 37;

# 1: Make sure we can load the module
BEGIN { use_ok('String::Random'); }

# 2: Make sure we can create a new object
my $foo=new String::Random;
my $bar=String::Random->new();
ok(defined($foo) && defined($bar), "new()");

# 3: Empty pattern shouldn't give undef for result
ok(my @notempty=$foo->randpattern(''), "randpattern('')");

# Try the object method...
$foo->{'x'}=['a'];
$foo->{'y'}=['b'];
$foo->{'z'}=['c'];

# 4: passing a scalar, in a scalar context
my $abc=$foo->randpattern("xyz");
is($abc, 'abc', "randpattern()");

# 5: passing an array, in a scalar context
my @foo=qw(x y z);
$abc=$foo->randpattern(@foo);
is($abc, 'abc', "randpattern() (scalar)");

# 6-8: passing an array, in an array context
my @bar=$foo->randpattern(@foo);
for (my $n=0;$n<@foo;$n++) {
    is($bar[$n], $foo->{$foo[$n]}->[0], "randpattern() (array) ($n)");
}

# 9-34: Check one of the built-in patterns to make
# sure it contains what we think it should
my @upcase=("A".."Z");
for (my $n=0;$n<26;$n++) {
    ok(defined($foo->{'C'}->[$n]) && ($upcase[$n] eq $foo->{'C'}->[$n]),
        "pattern ($n)");
}

# 35: Test modifying one of the built-in patterns
$foo->{'C'}=['n'];
is($foo->randpattern("C"), "n", "modify patterns");

# 36: Make sure we haven't clobbered anything in an existing object
isnt($bar->randpattern("C"), "n", "pollute pattern");

# 37: Make sure we haven't clobbered anything in a new object
my $baz=new String::Random;
ok(defined($baz) && ($baz->randpattern("C") ne "n"), "pollute new object");

# vi: set ai et syntax=perl: