6 use Test::More tests => 19;
8 use IPC::MorseSignals::Emitter;
10 sub neq { abs($_[0] - $_[1]) < ($_[1] / 10) };
12 my $deuce = IPC::MorseSignals::Emitter->new;
13 ok(defined $deuce, 'BME object is defined');
14 is(ref $deuce, 'IPC::MorseSignals::Emitter', 'IME object is valid');
15 ok($deuce->isa('Bit::MorseSignals::Emitter'), 'IME is a BME');
18 bless $fake, 'IPC::MorseSignal::Hlagh';
19 eval { IPC::MorseSignals::Emitter::speed($fake) };
20 ok($@ && $@ =~ /^First\s+argument/, "IME methods only apply to IME objects");
21 eval { Bit::MorseSignals::Emitter::reset($fake) };
22 ok($@ && $@ =~ /^First\s+argument/, "BME methods only apply to BME objects");
24 is($deuce->delay, 1, 'default delay is 1');
25 is($deuce->speed, 1, 'default speed is 1');
28 ok(neq($deuce->delay, 0.1), 'set delay is 0.1');
29 is($deuce->speed, 10, 'resulting speed is 10');
32 is($deuce->speed, 100, 'set speed is 100');
33 ok(neq($deuce->delay, 0.01), 'resulting speed is 0.01');
35 $deuce = IPC::MorseSignals::Emitter->new(delay => 0.25);
36 ok(neq($deuce->delay, 0.25), 'initial delay is 0.25');
37 is($deuce->speed, 4, 'resulting initial speed is 4');
39 $deuce = IPC::MorseSignals::Emitter->new(speed => 40);
40 is($deuce->speed, 40, 'initial speed is 40');
41 ok(neq($deuce->delay, 0.025), 'resulting initial delay is 0.025');
43 $deuce = IPC::MorseSignals::Emitter->new(delay => 0.25, speed => 40);
44 ok(neq($deuce->delay, 0.25), 'delay supersedes speed');
46 $deuce = IPC::MorseSignals::Emitter->new(delay => 0);
47 is($deuce->delay, 1, 'wrong delay results in 1');
49 $deuce = IPC::MorseSignals::Emitter->new(speed => 0.1);
50 is($deuce->delay, 1, 'wrong speed results in 1');
52 $deuce = IPC::MorseSignals::Emitter->new(delay => 0, speed => -0.1);
53 is($deuce->delay, 1, 'wrong delay and speed result in 1');