Merge branch 'DiceGoodieChanges' of git://github.com/mattlehning/zeroclickinfo-goodies into dice
commit
be1d0a07b5
|
@ -17,7 +17,7 @@ attribution twitter => 'crazedpsyc',
|
|||
cpan => 'CRZEDPSYC' ;
|
||||
|
||||
handle remainder => sub {
|
||||
if ($_ =~ /^(?:die|(\d{0,2})\s*dice)$/) {
|
||||
if ($_ =~ /^(?:a? ?die|(\d{0,2})\s*dic?e)$/) {
|
||||
my @output;
|
||||
my $rolls = 1; # If "die" is entered
|
||||
my $choices = 6; # To be replace with input string in the future
|
||||
|
@ -33,7 +33,7 @@ handle remainder => sub {
|
|||
my $roll = int(rand($choices)) + 1;
|
||||
push @output, $roll;
|
||||
}
|
||||
return join(' ', @output) if @output;
|
||||
return join(' ', @output, '(random)') if @output;
|
||||
}
|
||||
elsif ($_ =~ /^(\d{0,4})[d|w](\d+)\s?([+-])?\s?(\d+|[lh])?$/) { # 'w' is the German form
|
||||
my $output;
|
||||
|
@ -69,7 +69,7 @@ handle remainder => sub {
|
|||
} else {
|
||||
$output = $sum;
|
||||
}
|
||||
return $output if $output;
|
||||
return join('',$output, ' (random)') if $output;
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
|
16
t/Dice.t
16
t/Dice.t
|
@ -12,14 +12,14 @@ ddg_goodie_test(
|
|||
[qw(
|
||||
DDG::Goodie::Dice
|
||||
)],
|
||||
'throw dice' => test_zci(qr/^\d \d$/),
|
||||
"roll 5 dice" => test_zci(qr/\d \d \d \d \d/),
|
||||
"throw die" => test_zci(qr/^\d$/),
|
||||
"roll 2d6" => test_zci(qr/^\d (\+|-) \d = \d+$/),
|
||||
"roll 3d12 + 4" => test_zci(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d{1,2}$/),
|
||||
"throw 1d20" => test_zci(qr/\d{1,2}$/),
|
||||
"roll 3d8 - 8" => test_zci(qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d = -?\d+$/),
|
||||
"roll d20" => test_zci(qr/^\d{1,2}$/),
|
||||
'throw dice' => test_zci(qr/^\d \d \(random\)$/),
|
||||
"roll 5 dice" => test_zci(qr/\d \d \d \d \d \(random\)$/),
|
||||
"throw die" => test_zci(qr/^\d \(random\)$/),
|
||||
"roll 2d6" => test_zci(qr/^\d (\+|-) \d = \d+ \(random\)$/),
|
||||
"roll 3d12 + 4" => test_zci(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d{1,2} \(random\)$/),
|
||||
"throw 1d20" => test_zci(qr/\d{1,2} \(random\)$/),
|
||||
"roll 3d8 - 8" => test_zci(qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d = -?\d+ \(random\)$/),
|
||||
"roll d20" => test_zci(qr/^\d{1,2} \(random\)$/),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue