Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions exercises/beer-song/.meta/exercise-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
exercise: BeerSong
plan: 9
subs: sing
tests: |-
for my $case ( recurse_cases($C_DATA) ) {
# Your result should be a string, which is transformed into
# an array here when matching for a cleaner test output.
is(
[split("\n", sing({
bottles => $case->{input}{startBottles},
verses => $case->{input}{takeDown},
}))],
$case->{expected},
$case->{description}
);
}

sub recurse_cases {
my $obj = shift;
return $obj->{cases}
? map recurse_cases($_), @{ $obj->{cases} }
: $obj
}

example: |-
sub sing {
my ($input) = @_;
my @verses;
for ( 1..$input->{verses} ) {
if ( $input->{bottles} ) {
my $s = $input->{bottles} > 1 ? 's' : '';
my $one = $input->{bottles} == 1 ? 'it' : 'one';
chomp(my $str = <<VERSE);
$input->{bottles} bottle$s of beer on the wall, $input->{bottles} bottle$s of beer.
Take $one down and pass it around,
VERSE
push @verses, $str . (--$input->{bottles} || 'no more') . ' bottle' . ($input->{bottles} == 1 ? '' : 's') . ' of beer on the wall.';
}
else {
chomp(my $str = <<VERSE);
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
VERSE
push @verses, $str;
}
}
return join "\n\n", @verses;
}

stub: |-
sub sing {
my ($input) = @_;
return undef;
}
60 changes: 0 additions & 60 deletions exercises/beer-song/.meta/solutions/Beer.pm

This file was deleted.

36 changes: 36 additions & 0 deletions exercises/beer-song/.meta/solutions/BeerSong.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package BeerSong;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT_OK = qw(sing);

sub sing {
my ($input) = @_;
my @verses;
for ( 1 .. $input->{verses} ) {
if ( $input->{bottles} ) {
my $s = $input->{bottles} > 1 ? 's' : '';
my $one = $input->{bottles} == 1 ? 'it' : 'one';
chomp( my $str = <<VERSE);
$input->{bottles} bottle$s of beer on the wall, $input->{bottles} bottle$s of beer.
Take $one down and pass it around,
VERSE
push @verses,
$str
. ( --$input->{bottles} || 'no more' )
. ' bottle'
. ( $input->{bottles} == 1 ? '' : 's' )
. ' of beer on the wall.';
}
else {
chomp( my $str = <<VERSE);
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
VERSE
push @verses, $str;
}
}
return join "\n\n", @verses;
}

1;
1 change: 1 addition & 0 deletions exercises/beer-song/.meta/solutions/beer-song.t
1 change: 0 additions & 1 deletion exercises/beer-song/.meta/solutions/beer.t

This file was deleted.

12 changes: 12 additions & 0 deletions exercises/beer-song/BeerSong.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package BeerSong;
use strict;
use warnings;
use Exporter 'import';
our @EXPORT_OK = qw(sing);

sub sing {
my ($input) = @_;
return undef;
}

1;
Loading