-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
58 lines (46 loc) · 1.2 KB
/
test.pl
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
57
58
# $Id$
use strict;
use Test;
BEGIN { plan tests => 17 }
use DelayLine;
# simple constuction
ok( my $dl = DelayLine->new );
# simple constuction - alternative syntax
ok( my $dl = new DelayLine );
# construction via other object
my $dl = DelayLine->new('-delay' => 42);
ok( my $dl2 = $dl->new );
# different arg spelling
ok( my $dl = DelayLine->new('-delay' => 42) );
ok( my $dl = DelayLine->new('delay' => 42) );
ok( my $dl = DelayLine->new('Delay' => 42) );
ok( my $dl = DelayLine->new('DELAY' => 42) );
# unknown args
eval { my $dl = DelayLine->new('-badarg' => 42) };
ok($@, "/^DelayLine: Unknown argument '-badarg' at /");
eval { my $dl = DelayLine->new('-badarg' => 42, '-anotherbadarg' => 42) };
ok($@, "/^DelayLine: Unknown arguments /");
# check attributes
ok($dl->delay, 42);
ok($dl->debug, 0);
# check sequence
my $a = 'Hi, Mom!';
my $b = 'Look! No hands!';
$dl->in($a, 0);
$dl->in($b, 0);
ok($dl->out, $a);
ok($dl->out, $b);
# check delay
$dl->in($a, 2);
$dl->in($b, 0);
ok($dl->out, $b); # b should be ready immediately
ok($dl->out, undef); # a is not ready yet
sleep 2;
ok($dl->out, $a); # now a is ready
# event loop idiom
$dl->in($a, 3);
my $ob;
until ($ob = $dl->out) {
sleep 1;
}
ok($ob, $a);