Created
July 28, 2013 02:32
-
-
Save mix3/6097116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Sample; | |
use strict; | |
use warnings; | |
use utf8; | |
sub type_a { return "a" } | |
sub type_b { return "b" } | |
sub type_to_execute { | |
my $type = shift; | |
if ($type eq 'a') { | |
type_a(); | |
} elsif ($type eq 'b') { | |
type_b(); | |
} | |
} | |
sub calc_type { | |
my $args = shift; | |
($args < 100) ? 'a' : 'b'; | |
} | |
sub execute { | |
type_to_execute(calc_type(shift)); | |
} | |
1; | |
package main; | |
use strict; | |
use warnings; | |
use utf8; | |
use Test::More; | |
subtest type_a => sub { | |
is Sample::type_a, 'a'; | |
}; | |
subtest type_b => sub { | |
is Sample::type_b, 'b'; | |
}; | |
subtest type_to_execute => sub { | |
is Sample::type_to_execute('a'), 'a'; | |
is Sample::type_to_execute('b'), 'b'; | |
}; | |
subtest calc_type => sub { | |
is Sample::calc_type(0), 'a'; | |
is Sample::calc_type(99), 'a'; | |
is Sample::calc_type(100), 'b'; | |
is Sample::calc_type(1000), 'b'; | |
}; | |
subtest execute => sub { | |
is Sample::execute(0), 'a'; | |
is Sample::execute(99), 'a'; | |
is Sample::execute(100), 'b'; | |
is Sample::execute(1000), 'b'; | |
}; | |
done_testing(); | |
__DATA__ | |
ok 1 | |
1..1 | |
ok 1 - type_a | |
ok 1 | |
1..1 | |
ok 2 - type_b | |
ok 1 | |
ok 2 | |
1..2 | |
ok 3 - type_to_execute | |
ok 1 | |
ok 2 | |
ok 3 | |
ok 4 | |
1..4 | |
ok 4 - calc_type | |
ok 1 | |
ok 2 | |
ok 3 | |
ok 4 | |
1..4 | |
ok 5 - execute | |
1..5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment