6 use Test::More tests => 19;
8 use IPC::MorseSignals::Emitter;
10 my $deuce = new IPC::MorseSignals::Emitter;
11 ok(defined $deuce, 'BME object is defined');
12 ok(ref $deuce eq 'IPC::MorseSignals::Emitter', 'IME object is valid');
13 ok($deuce->isa('Bit::MorseSignals::Emitter'), 'IME is a BME');
16 bless $fake, 'IPC::MorseSignal::Hlagh';
17 eval { IPC::MorseSignals::Emitter::speed($fake) };
18 ok($@ && $@ =~ /^First\s+argument/, "IME methods only apply to IME objects");
19 eval { Bit::MorseSignals::Emitter::reset($fake) };
20 ok($@ && $@ =~ /^First\s+argument/, "BME methods only apply to BME objects");
22 ok($deuce->delay == 1, 'default delay is 1');
23 ok($deuce->speed == 1, 'default speed is 1');
26 ok(abs($deuce->delay - 0.1) < 0.01, 'set delay is 0.1');
27 ok($deuce->speed == 10, 'resulting speed is 10');
30 ok($deuce->speed == 100, 'set speed is 100');
31 ok(abs($deuce->delay - 0.01) < 0.001, 'resulting speed is 0.01');
33 $deuce = new IPC::MorseSignals::Emitter delay => 0.25;
34 ok(abs($deuce->delay - 0.25) < 0.025, 'initial delay is 0.25');
35 ok($deuce->speed == 4, 'resulting initial speed is 4');
37 $deuce = new IPC::MorseSignals::Emitter speed => 40;
38 ok($deuce->speed == 40, 'initial speed is 40');
39 ok(abs($deuce->delay - 0.025) < 0.0025, 'resulting initial delay is 0.025');
41 $deuce = new IPC::MorseSignals::Emitter delay => 0.25, speed => 40;
42 ok(abs($deuce->delay - 0.25) < 0.025, 'delay supersedes speed');
44 $deuce = new IPC::MorseSignals::Emitter delay => 0;
45 ok($deuce->delay == 1, 'wrong delay results in 1');
47 $deuce = new IPC::MorseSignals::Emitter speed => 0.1;
48 ok($deuce->delay == 1, 'wrong speed results in 1');
50 $deuce = new IPC::MorseSignals::Emitter delay => 0, speed => -0.1;
51 ok($deuce->delay == 1, 'wrong delay and speed result in 1');